1
votes

I have done partial fraction decomposition to a symbolic polynomial in MATLAB, which gives me a symbolic expression like e.g. the following:

poly = -2i/(x - 1.0 - 1.7i) + 0.57i/(x - 1.0 + 1.1559i)

As you see, this symbolic expression contains both x-variables and constant complex numbers. How can I extract all the numeric values from this expression in MATLAB? The information whether the number is real or complex must not be lost.

So for the given expression poly, how would I get the following matrix A:

A = [-2i, -1-1.7i; .57i, -1+1.1559i]

A =

     0 - 2i        -1 - 1.7i
     0 + 0.57i     -1 + 1.1559i

Please also note that A should contain numbers, not symbolic expressions as poly does.


I read of coeffs-function, but it requires the input being a polynomial. With children-function I am able to divide the summation terms in the symbolic expression to vector of symbolic expressions as shown below:

p = - 0.57735026918962576450914878050196i/(x - 1.0 - 1.7320508075688772935274463415059i) + 0.57735026918962576450914878050196i/(x - 1.0 + 1.7320508075688772935274463415059i);
terms = children(p)

terms = 
[ -0.57735026918962576450914878050196i/(x - 1.0 - 1.7320508075688772935274463415059i), 0.57735026918962576450914878050196i/(x - 1.0 + 1.7320508075688772935274463415059i)]
1

1 Answers

7
votes

Let me start with that I don't really know what you want to use this for. However, as long as your expressions follow this strict form (i.e. the sum of fractions of the form A/(x+B)), you can hack up a solution to your problem.

I'll be working with your sample input (renamed to pol in order not to shadow the function named poly):

x = sym('x');
pol = -2i/(x - 1.0 - 1.7i) + 0.57i/(x - 1.0 + 1.1559i);

First, cut this into two fractions with children:

fractions = children(pol);
frac1 = fractions(1);

Now, decompose a fraction using numden:

[n,d] = numden(frac1);
A = n;

Now we have terms for a fraction of the form A/(B*x+C), where n == A and d == B*x + C. You can extract the latter two parameters in multiple ways, I prefer calculus:

B = diff(d,x);
C = subs(d,x,0);

Now you know that your first fraction is A/(B*x+C), or if you want you can divide A and C by B to get the "canonical" form of your fraction. Do the same for the second (and further, if any) child of pol.

Check:

>> simplify(frac1 == A/(B*x+C))

ans =

TRUE