Download - Lenguaje Matlab Metodo Lagrange

Transcript

fprintf('INTERPOLACION "POLINIMIO DE LAGRAGE"\n\n\n');xi=input('Ingrese los puntos pertenecientes a las x: ');yi=input('Ingrese los puntos pertenecientes a las y: ');n=length(xi);x=sym('x');for j=1:nproducto=1;for i=1:j-1producto=producto*(x-xi(i));endproducto2=1;for i=j+1:nproducto2=producto2*(x-xi(i));endproducto3=1;for i=1:j-1producto3=producto3*(xi(j)-xi(i));endproducto4=1;for i=j+1:nproducto4=producto4*(xi(j)-xi(i));endL(j)=(producto*producto2)/(producto3*producto4);fprintf('\n L%d:\n',j-1)disp(L(j))endpn=0;for j=1:npn=pn+L(j)*yi(j);endfprintf('\n POLINOMIO INTERPOLANTE: \n')pn = simple(pn);disp(pn)opc=input('\nDesea aproximar un valor (si/no): ','s');if opc=='si'x=input('\nIngrese el punto a aproximar: ');y=eval(pn);disp('\nLa aproximacion a f(x) es:')disp(y)end