How to sort solution of multiple terms by variables?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Arno Kinnen
am 20 Jun. 2018
Kommentiert: Arno Kinnen
am 20 Jun. 2018
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 Kommentare
Akzeptierte Antwort
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Symbolic Math Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!