Upload
alessandro-spadoni
View
216
Download
0
Embed Size (px)
Citation preview
8/13/2019 MATLAB2_lezione7
1/9
APPROSSIMAZIONE DI UNA FUNZIONE CONPOLINOMI DI TAYLOR
Consideriamo la funzione f:(a,b)R, derivabile n+1volte
inx0
(a,b); usiamo la formula di Taylor:
f(x)=Tn (x)+Rn+1(x) ,
Tn (x)= k=0nf(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).
7. SERIE DI TAYLOR E DI FOURIER
8/13/2019 MATLAB2_lezione7
2/9
Esempio: confrontare sin(x) con il polinomio di Taylor
grado 1, 3, 5 rispetto al puntox0=0, essendo
sin(x)=k=0(-1)kx2k+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)
Lerrorecommesso ||f-Tn||,(a,b)=max x (a,b) |f(x)-Tn(x)|.
8/13/2019 MATLAB2_lezione7
3/9
Esempio: comportamento dellerroreper n=0,,10. Siosserva 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,-*)
8/13/2019 MATLAB2_lezione7
4/9
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. Theexpansion point is 0.
taylor(f,n,v,a) computes the Taylor series expansion of f
with respect to v around the expansion point a.
8/13/2019 MATLAB2_lezione7
5/9
8/13/2019 MATLAB2_lezione7
6/9
APPROSSIMAZIONE DI UNA FUNZIONE IN SERIE DIFOURIER
Un polinomio trigonometrico di ordine n una funzionedella forma
Pn (x)= k=0n (akcos(kx)+bksin(kx)) ,conak, bkcomplessi. Introduciamo la serie di Fourier:
f(x)~ a0/2+k=1
(akcos(kx)+bksin(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 akcos(kx)+ k=1n bksin(kx) ,
che minimizza lo scarto quadratico medio:
- |f(x)-Fn(x)|2dx .
8/13/2019 MATLAB2_lezione7
7/9
8/13/2019 MATLAB2_lezione7
8/9
>> help stepfun
STEPFUN Unit step function.
STEPFUN(T,T0), where T is a monotonically increasingvector, returns a vector the same length as T with zeros
where T < T0 and ones where T >= T0.
8/13/2019 MATLAB2_lezione7
9/9
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:2s2=s2+4/(pi*(2*n+1))*sin((2*n+1)*x);
end
>> s6=0;
>> for n=1:6s6=s6+4/(pi*(2*n+1))*sin((2*n+1)*x);
end
>> plot(x,f,x,s2,x,s6)