Taylor Polynomial possible "bug" in return

18 views
Skip to first unread message

LFS

unread,
Jan 10, 2013, 6:09:05 AM1/10/13
to sage-s...@googlegroups.com
Hiya, Probably I am just doing something wrong ...
I have a cubic polynomial p(x) with "regular" coefficients and I wanted coefficients around e.g. (x-1). So I did p1=p.taylor(x,1,3).
I get:
x |--> 0.085*(x - 1)^3 - 0.255*(x - 1)^2 + 0.34*x + 1.23
The polynomial is correct, but look at the last two terms.
The 1-degree term is in x not in (x-1) and the difference has been added to the 0-degree term. 

I think i should get:
x |--> 0.085*(x - 1)^3 - 0.255*(x - 1)^2 + 0.34*(x-1) + 1.57

See (scroll all the way to the bottom): http://sage.math.canterbury.ac.nz/home/pub/237/

Thanks for any help. Linda

LFS

unread,
Jan 10, 2013, 7:15:39 AM1/10/13
to sage-s...@googlegroups.com

Little more: I see canterbury is using 4.8. Maybe this is fixed in version 5?

Burcin Erocal

unread,
Jan 10, 2013, 7:35:46 AM1/10/13
to sage-s...@googlegroups.com
On Thu, 10 Jan 2013 03:09:05 -0800 (PST)
LFS <lfah...@gmail.com> wrote:

> Hiya, Probably I am just doing something wrong ...
> I have a cubic polynomial p(x) with "regular" coefficients and I
> wanted coefficients around e.g. (x-1). So I did p1=p.taylor(x,1,3).
> I get:
>
> x |--> 0.085*(x - 1)^3 - 0.255*(x - 1)^2 + 0.34*x + 1.23
> The polynomial is correct, but look at the last two terms.
>
> The 1-degree term is in x not in (x-1) and the difference has been
> added to the 0-degree term.
>
> I think i should get:
>
> x |--> 0.085*(x - 1)^3 - 0.255*(x - 1)^2 + 0.34*(x-1) + 1.57

The taylor() method calls maxima. Maxima returns the expected result,
but while converting the expression back to Sage, we "normalize" it,
and expand the linear term.

sage: ps
2*x^3 - x^2 + 2*x + 1
sage: mps = maxima(ps)
sage: mps
2*x^3-x^2+2*x+1
sage: mps.taylor(x, 1, 3)
4+6*(x-1)+5*(x-1)^2+2*(x-1)^3
sage: ps.taylor(x, 1, 3)
2*(x - 1)^3 + 5*(x - 1)^2 + 6*x - 2


Note that series() does the right thing:

sage: ps.series(x==1, 3)
4 + 6*(x - 1) + 5*(x - 1)^2 + Order((x - 1)^3)


There is a ticket to deprecate taylor() or switch it to use series():

http://trac.sagemath.org/sage_trac/ticket/6119

This requires some work to identify differences in the behavior of
these two functions and figure out how to best remedy these. Any help
is much appreciated.


Cheers,
Burcin

LFS

unread,
Jan 10, 2013, 12:01:32 PM1/10/13
to sage-s...@googlegroups.com
Hiya Burcin,
Thanks for reply!
For my cubic polynomials p0 and p1, I did get the following to work:
p0=p.series(x==xD[0],4)
p1=q.series(x==xD[1],4)
print p0; p1
x |--> 1.0600000000000001 + 0.59499999999999997*x +
(-0.08500000000000002)*x^3
x |--> 1.5699999999999998 + 0.34000000000000008*(x - 1) +
(-0.25500000000000006)*(x - 1)^2 + 0.08500000000000002*(x - 1)^3

(I am guessing that here (a) you must add one more degree than you want and (b) if the derivative is not zero, you get the Order thing indicating a remainder??)
 I did like the taylor command. It was easy to understand and the syntax was intuitive (good for people like me). I don't mind the Order thing so much, but the x==1, I don't like.
BTW: The wolframalpha command is: series[0.085*x^3 - 0.510*x^2 + 1.105*x + 0.890,(x,1,3)]
I know next to nothing about programming so I hope someone else offers to help :)
Thanks again.
Linda

Reply all
Reply to author
Forward
0 new messages