How to sort solution of multiple terms by variables?
9 次查看(过去 30 天)
显示 更早的评论
I have a solution which consists of multiple terms. Some of these terms have a common factor (a variable created with "syms", i.e. "k"). I want to sort these by that variable so that I get: k(term1 + term2) instead of term1*k + term2*k. I want to do this for multiple variables and terms (of the same solution). I tried simplify() but this didn't work. I use MATLAB R2018a.
What I have:
syms m s k X Y1 Y2 F1 F2
eqns = [m*s^2*Y1 == -k*(Y1-X)-k*(Y1-Y2)+F1 , m*s^2*Y2 == -k*(Y2-Y1)+F2];
vars = [Y1 Y2];
[Y1,Y2] = solve(eqns,vars)
The solution:
Y1 = (F1*k + F2*k + X*k^2 + F1*m*s^2 + X*k*m*s^2)/(k^2 + 3*k*m*s^2 + m^2*s^4)
Y2 = (F1*k + 2*F2*k + X*k^2 + F2*m*s^2)/(k^2 + 3*k*m*s^2 + m^2*s^4)
What I want: sort by X, F1 and F2 like below
Y1 = ((m*k*s^2+k^2)*X + (m*s^2+k)*F1 + k*F2)/(k^2 + 3*k*m*s^2 + m^2*s^4)
Y2 = (k^2*X + k*F1 + (m*s^2+2*k)*F2)/(k^2 + 3*k*m*s^2 + m^2*s^4)
Is there a way to do this?
Thanks in advance!
0 个评论
采纳的回答
更多回答(0 个)
另请参阅
类别
在 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!