The nth-degree Taylor Polynomial for a function
If
A Maclaurin series is a special case of a Taylor series where
Let's find 6th degree Taylor Polynomial for
f:sin(2*x)$
makelist(diff(f,x,k),k,0,6)$
subst(x=%pi/6,%);
Here are the values returned by Maxima:
Rather than just finding the numerators, we could go ahead and divide by
The spacing below is not necessary, I just put it in there to make things easier to follow.
f:sin(2*x)$
makelist( subst(x=%pi/6, diff(f,x,k) ) /k!,k,0,6);
Here are the values returned by Maxima:
To create the polynomial from the terms, we need to change it from a sequence into a sum. That means switching from makelist() to sum(). We also need to multiply by
f:sin(2*x)$
sum(subst(x=%pi/6,diff(f,x,k))/k!*(x-%pi/6)^k,k,0,6);
The above was good for understanding the process, but not useful if you need to do any real work with Taylor series. Thankfully, Maxima has a taylor() command built into it. The syntax of the command is "taylor(function, variable, point, degree)".
taylor(sin(2*x),x,%pi/6,6);
The output is also nicer looking than what we came up with.
You may notice that there is a
f:sin(2*x)$
g:taylor(sin(2*x),x,%pi/6,6);
draw2d(
dimensions = [800,500],
xrange = [-1,2.5],
yrange = [-1.35,1.15],
xaxis = true, xaxis_type = solid, xaxis_width = 1,
xaxis_color = orange, xtics = 1,
yaxis = true, yaxis_type = solid, yaxis_width = 1,
yaxis_color = orange, ytics = 1,
font = Arial,
font_size = 14,
nticks = 250,
color = blue,
line_width = 3,
line_type = solid,
explicit(f,x,-1,2.5),
label(["f",-0.75,-0.9]),
color = red,
line_width = 2,
explicit(g,x,-1,2.5),
label(["T_6",-0.7,-1.2])
)$
A good way to see how close your approximation is to the actual value is to graph the remainder
However, if you graph the remainder, you don't get what you expect. You get 0.No matter how much you zoom in vertically, you still get that the two are equal to each other. To get around this, you can use the trunc() function, which will truncate or drop the remainder on the Taylor series approximation.
f:sin(2*x)$
g:taylor(sin(2*x),x,%pi/6,6);
draw2d(
dimensions = [800,500],
xrange = [-1,2.5],
xaxis = true, xaxis_type = solid, xaxis_width = 1,
xaxis_color = orange, xtics = 1,
yaxis = true, yaxis_type = solid, yaxis_width = 1, yaxis_color = orange,
font = Arial,
font_size = 14,
nticks = 250,
color = blue,
line_width = 3,
line_type = solid,
explicit(f-trunc(g),x,-1,2.5)
)$