equate the parameters of two equations in symbolic

3 vues (au cours des 30 derniers jours)
Elric
Elric le 22 Avr 2015
Commenté : Star Strider le 22 Avr 2015
Hello,
I have two equations, one with known parameters and one with unknown. I would like to ask for a simple way to solve the system that equates the parameters for the two equations
e.g.
eq. 1 = (a2 - a1 - a3 + 1)*x1 + (2*a1 - a2 - 3)*x2 + (3 - a1)*x3
eq. 2 = 0.957*x1 - 0.253*x2 + 0.119*x3
Of course in this simple case it is easy to see that a1=2.043, a2=1.339 and a3=0.177.
One manual way that I have found to work is to create two sym vectors that v1 and v2 that contain the parameters of x1,x2 and x3 and then use the solve function
p=solve(y==b)
However this method solves the solution into a structure p.a1, p.a2 and p.a3 which is not convient (I would like to have it a vector) And second I have to manually create the sym vectors v1 and v2 which again is not convenient when I have to repeat the same thing for different equations of different orders.
Any ideas to work around this problem?
thank you in advance

Réponse acceptée

Star Strider
Star Strider le 22 Avr 2015
You can easily create the vector yourself in the format you choose from these results:
syms a1 a2 a3 x1 x2 x3
eq1 = (a2 - a1 - a3 + 1)*x1 + (2*a1 - a2 - 3)*x2 + (3 - a1)*x3;
eq2 = 0.957*x1 - 0.253*x2 + 0.119*x3;
[C1,T] = coeffs(eq1, [x1, x2, x3]);
[C2,T] = coeffs(eq2, [x1, x2, x3]);
[a1, a2, a3] = solve(C1 == C2, [a1, a2, a3])
producing:
a1 =
2881/1000
a2 =
603/200
a3 =
177/1000

Plus de réponses (1)

Elric
Elric le 22 Avr 2015
Hi Star Strider, the coeffs function was what I was looking for!
Thank you!

Catégories

En savoir plus sur Symbolic Math Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by