Function handler in a for loop

1 view (last 30 days)
KingsOz
KingsOz on 1 Aug 2022
Commented: KingsOz on 1 Aug 2022
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 Comments
Jan
Jan on 1 Aug 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.
KingsOz
KingsOz on 1 Aug 2022
Sorry I pasted the wrong row vector for (No). (No) should have 5 elements. I will try your suggestion. (No) is a scaling function used in curve fitting a set of analysis data to match a reference data. I have two sets of plots with the same duration along the time axis (0 to 0.295). However, their peak amplitude is different in magnitude and occurs at different instances in time. My goal is to scale one of them to match the other.

Sign in to comment.

Answers (0)

Products


Release

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!