when i do fmincon live script optimize, the coordinate is different

i want to get a coordinate for maximum distance which form is
distance =10.361+0.40125.*a-0.34875.*c-0.78375.*a.*c
i plot this surface, and i saw (1,-1) is the best coordinate and the maximum distance is 11.8947
but when i do this for live script fmincon,
x0=[0 0];
lowerbound=[-1 -1];
upperbound =[1 1];
%objective function
function f = distance(x) ;
A=x(1);
C=x(2);
f= (-1).*(10.361+0.40125.*A-0.34875.*C-0.78375.*A.*C);
end
function [c ceq]=const(x)
A=x(1);
C=x(2);
c=A+C-2;
ceq=[];
end
the answer is x=1 y=1 , not x=1 y=-1 that i saw by surface plot !!!!!! plz help me
in my picture, it says optimal point is x= 1, y=1
altough the coordinate is differant (1,1)=/ (1,-1)
result of maximum distance is same

1 个评论

in my picture, it says optimal point is x= 1, y=1
It doesn't say that, as far as I can see.

请先登录,再进行评论。

回答(1 个)

Hi Jong,
It is my understanding that the minimum coordinates on the surface plot subjected to the objective function calculated using “fmincon” function is different from the visually observed minimum coordinates. This is due to improper syntax of the used "fmincon" function.
Here's the corrected syntax to use to obtain the desired solution-
distance = @(x) -1 * (10.361 + 0.40125 * x(1) - 0.34875 * x(2) - 0.78375 * x(1) * x(2));
Since the bounds of the parameters is defined as below -
lb = [-1, -1];
ub = [1, 1];
This implies that x1+x2<=2, Which as per the documentation can be modelled as follows-
A =[1,1];
b = 2;
Aeq =[];
Beq =[];
x0 =[0, 0];
x_min =fmincon(distance,x0,[1 1],2,[],[],lb,ub);
Read through the below mentioned documentation on "fmincon" for more details
Hope this helps!
Regards,
Vinayak Luha

类别

帮助中心File Exchange 中查找有关 Get Started with Optimization Toolbox 的更多信息

产品

版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by