I have differnt coodinate after use fmincon

1 回表示 (過去 30 日間)
jong eun kim
jong eun kim 2022 年 12 月 4 日
コメント済み: jong eun kim 2022 年 12 月 4 日
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 have (1,-1) is the best coordinate and the maximum is 11.8947 but when i do this for fmincon, x0=[0 0]; lowerbound=[-1 -1]; upperbound =[1 1]; 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 a x=1 y=-1!!!!!! plz help me
  5 件のコメント
jong eun kim
jong eun kim 2022 年 12 月 4 日
nono i mistake the question i set lower=[-1 -1] upper=[1 1]
Torsten
Torsten 2022 年 12 月 4 日
Both Matt J and I already changed the settings.
And the result is as you expect: A = 1 and C = -1.

サインインしてコメントする。

採用された回答

Matt J
Matt J 2022 年 12 月 4 日
x0=[0 0]; lb=[-1 -1]; ub =-lb;
fmincon(@distance,x0,[1,1],2,[],[],lb,ub)
Local minimum found that satisfies the constraints. Optimization completed because the objective function is non-decreasing in feasible directions, to within the value of the optimality tolerance, and constraints are satisfied to within the value of the constraint tolerance.
ans = 1×2
1.0000 -1.0000
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
  4 件のコメント
jong eun kim
jong eun kim 2022 年 12 月 4 日
i reupload my question by more specificly. i think u dont understand my question. but thank you for your help
jong eun kim
jong eun kim 2022 年 12 月 4 日
plz check my new question sir

サインインしてコメントする。

その他の回答 (1 件)

Torsten
Torsten 2022 年 12 月 4 日
編集済み: Torsten 2022 年 12 月 4 日
x0=[0 0];
lowerbound =[-1 -1];
upperbound = [1 1];
sol = fmincon(@distance,x0,[1 1],2,[],[],lowerbound,upperbound)
Local minimum found that satisfies the constraints. Optimization completed because the objective function is non-decreasing in feasible directions, to within the value of the optimality tolerance, and constraints are satisfied to within the value of the constraint tolerance.
sol = 1×2
1.0000 -1.0000
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

カテゴリ

Help Center および File ExchangeNonlinear Optimization についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by