diff options
Diffstat (limited to '260/DEPENDENCIES/lagrange.sci')
-rw-r--r-- | 260/DEPENDENCIES/lagrange.sci | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/260/DEPENDENCIES/lagrange.sci b/260/DEPENDENCIES/lagrange.sci new file mode 100644 index 000000000..59d81f779 --- /dev/null +++ b/260/DEPENDENCIES/lagrange.sci @@ -0,0 +1,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
\ No newline at end of file |