Ask Your Question

Revision history [back]

Use the taylor method to get a Taylor polynomial. This needs to be done in the symbolic ring since the power series ring is purely algebraic and doesn't know about derivatives.

sage: t = var('t')
sage: f = sin(t)
sage: s_poly = f.taylor(t,0,7)
sage: s_poly
-1/5040*t^7 + 1/120*t^5 - 1/6*t^3 + t
sage: s_poly.parent()
Symbolic Ring

The power_series method will convert the Taylor polynomial to a power series for you:

sage: s_ser = s_poly.power_series(QQ)
sage: s_ser
t - 1/6*t^3 + 1/120*t^5 - 1/5040*t^7 + O(t^8)
sage: s_ser.parent()
Power Series Ring in t over Rational Field

sage: g = cos(t)
sage: c_poly = g.taylor(t,0,7)
sage: c_poly
-1/720*t^6 + 1/24*t^4 - 1/2*t^2 + 1
sage: c_ser = c_poly.power_series(QQ)
sage: c_ser
1 - 1/2*t^2 + 1/24*t^4 - 1/720*t^6 + O(t^7)

Over the power series ring, you can do arithmetic with the power series. Note that you will need to change "t" from the generator of the symbolic ring to the generator of the power series ring in order to use things like t+2:

sage: t.parent()
Symbolic Ring

sage: t = s_ser.parent().gen()
sage: t.parent()
Power Series Ring in t over Rational Field

sage: s_ser/c_ser(t+2)
-45/19*t + 1890/361*t^2 - 83085/6859*t^3 + 3677670/130321*t^4 - 649441779/9904396*t^5 + 7173329982/47045881*t^6 - 17745663554041/50056817384*t^7 + O(t^8)