# Trying to find the best Padé approximant for a given number of terms

Let suppose that I have a function $f[x]$ I want to approximate using a Padé expansion and that I decide what would be maximum number of terms to be used.

Is there any way with Mathematica to find what have to be the degrees of numerator and denominator in order to have the best approximation over a given range of $x$ ?

Doing this manually is, as one could expect, quite tedious. Any help and suggestion will be really appreciated.

• I'm not really sure how this question can be well-posed, because it's not clear what you mean by "best." Is that maximum absolute deviation? Mean deviation? And then, how do you reconcile that with the fact that the order $(n,d)$ Padé approximant generally improves with increasing $n$ and $d$? If your condition is to fix the sum of polynomial degrees, then it then becomes a computational exercise to go through all the approximants and measure the "goodness" by whatever metric you want. – heropup Feb 4 '14 at 7:53
• @heropup. I said that $n+d$ if fixed as well as the interval of $x$. What I would like is to be able to "automate" the process. The "best" could be defined the manner you want (say : lowest maximum absolute deviation). – Claude Leibovici Feb 4 '14 at 7:59
• No need for Mathematica in this case; it is known (see e.g. this or this) that the "diagonal" approximants (numerator and denominator degrees differ by at most 1) are usually the best approximants of a given function in the Padé table. Thus, if the number of series terms is even, use half that number for the numerator and denominator degrees. If you have an odd number of terms, you can have the numerator or denominator have the higher degree; you will have to check that for yourself. – J. M.'s discontentment Apr 20 '16 at 6:58

This is very slow but here it goes:

wPade[F_, x_, xo_, a_, b_, n_] := Sort[Table[{{m, n - m}, NIntegrate[Abs[F - PadeApproximant[F, {x, xo, {m, n - m}}]], {x, a, b}]} , {m, 1, n}] , #1[[2]] < #2[[2]] &][[1, 1]]
wPade[Sin[x], x, 0, 0, 1, 5]


where F is the function, x the variable, xo where the approximation is about, a and b the limits of the region, and n the sum of the upper and lower degrees

Edit

Now that MaximalBy is available

wPade[F_, x_, xo_, a_, b_, n_] := MinimalBy[Last][
Table[
{
{m, n - m}
, NIntegrate[
Abs[F - PadeApproximant[F, {x, xo, {m, n - m}}]], {x, a, b}]
}
, {m, 1, n}
]
][[1, 1]]

• Thanks a lot. This is exactly what I was looking for. – Claude Leibovici Feb 5 '14 at 9:15