Ask Your Question

Pade approximation

asked 2016-03-05 19:17:51 +0200

vkristijan gravatar image

How to use the pade function to calculate the pade approximation of a function. I have a function (for example arctan(x) ) and would like to calculate the pade approximation of that function. I have found that there exists a function for that in sage, but I was not able to run it, could someone help me with that?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2016-03-05 21:06:37 +0200

tmonteil gravatar image

Let f be your function, here a symbolic expression:

sage: f = arctan(x)
sage: f.parent()
Symbolic Ring

If you search for "pade sagemath" you will get this page so you have first to transform the symbolic expression arctan(x) into a power series. As you can see, the symbolic expression has a method named power_series, so let us try it:

sage: f.power_series(QQ)
TypeError: unable to convert arctan(x) to a rational

The problem is that, currently, Sage is not able to transform such a symbolic expression into a power series, only the expressions that are polynomials, see the doc of the method by typing f.power_series

So, you have first to approximate f to a truncated power series, also known as Taylor expansion:

sage: f.taylor(x,0,12)
-1/11*x^11 + 1/9*x^9 - 1/7*x^7 + 1/5*x^5 - 1/3*x^3 + x

Then you can get it as a power series over the rationals:

sage: f.taylor(x,0,12).power_series(QQ)
x - 1/3*x^3 + 1/5*x^5 - 1/7*x^7 + 1/9*x^9 - 1/11*x^11 + O(x^12)

Then you can get the pade approximant of your choice:

sage: f.taylor(x,0,12).power_series(QQ).pade(3,3)
(4/9*x^3 + 5/3*x)/(x^2 + 5/3)

Of course, the higher pade approximant you require, the higer the degree in the Taylor expansion:

sage: f.taylor(x,0,12).power_series(QQ).pade(10,10)
ValueError: the precision of the series is not large enough

sage: f.taylor(x,0,42).power_series(QQ).pade(10,10)
(61567/3969*x^9 + 106964/441*x^7 + 44902/45*x^5 + 281996/189*x^3 + 46189/63*x)/(x^10 + 55*x^8 + 1430/3*x^6 + 1430*x^4 + 12155/7*x^2 + 46189/63)
edit flag offensive delete link more


Hi, is it possible to go back to a power series? If I give

sage: f.taylor(x,0,12).power_series(QQ).pade(3,3).taylor(x,0,12)

I get the error: AttributeError: 'FractionFieldElement_1poly_field' object has no attribute 'taylor'

Marco Caliari gravatar imageMarco Caliari ( 2017-08-29 13:40:52 +0200 )edit

That's because the rational function in x returned by pade is not a symbolic expression. You can cast it back into the SymbolicRing and then take the Taylor series:

sage: SR(f.taylor(x, 0, 12).power_series(QQ).pade(3, 3)).taylor(x, 0, 12) -27/625*x^11 + 9/125*x^9 - 3/25*x^7 + 1/5*x^5 - 1/3*x^3 + x

AlexGhitza gravatar imageAlexGhitza ( 2020-07-23 01:51:33 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2016-03-05 19:17:51 +0200

Seen: 1,626 times

Last updated: Mar 05 '16