fmincon should return a scalar value error

78 visualizaciones (últimos 30 días)
Hassan garni
Hassan garni el 25 de En. de 2018
Comentada: Torsten el 30 de Ag. de 2022
Hello,
I am trying to do an optimization for a large function using a "fmincon" function. I have got an error and couldn't find the problem. The main function has so many trigonometric functions (cos, sin. ...). The following is the error obtained :
Error using fmincon (line 609)
Supplied objective function must return a scalar value.
Error in Energy_test2 (line 74)
x = fmincon(objective,x0,A,b,Aeq,beq,lb,ub,'flcon');
The following is the main script using "fmincon". I also have checked the matrices dimensions.
objective = @(x)( cos(x(1)).*sin(x(2))+ ....(cos(t).*cos((Ay)-(x(1)))).*...*Ar*e));
x0 = [2,42];
disp(['initial objective:' num2str(objective(x0))])
A = [];
b=[];
Aeq = [];
beq = [];
x0 = [1,4];
lb = [0,0];
ub = [90,90] ;
nonlinecon = @flcon;
x = fmincon(objective,x0,A,b,Aeq,beq,lb,ub,'flcon');
I appreciate if somebody help with this issue and how can be solved.
Thank you.
Hassan
  4 comentarios
AJEET Kumar
AJEET Kumar el 30 de Ag. de 2022
Hello sir, Sir how to decide the initial condition in fmincon problem.because fir different initial condition we get different solution.so please ask me any formula for take initial condition.
Torsten
Torsten el 30 de Ag. de 2022
Take the initial condition in the neighbourhood of the solution you want to get from fmincon :-)

Iniciar sesión para comentar.

Respuesta aceptada

Nicolas Schmit
Nicolas Schmit el 26 de En. de 2018
fmincon() crashed because it expected the objective function to return a scalar value but got something that was not a scalar.
Test your objective function on the initial conditions and check that the output is a scalar.
objective(x0) % Scalar?
If you need further help, post the complete program.
  13 comentarios
Sanyam Maheshwari
Sanyam Maheshwari el 17 de Jul. de 2020
Hi Walter
I just posted in order to get my answer as fast as possible.
As suggested by you I tried using syms x.
That again resulted in different errors.
If possible if you could suggest me to use any other solver. I am new to MATLAB So I don't have much experience.
Here x represents demand of 4 different products.
I am solving an optimization problem in which is somewhere linked with newspaper vendor problem of operations management.
Also can you please explain how I have to use double() with an example.
It will be really helpfull
Walter Roberson
Walter Roberson el 17 de Jul. de 2020
Here x represents demand of 4 different products.
The demands of 4 different products can be optimized in more than 16 different ways. If we call them P1, P2, P3, P4, then one way would be to find the mimimum of P1, ignoring P2, P3, P4. Another would be to find the mnimum of P2, ignoring P1, P3, P4. Another would be to find the product of P2 and P3 ignoring P1 and P4. Other way would be to find the sum of P1+P4, ignoring P2 and P3. And so on. You might even ask about min() of the P1, P2, P3, P4 values --- but if you use min() then the function is not differentiable and fmincon() cannot be used.
Each of the products is an "objective", and fmincon() can only optimize one objective. When you have four objectives, you need to either use a different routine such as gamultiobj() or else you need to find a function that takes the four individual objectives and forms a unified score.
For example, suppose you could lower P1, P2, P3 by 0.02 each, but only at the cost of increasing P4 by 0.01: should you do that? Suppose the mininum for P1 is at its lower bound, but that forces P3 to be relatively large: should you do that?

Iniciar sesión para comentar.

Más respuestas (1)

maged salah
maged salah el 20 de Jul. de 2020
  3 comentarios
maged salah
maged salah el 20 de Jul. de 2020
if you can help ,I need a drawing for this table (parallel,step response)

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by