How to make Lagrange interpolating polynomial return vectors

6 visualizaciones (últimos 30 días)
benjamin schroll
benjamin schroll el 26 de Nov. de 2019
I wrote a code that will interpolate data with lagrange but I am trying to get it to return the anser as vectors and not just a number as the vector will be more usefull for what Im trying to do. This is the code I've been using. What would be the simplest way to alter it to return a vector or stor the values calculated durring the loops?
function Lagrange(x,y,n,xx)
% Lagrange interpolation polynomial fitting a set of points
% LAGRANG(X,Y,N,XX) where X and Y are row vectors
% defining a set of N points uses Lagrange's method to find
% the N-1th order polynomial in X that passes through these
% points.
clc
format shortG
sum=0;
for i = 1:n
product=y(i);
for j=1:n
if (i~=j)
product= product*(xx-x(j))/(x(i)-x(j));
end
end
i;
sum = sum +product;
end
Lagrngr=sum
plot(x,y)
hold on
plot(x,y)
title('Lagrange Interpolation ')
xlabel('x - value')
ylabel('y - value')
axis([min(x)-1 max(x)+1 0 max(y)+50])
grid on
end

Respuestas (0)

Categorías

Más información sobre Interpolation en Help Center y File Exchange.

Productos


Versión

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by