MATLAB: Is there any function I can use to change a symbolic formula to rational fraction with a user-specified denominator

denominatorfractionsMATLABpartialspecifysymbolicworkaround

How can I decompose an expression into partial fractions with user-specified denominators? For example, if I have the symbolic formula below:
     G = w^2/(x*(x^2+2*k*w*x+w^2))
Is there any MATLAB function I can use to calculate the symbolic partial fractions below:
     G = A/x + B/(x+k*w+i*sqrt(1-k^2)*w) + C/(x+k*w-i*sqrt(1-k^2)*w) 
So I can solve and get the coefficients, A, B and C?
 

Best Answer

The "partfrac" function calculates a partial fraction decomposition of symbolic expressions, but this function alone will not allow you to solve for A, B, and C in the above example. This is because "partfrac" automatically finds a standard factorization of the denominator for the decomposition, and does not allow for denominators of the decomposition to be specified by the user. For more information about the function, refer to the following documentation link:
There is a workaround that will allow you to calculate the numerators of the partial fractions with specified denominators. The steps for this workaround are shown below, with examples specific to the above question included:
1. First, you can use “partfrac” to find any numerators with denominators that are part of a standard factorization. In this example, "partfrac" can be used to find A, because the 1/s denominator of the A term is a part of a standard factorization of the expression in your first equation. An example of code you could execute to find this is shown below:
>>syms omega_n s xi
>>partfrac(omega_n ^2/(s*(s^2+2*s*xi* omega_n + omega_n ^2)),s)
ans =
1/s - (s + 2* omega_n *xi)/(s^2 + 2*xi*s* omega_n + omega_n ^2)
Thus, you can see that A = 1
2. Next, manually create a system of equations to solve for the other numerators. More specifically, to solve for B and C:
(s+2* omega_n xi)/(s^2+2*xi omega_n*s+ omega_n^2) = B/(s+xi* omega_n-j*sqrt(1-xi^2)* omega_n) + C/(s+xi* omega_n+j*sqrt(1-xi^2)* omega_n)
After some algebra, this yields:
B+C = 1
2* omega_n*xi = B*(omega_n*xi-j*omega_n*sqrt(1-xi^2))+C*(omega_n*xi +j*omega_n*sqrt(1-xi^2))
3. This system of equations can now be solved using the “solve” function. Here is an example of code that could be executed to do this step:
>>syms B C
>>eqns = [B+C == 1, 2* omega_n*xi == B*(omega_n*xi-j*omega_n*sqrt(1-xi^2))+C*(omega_n*xi +j*omega_n*sqrt(1-xi^2))];
>>S = solve(eqns,[ B,C]);
>>S.B
>>S.C