equate the parameters of two equations in symbolic

3 次查看(过去 30 天)
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

采纳的回答

Star Strider
Star Strider 2015-4-22
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

更多回答(1 个)

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

类别

Help CenterFile Exchange 中查找有关 Symbolic Math Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by