Function handler in a for loop
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
Jan
2022-8-1
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.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Legend 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!