Error in fminsearch (line 200) fv(:,1) = funfcn(x,varargin{:});

5 visualizaciones (últimos 30 días)
Tushar Verma
Tushar Verma el 12 de Nov. de 2020
Respondida: Ameer Hamza el 12 de Nov. de 2020
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 comentarios
Ameer Hamza
Ameer Hamza el 12 de Nov. de 2020
What are the values of A, B, C, D, and E.
Tushar Verma
Tushar Verma el 12 de Nov. de 2020
Editada: Tushar Verma el 12 de Nov. de 2020
Sorry , the post got submitted halfway through. A B C D E are vectors of 576x1 each and the full error is :
im trying to fit the data to a curve using : https://se.mathworks.com/help/matlab/math/example-curve-fitting-via-optimization.html
Unable to perform assignment because the size of the left side
is 1-by-1 and the size of the right side is 576-by-1.
Error in fminsearch (line 200)
fv(:,1) = funfcn(x,varargin{:});
Error in anaLiSis (line 263)
param = fminsearch(fun,x0);

Iniciar sesión para comentar.

Respuesta aceptada

Ameer Hamza
Ameer Hamza el 12 de Nov. de 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);

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by