Function handler in a for loop
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi,
I am working on an optimization problem for curve fitting analysis data. I have tried to use a function handler to experess the data so that I can use fmincon to solve the parameters. However, i keep getting error messages : Operator '*' is not supported for operands of type 'function_handle'.
Here is code for the line with the error message:
for i = 1:60
No = [1.169, 1.724, 0.5, 1.725]; % initial values
if tp(i,1) < 0.065
ts(i,1) = P36S2_Steel_Ux(i,1) * @(No) (Lf_ref/Lf_i).^No(1) * (Cs_ref/Cs_i).^No(3) * (Ep_i/Ep_ref).^No(4)* (di/dref).^No(5);
else
ts(i,1) = P36S2_Steel_Ux(i,1) * @(No) (Lf_ref/Lf_i).^No(2) * (Cs_ref/Cs_i).^No(3) * (Ep_i/Ep_ref).^No(4)* (di/dref).^No(5);
end
end
The goal is to find the optimal values for No.
2 commentaires
Jan
le 1 Août 2022
The purpose of the "@(No)" is not clear. Either simply omit this part, or create ts as array of function handles:
ts{i,1} = @(No) P36S2_Steel_Ux(i,1) * (Lf_ref/Lf_i).^No(1) * ...
(Cs_ref/Cs_i).^No(3) * (Ep_i/Ep_ref).^No(4)* (di/dref).^No(5);
You provide No as 1x4 vector. Then accessing No(5) is confusing.
Réponses (0)
Voir également
Catégories
En savoir plus sur Legend dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!