<< CL_integrate Math CL_interpLin >>

CelestLab >> Math > CL_interpLagrange

CL_interpLagrange

Lagrange interpolation

Calling Sequence

[y, ydot] = CL_interpLagrange(xref,yref,x [,n,opt,nder])

Description

Parameters

xref:

Reference abscissae, sorted in strictly increasing order (1xN)

yref:

Corresponding ordinates (PxN)

x:

Abscissae, where to interpolate (1xM)

y:

Interpolated values (PxM)

n:

(integer, optional) Number of points for the interpolation (1x1). Must be even, >= 2 et <= 16. Default is 8. (1x1)

opt:

(integer, optional) Option for accuracy control (0 or 1). Default is 0. (1x1)

nder:

(integer, optional) Option for the computation of the derivatives (1=yes, 0=no). Default is 1. (1x1)

y:

Values of interpolating polynomials (PxN)

ydot:

Values of interpolating polynomials derivatives. [] if not computed (PxN)

Authors

See also

Examples

// 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)]);

Report an issue
<< CL_integrate Math CL_interpLin >>