How to solve 4 equations with 4 unknowns with bounds?

4 ビュー (過去 30 日間)
KY
KY 2019 年 4 月 19 日
回答済み: Alex Sha 2019 年 5 月 16 日
Hi everyone, I'm trying to solve this but the message displayed local minimum found and also the values of the x generated did not match with the boundary which was set ie. x(1)+x(2) = Ym. It also says lsqnonlin stopped because the final change in the sum of squares relative to its initial value is less than the value of the function tolerance.Could anyone help with this? Many thanks!
clear; clc;
x0 = [50; 50; 50; 50;];
options = optimoptions('fsolve','Display','iter');
%[x,fval] = fsolve(@myfun,x0,options)
lb = [0; 0; 0; 0;];
ub = [100; 100; 100; 100;];
x = lsqnonlin(@myfun,x0,lb,ub)
myfun(x)
function F = myfun(x)
A = 87.3145;
B = -0.289762;
C = 0.0000199677;
alpha = 0.4705;
Xm = 20;
Ym = 27.5;
F = [x(1)+x(2)-Ym;
x(3)+x(4)-Xm;
A*exp(B*x(3)^0.5 - C*x(3)^3) - x(1);
A*exp(B*x(4)^0.5 - C*x(4)^3) - x(2);
Ym/alpha - ((1-alpha)/alpha)*x(2) - x(1);
Xm/alpha - ((1-alpha)/alpha)*x(4) - x(3);
]
end

採用された回答

Alan Weiss
Alan Weiss 2019 年 4 月 22 日
  1. You set options for fsolve, but then call lsqnonlin. This is a mistake.
  2. You do not pass options to the solver. This might be a mistake.
  3. You have six equations in four unknowns. Generally, you should not expect a solution to such a system, only a point that is a local minimum of the sum of squares.
Alan Weiss
MATLAB mathematical toolbox documentation
  1 件のコメント
KY
KY 2019 年 4 月 23 日
Thank you Alan. I've edited it, add a tighter constraint based on my situation, and it works.
x0 = [10; 10; 10; 10;];
%options = optimoptions('fsolve','Display','iter');
%[x,fval] = fsolve(@myfun,x0,options)
lb = [5.31; 5.31; 0.68; 0.68;];
ub = [68.80; 68.80; 37.24; 37.24;];
x = lsqnonlin(@myfun,x0,lb,ub)
myfun(x)
function F = myfun(x)
A = 87.3145;
B = -0.289762;
C = 0.0000199677;
alpha = 0.3935;
Xm = 20;
Ym = 22.5;
F = [ A*exp(B*x(3)^0.5 - C*x(3)^3) - x(1);
A*exp(B*x(4)^0.5 - C*x(4)^3) - x(2);
Ym/alpha - ((1-alpha)/alpha)*x(2) - x(1);
Xm/alpha - ((1-alpha)/alpha)*x(4) - x(3);
]
end

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

その他の回答 (1 件)

Alex Sha
Alex Sha 2019 年 5 月 16 日
Refer the results below:
x1: 7.73410323214524
x2: 32.0801819920043
x3: 33.4573119565274
x4: 11.2688338748665

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by