blob: b55a42ff6f57f17360ae755d339cda5fa8a9a7cd (
plain)
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
|
function P2=lagrangefundamentalpoly(x,f,n)
[nrx,ncx]=size(x)
[nrf,ncf]=size(f)
if ((nrx<>1)|(nrf<>1)) then
error('x or f, or both, not column vector(s)');
abort;
end;
if ((ncx<>ncf)) then
error('x and f are not of the same length');
abort;
end;
X=poly(0,"X");
L=zeros(n);
P2=0;
for i=1:n+1
L(i)=1;
for j=1:n+1
if i~=j then
L(i)=L(i)*(X-x(j))/(x(i)-x(j))
end;
end;
P2=P2+L(i)*f(i);
end;
endfunction
|