Filter löschen
Filter löschen

How to sort solution of multiple terms by variables?

2 Ansichten (letzte 30 Tage)
Arno Kinnen
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!

Akzeptierte Antwort

Nikolai Jakuba
Nikolai Jakuba am 20 Jun. 2018
Look here: https://de.mathworks.com/help/symbolic/collect.html.
  1 Kommentar
Arno Kinnen
Arno Kinnen am 20 Jun. 2018
This worked, only now I have 3 collected terms with 3 times the same denominator. Is there a way to get these terms together on that denominator?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

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!

Translated by