fitnessfcn: Not enough input arguments.
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
function Y = objfun(X)
% Y = fitness value
% X = variable vector (1*n)
% R = 1.994*r^-0.32*f^2.34*v^-0.01*d^0.18
% where r=[0.2:0.8], f=[0.2:0.6], v=[39.27:117.81], d=[0.2:0.8]
r=X(1,1); % variable 1
f=X(1,2); % variable 2
v=X(1,3); % variable 3
d=X(1,4); % variable 4
Y = 1.994*r^-0.32*f^2.34*v^-0.01*d^0.18;
0 comentarios
Respuestas (2)
Ameer Hamza
el 6 de Oct. de 2020
I think you are trying to run this function by pressing the Green Run button. It will not work because you can not specifying the value of X. Call it like this, from the command window or a script
X = [2 1 4 5]; % example values
objfun(X)
Star Strider
el 6 de Oct. de 2020
It would help to see your ga call.
When I run your function using this ga call:
Xest = ga(@objfun, 4)
it produces (in one run):
Xest =
-355.83 0.028458 181.05 -0.038601
Be certain that you are providing the correct value (4) for ‘nvars’ , or if you are using InitialPopulationMatrix that the matrix has 4 columns.
2 comentarios
Star Strider
el 6 de Oct. de 2020
The point is that your code no longer throws the error!
The values will likelly not be the same (at least exactly the same) on any specific run, unless the tolerances are decreased. (Use optimoptions to set them.)
It is generally necessary to use the values returned by ga that have the lowest fitness score (include the ‘fval’ output to return and display them) as starting parameter estimates for fminsearch or fminunc, or similar functions. Those functions will generally provide more precise parameter estimates, however the ga results with the lowest fitness scores are the best initial values to provide to them.
If my Answer helped you solve your problem, please Accept it!
.
Ver también
Categorías
Más información sobre Solver Outputs and Iterative Display en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!