Error in fminsearch (line 200) fv(:,1) = funfcn(x,varargin{:});
7 views (last 30 days)
Show older comments
I'm trying to get an optimised curve fir for my data, but i get the error
fun = @(x)(x(1).*(A).^2 + x(2).*(B).^2 + x(3).*(C).^2 + x(4).*(D).^2 -(E).^2);
x0 = zeros(1,4);
param = fminsearch(fun,x0);
2 Comments
Accepted Answer
Ameer Hamza
on 12 Nov 2020
Objective function must return a scalar value, whereas, in your case, it returns a 576x1 vector. Following code uses norm() to take l2-norm of 576x1 to return a scalar.
A = rand(576,1); % example values
B = rand(576,1);
C = rand(576,1);
D = rand(576,1);
E = rand(576,1);
fun = @(x) norm((x(1).*(A).^2 + x(2).*(B).^2 + x(3).*(C).^2 + x(4).*(D).^2 -(E).^2));
x0 = zeros(1,4);
param = fminsearch(fun,x0);
0 Comments
More Answers (0)
See Also
Categories
Find more on Digital Filter Design in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!