fmincon error in matlab

1 次查看(过去 30 天)
divya
divya 2016-2-18
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);
>>

回答(1 个)

Brendan Hamm
Brendan Hamm 2016-2-18
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?

类别

Help CenterFile Exchange 中查找有关 Systems of Nonlinear Equations 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by