Zero crossing detection
[xres, yres] = CL_detectZero(x, y [[, direct, ytol, xbounds, opts]])
Computes zero crossings, that is (abscissa,ordinate) pairs such that ordinate = 0.
There are 2 possibilities for the arguments x and y:
1) x and y are 2 row vectors. Lagrange interpolation in then used to compute data at intermediate abscissae.
2) x is a row vector and y is a list that gives the function to be called. y must be defined as follows:
y = list(fct) => fct is a function with the interface: z = fct(x)
y = list(fct, args) => fct is a function with the interface: z = fct(x, args)
y = list(fct, ind, args) => fct is a function with the interface: z = fct(x, ind, args) [ind: unused]
The other arguments are:
- direct: Specifies the direction of y: "incr"=increasing, "decr"=decreasing, "any"=both.
- ytol: Desired accuracy on y.
- xbounds: Abscissae intervals where the abscissae are looked-for.
- opts: structure containing additional optional parameters.
The opts structure may contain the fields:
- nsub: (integer) Number of intermediate points (>= 0).
- meth: Method used to finely compute the zeros of y(x): "s": secant, "d": dichotomy, "ds": mix of secant and dichotomy (see CL_fsolveb).
- impr: True (%t) to activate the improved detection mechanism. Default value is %t.
- ninterp: Number of interpolation points. Default value is 8.
The method consists in selecting the abscissae for which the sign of y changes, and then computing a more exact value using CL_fsolveb. If the improved detection mechanism is active, the function first detects when y reaches an extremum, which improves the zero detection capability.
Notes:
- The abscissae x must be strictly increasing.
- The data must be continuous and smooth enough so that polynomial interpolation or zero detection works.
- The condition used for returning the solution in the case one of the "y" is exactly 0 and "direct" is not "any" may sometimes be too strict (see example 3 below).
Abscissae. (1xN)
(1xN or list) Corresponding ordinates or list(function, ...). See above for details.
(string, optional) "incr"=increasing, "decr"=decreasing, "any"=both. Default value is "any".
(optional) Accuracy on y (empty <=> default value). Default value <= max(abs(y)) / 1.e8.
(optional) Abscissae intervals where the results are looked-for. Default value is [-%inf; %inf]. (2xQ)
(structure, optional) Additional options - see above
Abscissae of solutions. (1xP)
Ordinates of solutions. (1xP)
CNES - DCT/SB
x = 0 : 10; a = 0.99; // Example 1: Data interpolation y = sin(x) - a; xres = CL_detectZero(x,y); sin(xres) - a // => ~0 (includes effect of interpolation errors) // Example 2: User-defined function function [y]=myfunction(x, c) y = sin(x) - c; endfunction xres = CL_detectZero(x, list(myfunction, a)); myfunction(xres,a) // => 0 (more accurate) // Example 3: using "incr" or "decr" x = 0 : 10; y = abs(x - 5); // No solution returned for "incr" or "decr" as function does not appear // monotonous around the value "5". xres = CL_detectZero(x, y, "incr") // => no solution xres = CL_detectZero(x, y, "decr") // => no solution xres = CL_detectZero(x, y, "any") // => one solution returned | ![]() | ![]() |