blob: 59d81f779f6169b1d2c7547f0c729f9c23ddf717 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
function p = lagrange(X,y,n)
x = poly(0,'x')
// n is the order of the polynomial
//x is the matrix of independent variable values
//y is the matrix of values of f(x)
p = 0;
for i = 1:n+1
L(i) = 1
for j = 1:n+1
if j == i then
continue ;
else
L(i) = L(i)*( x - X(j) )/( X(i) - X(j) ) ;
end
end
p = p + y(i)*L(i)
end
endfunction
|