ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 05 Feb 2019 11:00:34 +0100Problem with Padé approximationhttps://ask.sagemath.org/question/45300/problem-with-pade-approximation/ I let
f(x)=cos(x)
and calculate the (2,4) Padé approximation of f:
f.taylor(x,0,10).power_series(QQ).pade(2,4)
Sage answers with
(-244/3*x^2 - 1/1512000*x + 200)/(x^4 - 1/18144000*x^3 + 56/3*x^2 - 1/1512000*x + 200)
which seems incorrect. (The Taylor series of this rational function has a x^3 term which differs from that of f.)
Am I doing something wrong, or is there a problem with sage?Mon, 04 Feb 2019 14:07:16 +0100https://ask.sagemath.org/question/45300/problem-with-pade-approximation/Answer by FrédéricC for <p>I let</p>
<p>f(x)=cos(x)</p>
<p>and calculate the (2,4) Padé approximation of f:</p>
<p>f.taylor(x,0,10).power_series(QQ).pade(2,4)</p>
<p>Sage answers with</p>
<p>(-244/3<em>x^2 - 1/1512000</em>x + 200)/(x^4 - 1/18144000<em>x^3 + 56/3</em>x^2 - 1/1512000*x + 200)</p>
<p>which seems incorrect. (The Taylor series of this rational function has a x^3 term which differs from that of f.)</p>
<p>Am I doing something wrong, or is there a problem with sage?</p>
https://ask.sagemath.org/question/45300/problem-with-pade-approximation/?answer=45314#post-id-45314Here is what I get with sage 8.7.beta2. This seems to be correct. Which version of sage are you using ?
sage: x = QQ[['x']].0
sage: f = x.cos()
sage: f.pade(2,4)
(-244/3*x^2 + 200)/(x^4 + 56/3*x^2 + 200)
sage: f.pade(2,4)(x)
1 - 1/2*x^2 + 1/24*x^4 - 1/720*x^6 - 17/216000*x^8 + 463/32400000*x^10 - 9139/9720000000*x^12 + 23771/1458000000000*x^14 + 1390687/437400000000000*x^16 - 24818093/65610000000000000*x^18 + O(x^20)
sage: f
1 - 1/2*x^2 + 1/24*x^4 - 1/720*x^6 + 1/40320*x^8 - 1/3628800*x^10 + 1/479001600*x^12 - 1/87178291200*x^14 + 1/20922789888000*x^16 - 1/6402373705728000*x^18 + O(x^20)Mon, 04 Feb 2019 20:01:46 +0100https://ask.sagemath.org/question/45300/problem-with-pade-approximation/?answer=45314#post-id-45314Comment by Tomas Persson for <p>Here is what I get with sage 8.7.beta2. This seems to be correct. Which version of sage are you using ?</p>
<pre><code>sage: x = QQ[['x']].0
sage: f = x.cos()
sage: f.pade(2,4)
(-244/3*x^2 + 200)/(x^4 + 56/3*x^2 + 200)
sage: f.pade(2,4)(x)
1 - 1/2*x^2 + 1/24*x^4 - 1/720*x^6 - 17/216000*x^8 + 463/32400000*x^10 - 9139/9720000000*x^12 + 23771/1458000000000*x^14 + 1390687/437400000000000*x^16 - 24818093/65610000000000000*x^18 + O(x^20)
sage: f
1 - 1/2*x^2 + 1/24*x^4 - 1/720*x^6 + 1/40320*x^8 - 1/3628800*x^10 + 1/479001600*x^12 - 1/87178291200*x^14 + 1/20922789888000*x^16 - 1/6402373705728000*x^18 + O(x^20)
</code></pre>
https://ask.sagemath.org/question/45300/problem-with-pade-approximation/?comment=45315#post-id-45315Merci! I am running version 6.6, which gives error messages already for your "f = x.cos()".
However, the answer which you get is not correct either. By definition the (2,4) Pade approximation is a rational function p/q where p is of degree at most 2 and q of degree at most 4.Mon, 04 Feb 2019 21:01:06 +0100https://ask.sagemath.org/question/45300/problem-with-pade-approximation/?comment=45315#post-id-45315Comment by Tomas Persson for <p>Here is what I get with sage 8.7.beta2. This seems to be correct. Which version of sage are you using ?</p>
<pre><code>sage: x = QQ[['x']].0
sage: f = x.cos()
sage: f.pade(2,4)
(-244/3*x^2 + 200)/(x^4 + 56/3*x^2 + 200)
sage: f.pade(2,4)(x)
1 - 1/2*x^2 + 1/24*x^4 - 1/720*x^6 - 17/216000*x^8 + 463/32400000*x^10 - 9139/9720000000*x^12 + 23771/1458000000000*x^14 + 1390687/437400000000000*x^16 - 24818093/65610000000000000*x^18 + O(x^20)
sage: f
1 - 1/2*x^2 + 1/24*x^4 - 1/720*x^6 + 1/40320*x^8 - 1/3628800*x^10 + 1/479001600*x^12 - 1/87178291200*x^14 + 1/20922789888000*x^16 - 1/6402373705728000*x^18 + O(x^20)
</code></pre>
https://ask.sagemath.org/question/45300/problem-with-pade-approximation/?comment=45316#post-id-45316Sorry! I read too fast, and misunderstood "f.pade(2,4)(x)" as the Pade approximation!
So the newer version seems to work, I should get a newer one.Mon, 04 Feb 2019 21:04:03 +0100https://ask.sagemath.org/question/45300/problem-with-pade-approximation/?comment=45316#post-id-45316Answer by Emmanuel Charpentier for <p>I let</p>
<p>f(x)=cos(x)</p>
<p>and calculate the (2,4) Padé approximation of f:</p>
<p>f.taylor(x,0,10).power_series(QQ).pade(2,4)</p>
<p>Sage answers with</p>
<p>(-244/3<em>x^2 - 1/1512000</em>x + 200)/(x^4 - 1/18144000<em>x^3 + 56/3</em>x^2 - 1/1512000*x + 200)</p>
<p>which seems incorrect. (The Taylor series of this rational function has a x^3 term which differs from that of f.)</p>
<p>Am I doing something wrong, or is there a problem with sage?</p>
https://ask.sagemath.org/question/45300/problem-with-pade-approximation/?answer=45326#post-id-45326Well...
sage: S=cos(x).taylor(x,0,10).power_series(QQ).pade(2,4);S
(-244/3*x^2 + 200)/(x^4 + 56/3*x^2 + 200)
sage: M=mathematica.PadeApproximant(cos(x),[x,0,[2,4]]).sage();M
-4*(61*x^2 - 150)/(3*x^4 + 56*x^2 + 600)
sage: bool(M==S)
True
By the way, the Padé approximation is slightly less precise than the Taylor development of the equivalent degree:
sage: S(x=pi).n()
-1.25140289236071
sage: cos(x).taylor(x,0,6)(x=pi).n()
-1.21135284298250
And `FredericC`'s solution is equivalent:
sage: t=QQ[['t']].0
sage: T=t.cos().pade(2,4);T
(-244/3*t^2 + 200)/(t^4 + 56/3*t^2 + 200)
sage: bool(T(x)==S)
True
Your Sage version (which is antique, by Sage standards...) gives you bullshit.
Tue, 05 Feb 2019 11:00:34 +0100https://ask.sagemath.org/question/45300/problem-with-pade-approximation/?answer=45326#post-id-45326