How to use "@" functionhandle for multiple inputs? (to use with fmincon)
9 views (last 30 days)
Show older comments
Hallo,
I wrote a function (which works by itself), which can be called like this:
[output]=get_amps(input,par)
"output" can not be written as simple analytical function of "input".
Now I want to optimize the parameters "par" using fmincon:
input_a=a; % a is a vector in the workspace
par0=[100,5000];
out_a = @opt_a get_amps(input_a,par0); % here is the problem
objective = @opt_a sum((input_a-out_a).^2);
p_opt=fmincon(objective,par0);
In line3 I get the error:
" Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. ..."
How to use the @function handle with functions with multiple inputs?
Is there a better way to optimze parameters of a (non-analytical) function than fmincon?
I would be greatfull for any help.
best
Ralf
Accepted Answer
Matt J
on 5 Mar 2022
objective = @(p) sum( ( a - get_amps(a, p) ).^2);
par0=[100,5000];
p_opt=fmincon(objective,par0);
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!