How to make Lagrange interpolating polynomial return vectors

6 vues (au cours des 30 derniers jours)
benjamin schroll
benjamin schroll le 26 Nov 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

Réponses (0)

Catégories

En savoir plus sur Interpolation dans Help Center et File Exchange

Produits


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by