Lenguaje Matlab Metodo Lagrange

1
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:n producto=1; for i=1:j-1 producto=producto*(x-xi(i)); end producto2=1; for i=j+1:n producto2=producto2*(x-xi(i)); end producto3=1; for i=1:j-1 producto3=producto3*(xi(j)-xi(i)); end producto4=1; for i=j+1:n producto4=producto4*(xi(j)-xi(i)); end L(j)=(producto*producto2)/(producto3*producto4); fprintf('\n L%d:\n',j-1) disp(L(j)) end pn=0; for j=1:n pn=pn+L(j)*yi(j); end fprintf('\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

description

Lenguaje Matlab Metodo Lagrange

Transcript of Lenguaje Matlab Metodo Lagrange

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