フィルターのクリア

Solve system of 3 variable equations

61 ビュー (過去 30 日間)
Abdullah Azzam
Abdullah Azzam 2019 年 1 月 21 日
編集済み: Stephan 2019 年 1 月 21 日
Hi guys and thanks in advance. I am working on matlab code to solve me a system of 3 variables (a, b and c) and print them out. Here is my code:
X1=input('X1');
X2=input('X2');
X3=input('X3');
syms a b c
eq1= a+b;
eq2=a+b*exp(-105*c);
eq3=a+b*exp(-180*c);
eqns=[eq1==X1, eq2==X2, eq3==X3];
S = solve(eqns, [a b c])
S.a
S.b
S.c
However, when I run to check it the solver keep running forever. I also tried to write the full equations like this
eqns=[a+b==X1, a+b*exp(-105*c)==X2, a+b*exp(-180*c)==X3];
But still didn't work either.
I appreciate if someone can tell me where my mistake is and help correct it.
Again Thanks in advance.
  3 件のコメント
Torsten
Torsten 2019 年 1 月 21 日
編集済み: Torsten 2019 年 1 月 21 日
An analytical solution for a, b and c does not exist. You will have to specify values for X1, X2 and X3 to get a numerical solution.
Abdullah Azzam
Abdullah Azzam 2019 年 1 月 21 日
X1 X2 and X3 are user inputs based on their value the program find the appropriate value for a b and c

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

回答 (1 件)

Stephan
Stephan 2019 年 1 月 21 日
Hi,
since you want to calculate values, follow Torstens suggestion and use fsolve to solve your nonlinear system:
X1 = input('X1');
X2 = input('X2');
X3 = input('X3');
options = optimoptions('fsolve','display','off');
x = fsolve(@(x)eqs(x,X1,X2,X3),ones(1,3),options);
fprintf('a = %.5f\nb = %.5f\nc = %.5f',x(1),x(2),x(3));
function F = eqs(x,X1,X2,X3)
a=x(1);
b=x(2);
c=x(3);
F(1)= a+b-X1;
F(2)= a+b.*exp(-105.*c)-X2;
F(3)=a+b.*exp(-180.*c)-X3;
end
Best regards
Stephan
  2 件のコメント
madhan ravi
madhan ravi 2019 年 1 月 21 日
It gives No solution found. , what values did you give to X1,X2 and X3 Stephen?
Stephan
Stephan 2019 年 1 月 21 日
編集済み: Stephan 2019 年 1 月 21 日
I think for this system there are a lot of combinations that will not have a solution. For X1=3, X2=X3=1 it works for example.

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

カテゴリ

Help Center および File ExchangeNumeric Solvers についてさらに検索

製品


リリース

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by