Sei sulla pagina 1di 9

7.

SERIE DI TAYLOR E DI FOURIER


APPROSSIMAZIONE DI UNA FUNZIONE CON POLINOMI DI TAYLOR Consideriamo la funzione f:(a,b) R, derivabile n+1 volte in x0 (a,b); usiamo la formula di Taylor:
f(x)=Tn (x)+Rn+1(x) , Tn (x)= k=0n f(k)(x0)/k! (x- x0)k Rn+1(x)= f(n+1)()/(n+1)! (x- x0)n+1, dove Rn+1(x) il resto di Lagrange con (x0,x).

Esempio: confrontare sin(x) con il polinomio di Taylor grado 1, 3, 5 rispetto al punto x0=0, essendo sin(x)= k=0 (-1)k x2k+1/(2k+1)! in [0,] .
>> x=0:0.01:pi; >> f=sin(x); >> T1=x; >> T3=T1-x.^3/6; >> T5=T3+x.^5/120; >> plot(x,f,b,x,T1,g,x,T3,r,x,T5,m) Lerrore commesso ||f-Tn||,(a,b)=max x (a,b) |f(x)-Tn(x)|.

Esempio: comportamento dellerrore per n=0,,10. Si osserva una rapida convergenza a zero dellerrore. >> x=0:0.01:pi; >> f=sin(x); >> Tn=zeros(size(x)); >> for n=0:10 Tn=Tn+(-1)^n*x.^(2*n+1)/(prod(1:2*n+1)); e(n+1)=norm(f-Tn,inf); stima(n+1)=(pi^(2*n+3))/(prod(1:2*n+3)); end >> loglog(0:10,e,-*)

Matlab: espansione in serie di Taylor taylor(f) computes the Taylor series expansion of f up to the fifth order. The expansion point is 0. taylor(f,n) computes the Taylor series expansion of f up to the (n-1)-order. The expansion point is 0. taylor(f,a) computes the Taylor series expansion of f up to the fifth order around the expansion point a. taylor(f,n,a) computes the Taylor series expansion of f up to the (n-1)-order around the expansion point a. taylor(f,n,v) computes the Taylor series expansion of f up to the (n-1)-order with respect to variable v. The expansion point is 0. taylor(f,n,v,a) computes the Taylor series expansion of f with respect to v around the expansion point a.

Input Arguments f: A symbolic expression n: A positive integer specifying the truncation order (Default: 6) v: A string or symbolic variable with respect to which you want to compute the Taylor series expansion a: A real number specifying the expansion point (Default: 0)

APPROSSIMAZIONE DI UNA FUNZIONE IN SERIE DI FOURIER Un polinomio trigonometrico di ordine n una funzione della forma Pn (x)= k=0n (ak cos(kx)+bk sin(kx)) , con ak, bk complessi. Introduciamo la serie di Fourier: f(x)~ a0 /2+k=1 (ak cos(kx)+bk sin(kx)), a0=1/(2) - f(x) dx ak=1/ - f(x) cos(k x) dx, k=1,2, bk=1/ - f(x) sin(k x) dx . La troncata n-esima : Fn(x)= k=0n ak cos(kx)+ k=1n bk sin(kx) , che minimizza lo scarto quadratico medio: - |f(x)-Fn(x)|2 dx .

Esempio: Onda quadra


f(x)=A per 0<x< , f(x)=-A per - <x<0 con A costante; ak=1/ - A sign(x) cos(k x) dx=0, bk=1/ - A sign(x) sin(k x) dx =0 bk=4A/(k) e quindi: f(x) ~ n=0 4A/((2n+1)) sin((2n+1)x). k=1,2, se k pari, se k dispari

>> help stepfun STEPFUN Unit step function. STEPFUN(T,T0), where T is a monotonically increasing vector, returns a vector the same length as T with zeros where T < T0 and ones where T >= T0.

Esempio: A=1 e si disegni il grafico per n=2 e n=6. >> x=-2*pi:0.01:2*pi; >> f1=stepfun(x,0)-stepfun(x,pi); >> f2=stepfun(x+2*pi,0)-stepfun(x+2*pi,pi); >> f=2*(f1+f2)-1; >> s2=0; >> for n=1:2 s2=s2+4/(pi*(2*n+1))*sin((2*n+1)*x); end >> s6=0; >> for n=1:6 s6=s6+4/(pi*(2*n+1))*sin((2*n+1)*x); end >> plot(x,f,x,s2,x,s6)

Potrebbero piacerti anche