Solve system of 3 variable equations

103 visualizaciones (últimos 30 días)
Abdullah Azzam
Abdullah Azzam el 21 de En. de 2019
Editada: Stephan el 21 de En. de 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 comentarios
Torsten
Torsten el 21 de En. de 2019
Editada: Torsten el 21 de En. de 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 el 21 de En. de 2019
X1 X2 and X3 are user inputs based on their value the program find the appropriate value for a b and c

Iniciar sesión para comentar.

Respuestas (1)

Stephan
Stephan el 21 de En. de 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 comentarios
madhan ravi
madhan ravi el 21 de En. de 2019
It gives No solution found. , what values did you give to X1,X2 and X3 Stephen?
Stephan
Stephan el 21 de En. de 2019
Editada: Stephan el 21 de En. de 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.

Iniciar sesión para comentar.

Categorías

Más información sobre Particle & Nuclear Physics en Help Center y File Exchange.

Productos


Versión

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by