Lagrange interpolation
[y, ydot] = CL_interpLagrange(xref,yref,x [,n,opt,nder])
Interpolates using Lagrange method.
Given reference abscissae (xref) sorted in strictly increasing order and corresponding ordinates (yref), the function computes interpolated ordinates for the given abscissae (x).
The number of points to be used for the interpolation (n) should be an even whole number in the range [2,16].
The behavior of the function for the allowed range of values for x can be changed via the argument opt:
- opt = 0 : Default mode. The allowed range for x is [xref(1), xref($)]
- opt = 1 : Strict (= optimal) mode. The allowed range for x is [xref(n/2), xref($-n/2+1)]
The derivatives of the interpolating polynomials are computed if nder == 1 and if the output argument is present.
Notes:
- The degree of the polynomial is n-1.
- y = %nan for values of x that are outside the allowed range
Reference abscissae, sorted in strictly increasing order (1xN)
Corresponding ordinates (PxN)
Abscissae, where to interpolate (1xM)
Interpolated values (PxM)
(integer, optional) Number of points for the interpolation (1x1). Must be even, >= 2 et <= 16. Default is 8. (1x1)
(integer, optional) Option for accuracy control (0 or 1). Default is 0. (1x1)
(integer, optional) Option for the computation of the derivatives (1=yes, 0=no). Default is 1. (1x1)
Values of interpolating polynomials (PxN)
Values of interpolating polynomials derivatives. [] if not computed (PxN)
CNES - DCT/SB
// Example 1: Exact interpolation xref = 1:6; yref = [xref; xref.^2; xref.^3]; x = 0:0.5:4; [y] = CL_interpLagrange(xref, yref, x, n=4); y - [x; x.^2; x.^3] [y] = CL_interpLagrange(xref, yref, x, n=4, opt=1); y - [x; x.^2; x.^3] // Example 2: Interpolation of sin and cos xref = linspace(0,1,101); yref = [sin(2*%pi*xref); cos(2*%pi*xref)]; x = linspace(0,1,1001); [y] = CL_interpLagrange(xref, yref, x, opt=0); scf(); plot(x, y - [sin(2*%pi*x); cos(2*%pi*x)]); [y] = CL_interpLagrange(xref, yref, x, opt=1); scf(); plot(x, y - [sin(2*%pi*x); cos(2*%pi*x)]); |