Previous Up Next

6.27.29  Lagrange polynomial: lagrange interp

The lagrange command finds the Lagrange polynomial which interpolates given data.
interp is a synonym for lagrange.


Examples.


Warning.
An attempted function definition such as f:=lagrange([1,2],[3,4],y) does not return a function but an expression with respect to y. To define f as a function, input:

f:=unapply(lagrange([1,2],[3,4],x),x)

Avoid f(x):=lagrange([1,2],[3,4],x) since then the Lagrange polynomial would be computed each time f is called (indeed in a function definition, the second member of the assignment is not evaluated). Note also that g(x):=lagrange([1,2],[3,4]) would not work since the default argument of lagrange would be global, hence not the same as the local variable used for the definition of g.


Previous Up Next