Filter löschen
Filter löschen

Solve system of 3 variable equations

61 Ansichten (letzte 30 Tage)
Abdullah Azzam
Abdullah Azzam am 21 Jan. 2019
Bearbeitet: Stephan am 21 Jan. 2019
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 Kommentare
Torsten
Torsten am 21 Jan. 2019
Bearbeitet: Torsten am 21 Jan. 2019
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 am 21 Jan. 2019
X1 X2 and X3 are user inputs based on their value the program find the appropriate value for a b and c

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Stephan
Stephan am 21 Jan. 2019
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 Kommentare
madhan ravi
madhan ravi am 21 Jan. 2019
It gives No solution found. , what values did you give to X1,X2 and X3 Stephen?
Stephan
Stephan am 21 Jan. 2019
Bearbeitet: Stephan am 21 Jan. 2019
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.

Melden Sie sich an, um zu kommentieren.

Produkte


Version

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by