fmincon should return a scalar value error
Show older comments
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 Comments
Walter Roberson
on 25 Jan 2018
Difficult to say without the actual objective function and knowing the sizes of the variables involved.
If that is intended to be the actual objective then you need to split the lines properly for us.
Hassan garni
on 26 Jan 2018
AJEET Kumar
on 30 Aug 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
on 30 Aug 2022
Take the initial condition in the neighbourhood of the solution you want to get from fmincon :-)
Accepted Answer
More Answers (1)
maged salah
on 20 Jul 2020
0 votes

3 Comments
Walter Roberson
on 20 Jul 2020
This does not appear to be an Answer to the original Question, and does not appear to be an Answer to anything, and also does not appear to be related to any of the earlier discussion ?
maged salah
on 20 Jul 2020
if you can help ,I need a drawing for this table (parallel,step response)
Walter Roberson
on 20 Jul 2020
You should open a new Question for this. When you do, then http://www.mathworks.com/matlabcentral/answers/6200-tutorial-how-to-ask-a-question-on-answers-and-get-a-fast-answer
Categories
Find more on Conversion Between Symbolic and Numeric in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
