Factoring out a smaller equation, using symbolic math, from a larger equation
17 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
richard
am 14 Mär. 2022
Bearbeitet: John D'Errico
am 14 Mär. 2022
Greetings All!
Symbolic math is giving me an output here:
u_Version2 = Vin - L*dx1d - rL*x1d - L^2*kR1*x1d + L^2*kR1*x1
How can I tell Matlab to group the term (x1 - x1d) together? I have tried to use the "collect(u_Version2, x1 - x1d)" and "factor" functions, but no luck - Matlab just returns the same equation (no change). What I want is for Matlab to arrange terms like so:
u_Version2 = Vin - L*dx1d - rL*x1d - L^2*kR1*(x1 - x1d) (notice that "x1 - x1d" is now "collected" together)
In my near future, the above expression will get more complicated, so factoring out terms like "x1-x1d" will be very helpful.
Is there a way to do this?
0 Kommentare
Akzeptierte Antwort
John D'Errico
am 14 Mär. 2022
Bearbeitet: John D'Errico
am 14 Mär. 2022
You were using collect in the wrong way. You were thinking in terms of what you wanted to see INSIDE the parens. Instead, you need to think about what those terms have in common. In your question, what they had in common was the sub-expression L^2*kR1.
Note that collect can help, at least to some extent. For example:
syms a b c d x y
U = a + b - c*d + x*a + x*c - y*c + d
collect(U,x)
The idea of collect is it tries to express the result as a polynomial in the term you indicate. So here it found all terms that had x^1 in them, collecting them together.
However, it seems like collect is not as smart as I might want it to be. It looks like collect is able to best identify a single variable. For example, in V, we see that it did not recognize that there were three terms with x*y in them, and we might want to see it collect a factored term like x*y*(a - c*d +c).
V = x*y*a + b - x*y*c*d + x*y*c + d
collect(V,x*y)
Now, I suppose you might do this:
syms w
Vw = subs(V,x*y,w)
And now you could try a collect on w, and then recover the expression we want to see.
subs(collect(Vw,w),w,x*y)
That did work. (There may easily be other ways to accomplish what I did here too.) Regardless, sometimes directing a symbolic tool to do what you think is obvious can take a little effort.
Anyway, can collect handle your task?
syms Vin L dx1d rL x1d kR1 x1
u_Version2 = Vin - L*dx1d - rL*x1d - L^2*kR1*x1d + L^2*kR1*x1
collect(u_Version2,L^2*kR1)
As you can see, collect fails, if we try the direct approach. But the sneaky, indirect approach does work, as you see here:
subs(collect(subs(u_Version2,L^2*kR1,w),w),w,L^2*kR1)
subs in this case is apparently a synonym for subterfuge.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Assumptions 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!