Clear Filters
Clear Filters

fmincon error in matlab

1 view (last 30 days)
divya
divya on 18 Feb 2016
Edited: Walter Roberson on 18 Feb 2016
i need help to solve this ?
partial code is :
%Initial Guess for parameters
P01 = [.2;.4;.04;.1;.02;2];
LB = [0;0;0;0;0;.001]; % Lower Bounds
UB = [.6;.6;.6; .6;.6;inf]; % Upper Bounds
options = optimoptions(@fmincon,'Algorithm','interior-point','Display','off');
% x = fmincon(@(x)x,1,[],[],[],[],0,[],[],options)
[P,sse] =fmincon(@(resid)resid,P01,[],[],[],[],LB,UB,[],options);
% Compare to original
[tpost1,Xpost1] =ode23s(@state,tdata,[y0;x20;x30;zeros(18,1)],[],P(1),P(2),P(3),P(4),P(5),P(6));
error is
Error using fmincon (line 607)
User supplied objective function must return a
scalar value.
Error in soren (line 27)
[P,sse]
=fmincon(@(resid)resid,P01,[],[],[],[],LB,UB,[],options);
>>

Answers (1)

Brendan Hamm
Brendan Hamm on 18 Feb 2016
Your objective function must return a scalar value but yours is returning a vector as your vector of design variables is a vector; the unchanged input. Consider your objective:
>> Objective = @(resid) resid; % Takes an input and returns it as the output.
>> Objective(1)
ans =
1
>> Objective([.2;.4;.04;.1;.02;2])
ans =
0.2000
0.4000
0.0400
0.1000
0.0200
2.0000
What is it you are truly trying to minimize? The norm of the vector perhaps?

Categories

Find more on Systems of Nonlinear Equations in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!