Failure in initial objective function evaluation. FMINCON cannot continue.
54 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Lorenzo Ceresole
el 16 de Mzo. de 2022
Comentada: Walter Roberson
el 16 de Mzo. de 2022
Hello there, I have tried to look at the previous answers to this error, but I was still not able to resolve it with the advice given. I am trying to do a design optimization problem, but this is the error it returns. My code is shown below:
%% Parameters
l_0 = 3;
R = 5;
B = 4;
% fun = @(a,b) (8/((l_i)^2))*b*(a-1)*F*(l_i)^3;
a = 0.5;
b = 1;
C = [];
D = [];
% n=20;
LB = [0,0];
UB = [1,2];
x0 = (LB+UB)/2;
r=0.15*R:0.0425*R:R;
%% objective
nvars = 2;
LB = [4 5];
UB = [5 6];
aoa = 15; %need to make a matrix out of this for the baseline blade
x = [4 5];
%% Loop
for i = 1:length(r)
l_i = (l_0 * r(i)) / R;
% disp(l_i)
phi = atan(((1 - a) / (1 + b)) * (1/l_i(i)));
% disp(phi)
f = B / 2 * ((R - r(i)) / (R * sin(phi(i))));
% disp(f)
F = 2 / pi * acos(exp(1).^(-f(i)));
% disp(F)
twist_angle = phi(i) - aoa(i);
% disp(twist_angle)
obj = @(x)(8/((l_i).^2))*x(2)*(x(1)-1)*F*(l_i).^3;
% disp(obj)
[x,fvals] = fmincon(obj,nvars,[],[],[],[],LB,UB,@constraint);
end
with the constraint function being
function[c,ceq] = constraint(x)
c = (x(1)^2) * F + x(2) * l_i.^2 - x(2) * x(1) * l_i.^2 - x(1);
ceq = [];
end
-------------------------------------------------------------------------------------------------------------------------
and the error returned:
------------------------------------------------------------------------------------------------------------------------
1 comentario
John D'Errico
el 16 de Mzo. de 2022
I closed your exact duplicate question, since it adds nothing to the problem, and since I gave you a complete answer to your problem here.
Respuesta aceptada
John D'Errico
el 16 de Mzo. de 2022
Editada: John D'Errico
el 16 de Mzo. de 2022
You need to read the examples. Look at the help for fmincon. Why?
What is nvars?
nvars = 2;
nvars is the scalar 2. I assume you think that means the NUMBER of variables.
How do you use nvars?
[x,fvals] = fmincon(obj,nvars,[],[],[],[],LB,UB,@constraint);
As the second argument to fmincon.
However, READ THE HELP FOR FMINCON! LOOK AT THE EXAMPLES.
help fmincon
What is the second argument to fmincon assumed to be? Answer: a vector of initial estimates of the solution. x0 (the second input argument) is assumed to be a vector of the starting values for the opttimization, not just the number of variables to optimize over. You even try to index into x, inside the objective function. But all you did was pass fmincon a scalar value.
So fmincon assumes this is a ONE variable problem, with a starting value of 2.
You even gave fmincon lower and upper bounds for TWO variables.
LB = [4 5];
UB = [5 6];
Did you read the error message? It told you there were too many bounds provided, although that was only a warning message, trying to be friendly and help you. Again, this is a hint to you there is a problem with the variable x0.
2 comentarios
Walter Roberson
el 16 de Mzo. de 2022
Note that ga() would expect the number of variables in that particular position, but that fmincon() requires the initial position in that particular position.
Más respuestas (0)
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!