lagrange

Upload: dani-

Post on 01-Mar-2016

220 views

Category:

Documents


0 download

DESCRIPTION

lagrange matlab

TRANSCRIPT

  • clcN=9a=-2;b=2;f=inline('exp(-x.^2).*sin(x.^2+sqrt(x.^2+1))')

    xn=linspace(a,b,N);yn=f(xn); % [xk',xn',yn']xl=linspace(a,b,500);yl=lagrange(xn,yn,xl);% generando los nodos basados en los ceros de Tchebuchevk=1:1:N;xk=cos((2*k-1)*pi/(2*N));xk=sort(xk);% [xk',xn',yn']xnt=(b-a)*(xk-1)/2+b;[xk',xn',yn',xnt']ynt=f(xnt);yntl=lagrange(xnt,ynt,xl);

    plot(xn,yn,'ob')hold onfplot(f,[a,b],'b')plot(xl,yl,':r')

    plot(xnt,ynt,'*k')

    plot(xl,yntl,'--g')

    hold offlegend('coordenadas','f(x)','lagrange con nodos equidistantes',... 'coordendas de nodos-ceros de tchebychev',... 'interpolacion con los ceros de tchebychev')