(*            Formula di Taylor       -2-     *)

taylor[f_,x0_,npas_][x_]:=f[x0]+Sum[(D[f[x],{x,k}]/.x->x0)/Factorial[k]*(x-x0)^k,{k,1,npas}]

f[x0]+Sum[(D[f[x],{x,k}]/.x->x0)/Factorial[k]*(x-x0)^k,{k,1,3}]

grafico[f_,x0_,nit_]:=Show[{
Plot[f[x],{x,-4Pi,4Pi},PlotStyle->{Thick,Blue},ImageSize->400,AspectRatio->Automatic,PlotRange->{-4,4}],
Graphics[{PointSize[0.02],Point[{{x0,0},{x0,f[x0]}}]}],
Plot[Evaluate[Table[taylor[f,x0,h][x],{h,0,nit}]],{x,-5Pi,5Pi},PlotStyle->{Thick}]
}
]

grafico[Sin,0,11]

Manipulate[taylor[Sin,0,k][x],{k,1,50,1}]

f[x_]:=Sin[x]

taylor[f,0,1][x]

taylor[f,0,5][x]

taylor[Sin,0,5][x]

Manipulate[taylor[Sin,0,k][x],{k,1,50,1}]

Manipulate[taylor[Sin,0.,k][x],{k,1,50,1}]

?Chop

Manipulate[Chop[taylor[Sin,0.,k][x]],{k,1,50,1}]

taylorn[f_,x0_,npas_][x_]:=f[x0]+Sum[N[(D[f[x],{x,k}]/.x->x0)/Factorial[k]]*(x-x0)^k,{k,1,npas}]

Manipulate[taylorn[Sin,0,k][x],{k,1,50,1}]

taylor[Exp,0,5][x]

taylor[Exp[-#^2]&,0,5][x]

Exp[-#^2]&[x]

Exp[-#^2]&[2x]

Manipulate[taylor[Exp,0,k][x],{k,1,100,1}]

Manipulate[taylor[Exp,1,k][x],{k,1,100,1}]

taylor[Exp,1,3][x]

Expand[taylor[Exp,1,3][x],x]

Collect[taylor[Exp,1,3][x],x]

taylor[Exp[-(a#^2)]&,1,3][x]

Expand[taylor[Exp[-(a#^2)]&,1,3][x],x]

Collect[%,x]

%/.a->3

grafico[f_,x0_,nit_]:=Show[{
Plot[f[x],{x,-4Pi,4Pi},PlotStyle->{Thick,Blue},ImageSize->400,AspectRatio->Automatic,PlotRange->{-4,4}],
Graphics[{PointSize[0.02],Point[{{x0,0},{x0,f[x0]}}]}],
Plot[Evaluate[Table[taylor[f,x0,h][x],{h,0,nit}]],{x,-5Pi,5Pi},PlotStyle->{Thick}]
}
]

grafico[Sin,0,4]

Manipulate[grafico[Sin,0,n],{n,0,30,1}]

grafico[f_,x0_,nit_,{{xmin_,xmax_},{ymin_,ymax_}}]:=Show[{
Plot[f[x],{x,-4Pi,4Pi},PlotStyle->{Thick,Blue},ImageSize->400],
Graphics[{PointSize[0.02],Point[{{x0,0},{x0,f[x0]}}]}],
Plot[Evaluate[Table[taylor[f,x0,h][x],{h,0,nit}]],{x,-4Pi,4Pi},PlotStyle->{Thick}]
},PlotRange->{{xmin,xmax},{ymin,ymax}}
]

Manipulate[grafico[f,0,n,{{-4Pi,4Pi},{-4,4}}],{n,0,100,1}]

Plot[Evaluate[{f[x],taylor[f,0,33][x]}],{x,-5Pi,5Pi}]

g[x_]:=Exp[x]

Manipulate[grafico[g,0,n,{{-4,4},{-4,4}}],{n,0,10,1}]

Manipulate[grafico[g,0,n,{{-.04,.04},{1-.04,1+.04}}],{n,0,10,1}]

f2[x_]:=Sin[x]+Cos[2x]-Sin[3x]

Manipulate[grafico[f2,0,n,{{-4Pi,4Pi},{-4,4}}],{n,0,100,1}]

taylor[f2,0,10][x]

N[taylor[f2,0,10][x]]

Plot[Evaluate[{f2[x],taylor[f2,0,33][x]}],{x,-5Pi,5Pi}]

Plot[Evaluate[{f2[x],taylor[f2,0,88][x]}],{x,-5Pi,5Pi}]