Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Esercizio24(f,a,b,N)
- %cambio intervallo
- tk = linspace(a,b,N+1)';
- tk(end) = [];
- yk = f(tk);
- grado = N-1;
- k = 0:grado;
- xk = 2*pi/(b-a)*(tk-a);
- A = exp(i*xk*k);
- %risoluzione del sistema e calcolo dei coefficienti
- c1 = A\yk;
- c2 = (A/N)*yk;
- c3 = fft(yk)/N;
- c = [c1 c2 c3];
- %coordinate della funzione data
- t = linspace(a,b,200);
- y = f(t);
- x = 2*pi/(b-a)*(t-a);
- for j = 1:length(c)
- subplot(3,1,j);
- Q = polyval(flipud(c(:,j)),exp(i*x));
- h = plot(t,y,t,real(Q),'g',tk,yk,'or');
- set(h,'LineWidth',2,'MarkerFaceColor','r');
- title(['Funzione : ' char(f) ' Punti :' int2str(N)]);
- legend('grafico funzione data','polinomio trigonometrico interpolante',...
- 'dati interpolazione');
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement