Error using lsqcurvefit in non-linear data optimization
Mostrar comentarios más antiguos
I have a data file of inverted airfoil different angles of attack and corresponding CL and i am trying to optimize it for maximum downforce using lsqcurvefit by the following code
clear
clc
load num_data.txt
alfa = num_data(:,1);
cl= num_data(:,2);
plot(alfa,cl,'ro')
title('alfa_vs_cl')
rho=1.225;co=0.264;
objective = @(x) -0.5*rho*(x(1)^2)*x(2)*x(3)*co*(sind(x(4)));
x0 = [0.1,0.1,0.1,0];
lb=[0,0.8385,0,-2];
ub=[90, 2.0996,1.8,18];
x = lsqcurvefit(objective,x0,alfa,cl,lb,ub)
but i get the following error
Error using regularstand>@(x)-0.5*rho*(x(1)^2)*x(2)*x(3)*co*(sind(x(4)))
Too many input arguments.
Error in lsqcurvefit (line 202)
initVals.F = feval(funfcn_x_xdata{3},xCurrent,XDATA,varargin{:});
Error in regularstand (line 15)
x = lsqcurvefit(objective,x0,alfa,cl,lb,ub)
Caused by:
Failure in initial objective function evaluation. LSQCURVEFIT cannot continue.
what can i do to fix it?
Respuesta aceptada
Más respuestas (1)
Star Strider
el 5 de Dic. de 2017
Your objective function does not use ‘alfa’, so you are not doing any fitting of your data to ‘cl’. Your objective function needs to be of the form:
objective = @(x,alfa) some_function_of_x_and_alfa;
8 comentarios
Adel
el 5 de Dic. de 2017
Star Strider
el 5 de Dic. de 2017
My pleasure.
Adel
el 5 de Dic. de 2017
Star Strider
el 5 de Dic. de 2017
I am not sure what you are doing. To use lsqcurvefit, your ‘objective’ must be a function of only your independent variable and your parameter vector. The lsqcurvefit function will fit it to your dependent variable.
If you have more than one independent variable, you can concatenate ‘alfa’ and ‘cl’ in the same array and refer to the individual columns, for example:
iv = [alfa cl]; % Independent Variable Matrix
fcn = @(x,dv) x(1).*dv(:,1) + x(2).*dv(:,2);
This creates: fcn = x1*alfa + x2*cl. You would then regress this against whatever you define your dependent variable to be.
If you are doing optimization and both ‘alfa’ and ‘cl’ are part of ‘objective’ and you want to estimate ‘x’, you must use another optimization function, such as fmincon.
Walter Roberson
el 5 de Dic. de 2017
Walter Roberson
el 5 de Dic. de 2017
Note: for fitting problems you would want to minimize the difference between the projected data and the experimental data. To do that, you would not minimize the projection function: you would minimize
sum(projection_results.^2)
Star Strider
el 5 de Dic. de 2017
@Adel — Note that I mentioned in my original Answer that you have to incorporate ‘alfa’ in ‘objective’ and then fit it to ‘cl’ using lsqcurvefit.
Since ‘alfa’ does not appear in ‘objective’, lsqcurvefit is not fitting the equation to your data. I have no idea what that equation should be or where ‘alfa’ should appear in it, so I cannot write it for you.
Adel
el 5 de Dic. de 2017
Categorías
Más información sobre Systems of Nonlinear Equations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!