ClubEnsayos.com - Ensayos de Calidad, Tareas y Monografias
Buscar

Lagrange En Matlab


Enviado por   •  23 de Junio de 2013  •  273 Palabras (2 Páginas)  •  579 Visitas

Página 1 de 2

clear all;

clc;

fprintf('Interpolacion con el Metodo del Polinomio de Lagrange\n\n');

n=input('grado del polinolio: ');

for i1:n+1

x(1,i)=input('dame los valores de xi:');

end

for i=1:n+1

xi(1,i)=input('dame los valores de f(xi):');

end

x

xi

xint=input('Numero para el que desea interpolar x: ');

fxint=0;

i=1;

while i<=n+1

L=1;

J=0;

while J<=n

if i~=J+1

L=L*(xint-x(1,J+1))/(x(1,i)-x(1,J+1));

end

J=J+1;

end

fxint=fxint+L*xi(1,i);

i=i+1;

end

fprintf('\nresultado xi: %d',fxint');

plotx,xi)

grid

title('Polinomio de Lagrange');xlabel('x');yhabel('y')

La interpolación de Lagrange es una mejora de la interpolación lineal.

Sirve para aproximar valores en curvas, en lugar de en rectas.

Un código sencillo para hacerlo es:

function y0 = lagrange_interp(x, y, x0)

% x is the vector of abscissas.

% y is the matching vector of ordinates.

% x0 represents the target to be interpolated

% y0 represents the solution from the Lagrange interpolation

y0 = 0;

n = length(x);

for j = 1 : n

t = 1;

for i = 1 : n

if i~=j

t = t * (x0-x(i))/(x(j)-x(i));

...

Descargar como (para miembros actualizados)  txt (1.3 Kb)  
Leer 1 página más »
Disponible sólo en Clubensayos.com