MATLAB: Factoring a symbolic matrix

factoriseMATLABmatrixsymbolic matrixsymbolic toolbox

hi,
I've a symbolic matrix as following :
[s/((s^2 + w1^2)*L), w1/((s^2 + w1^2)*L); (-w1)/((s^2 + w1^2)*L), s/((s^2 + w1^2)*L)]
how can I factorize statement :
(s^2 + w1^2)*L
from all elements?
thx

Best Answer

The expression appears in the denominator of all the elements of the matrix, so just multiply it:
syms s w1 L
Eq = [s/((s^2 + w1^2)*L), w1/((s^2 + w1^2)*L); (-w1)/((s^2 + w1^2)*L), s/((s^2 + w1^2)*L)];
Eqf = Eq * (s^2 + w1^2)*L
producing:
Eqf =
[ s, w1]
[ -w1, s]
Another option is:
[n,d] = numden(Eq)
producing:
n =
[ s, w1]
[ -w1, s]
d =
[ L*(s^2 + w1^2), L*(s^2 + w1^2)]
[ L*(s^2 + w1^2), L*(s^2 + w1^2)]
.