fmincon should return a scalar value error

43 ビュー (過去 30 日間)
Hassan garni
Hassan garni 2018 年 1 月 25 日
コメント済み: Torsten 2022 年 8 月 30 日
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 件のコメント
AJEET Kumar
AJEET Kumar 2022 年 8 月 30 日
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 2022 年 8 月 30 日
Take the initial condition in the neighbourhood of the solution you want to get from fmincon :-)

サインインしてコメントする。

採用された回答

Nicolas Schmit
Nicolas Schmit 2018 年 1 月 26 日
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 件のコメント
Sanyam Maheshwari
Sanyam Maheshwari 2020 年 7 月 17 日
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 2020 年 7 月 17 日
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?

サインインしてコメントする。

その他の回答 (1 件)

maged salah
maged salah 2020 年 7 月 20 日
  3 件のコメント
maged salah
maged salah 2020 年 7 月 20 日
if you can help ,I need a drawing for this table (parallel,step response)
Walter Roberson
Walter Roberson 2020 年 7 月 20 日

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSolver Outputs and Iterative Display についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by