Download MuPAD from SciFace

MuPAD Pro Computing Essentials - Examples 

Example 12.5 - Taylor Polynomials

Problem: for a given function plot some of its Taylor polynomials. This is interesting to see how Taylor polynomials approximate the given function. Here we will use the function y=sin(x). 

taylorPol := proc(expr, var, n)
   local u, i, newexpr;
begin
   u := taylor(expr,var,n);
   newexpr := 0;
   for i from 0 to n-1 do
       newexpr := newexpr + coeff(u,i)*x^i
   end;
   return(newexpr)
end:
 
export(plot, Function2d):
range := (x=0..4*PI, y=-2..2):

h6 := Function2d(taylorPol(sin(x), x, 6), range):
h8 := Function2d(taylorPol(sin(x), x, 8), range):
h14 := Function2d(taylorPol(sin(x), x, 14), range):
h16 := Function2d(taylorPol(sin(x), x, 16), range):
h24 := Function2d(taylorPol(sin(x), x, 24), range):
h30 := Function2d(taylorPol(sin(x), x, 30), range):
 
MyFun := Function2d(sin(x),range,
   Color=RGB::Blue,
   LineWidth=15
):
 
plot(h6,h8,h14,h16,h24,h30,MyFun)

TOP