fmincon error in matlab
조회 수: 1 (최근 30일)
이전 댓글 표시
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);
>>
댓글 수: 0
답변 (1개)
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?
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!