1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| clear, close all
clc
% a=[0;1];
% b=[1;-1];
% c=[2;2];
% d=[3;-2];
% points = [a b c d];
xDebut=-1;
xFin=1;
N=100;
k=linspace(xDebut,xFin,N);
abscisse=cos(((2.*k)-1)*(pi/2*N));
ordonnee=(1./(1+25.*(abscisse).^2));
points=[abscisse ; ordonnee]
xi=[];
xj=[];
for i=1:length(points)
xi=[xi points(1, i)];
end
for j=1:length(points)
temp=[];
for i=1:length(xi)
if i~=j
temp=[temp ; points(1, i)];
end
end
xj=[xj temp];
end
polynomes=[];
for i=1:length(xi)
Coef=1;
racines=[];
for j=1:size(xj, 1)
racines = [racines xj(j, i)];
K=xi(1,i)-xj(j,i);
Coef=Coef*K;
end
polynomes = [polynomes ; poly(racines).*(1/Coef)];
end
lagrange=[];
for i=1:length(xi)
lagrange=[lagrange ; points(2, i).*polynomes(i, :)];
end
interpolation = sum(lagrange);
x=linspace(xDebut,xFin);
p=polyval(interpolation,x);
figure
hold all
plot(x, p)
plot(abscisse, ordonnee)
scatter(points(1,:),points(2,:)) |
Partager