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
댓글 수: 0
채택된 답변
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
댓글 수: 0
추가 답변 (1개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!