Integration of a function defined by a data series
[y,ydot] = CL_integrate(x,ydotn [,yini, meth, n])
Integrates a function of one variable defined by a data series.
The nth integral is evaluated by using derivatives (ydotn) and initial conditions (yini).
- For a simple integration (n=1), ydotn is the first derivative of y at abscissae x, and yini gives the value of y at first abscissa. The function returns the values of y at abscissae x.
- For a double integration (n=2), ydotn is the second derivative of y at abscissae x, and yini gives the value of y and ydot at first abscissa. The function returns the values of y and its first derivative ydot at abscissae x.
The methods used to integrate are:
- step_l (l as lower bound): The result is the integral of a step function (constant between x(k) and x(k+1)). The constant value between x(k) and x(k+1) is ydotn(k).
- step_m (m as middle): The result is the integral of step function (constant between x(k) and x(k+1)). The constant value between x(k) and x(k+1) is (ydotn(k)+ydotn(k+1)/2.
- lin (linear): The result is the integral of a linear function on each interval (polynomial (P) of degree 1). P(xk)=ydotn(k) and P(xk+1)=ydotn(k+1).
- sl4 : Simpson (1 intermediate point) + Lagrange interpolation using 4 points. %nan is returned if there are not enough input data.
- sspl : Simpson (1 intermediate point) + interpolation using splines.
- bl6 : Boole (3 intermediate points) + Lagrange interpolation using 6 points. %nan is returned if there are not enough input data.
Abscissae (in strictly increasing order) (1xN or PxN)
Values of nth derivative at abscissae x (1xN or PxN)
(optional) Initial conditions for y (y0 or [y0, ydot0]). Default is 0. (1xn or Pxn)
(string, optional) Integration method: "step_l", "step_m", "lin", "sl4", "sspl", "bl6". Default is "lin". (1x1)
(integer, optional) Integration order (= number of successive integrations): 1 or 2. Default is 1. (1x1)
Integrated values (after n successive integrations) at abscissae x (PxN)
First derivatives of y at abscissae x ([] if n == 1) (PxM)
CNES - DCT/SB
// Example 1: Simple integration x = linspace(0,2*%pi,100); ydot = cos(x); yini = 0; y1 = CL_integrate(x, ydot, yini, meth="lin"); disp(max(abs(y1-sin(x)))); y2 = CL_integrate(x, ydot, yini, meth="sl4"); disp(max(abs(y2-sin(x)))); y3 = CL_integrate(x, ydot, yini, meth="sspl"); disp(max(abs(y3-sin(x)))); y4 = CL_integrate(x, ydot, yini, meth="bl6"); disp(max(abs(y4-sin(x)))); // Example 2: Double integration (step method) x = linspace(0,2*%pi,100); ydot2 = cos(x); yini = [1, 2]; [y, ydot] = CL_integrate(x, ydot2, yini, meth="step_m", n=2); ydotref = sin(x) + 2; disp(max(abs(ydot-ydotref))); yref = -cos(x) + 2*x + 2; disp(max(abs(y-yref))); |