laozian mao
laozian mao

Reputation: 75

Series expansion of a function about infinity - how to return coefficients of series as a Matlab array?

This question is connected to this one. Suppose again the following code:

syms x
f = 1/(x^2+4*x+9)

Now taylor allows the function f to be expanded about infinity:

ts = taylor(f,x,inf,'Order',100)

But the following code

c = coeffs(ts)

produces errors, because the series does not contain positive powers of x (it contains negative powers of x).

In such a case, what code should be used?

Upvotes: 0

Views: 839

Answers (2)

horchler
horchler

Reputation: 18504

The output from taylor is not a multivariate polynomial, so coeffs won't work in this case. One thing you can try is using collect (you may get the same or similar result from using simplify):

syms x
f = 1/(x^2 + 4*x + 9);
ts = series(f,x,Inf,'Order',5) % 4-th order Puiseux series of f about 0
c = collect(ts)

which returns

ts =

1/x^2 - 4/x^3 + 7/x^4 + 8/x^5 - 95/x^6


c =

(x^4 - 4*x^3 + 7*x^2 + 8*x - 95)/x^6

Then you can use numden to extract the numerator and denominator from either c or ts:

[n,d] = numden(ts)

which returns the following polynomials:

n =

x^4 - 4*x^3 + 7*x^2 + 8*x - 95


d =

x^6

coeffs can then be used on the numerator. You may find other functions listed here helpful as well.

Upvotes: 2

TroyHaskin
TroyHaskin

Reputation: 8401

Since the Taylor Expansion around infinity was likely performed with the substitution y = 1/x and expanded around 0, I would explicitly make that substitution to make the power positive for use on coeffs:

syms x y
f      = 1/(x^2+4x+9);
ts     = taylor(f,x,inf,'Order',100);
[c,ty] = coeffs(subs(ts,x,1/y),y);
tx     = subs(ty,y,1/x);

Upvotes: 3

Related Questions