Intervals of positive or negative values
[xres, yres] = CL_detectSign(x, y, sgn [, ytol, xbounds, opts])
Computes the abscissa intervals where ordinate values are positive or negative.
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:
- sgn: "+" => intervals where y is positive, "-" => intervals where y is negative.
- 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.
Abscissae. (1xN)
(1xN or list) Corresponding ordinates or list(function, ...). See above for details.
(string) Wanted sign for y: "+" or "-".
(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
Intervals of abscissae where y has the requested sign. (2xP)
Corresponding ordinates. (2xP)
CNES - DCT/SB
x = 0 : 10; a = 0.99; // Example 1: Data interpolation y = sin(x) - a; xres = CL_detectSign(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_detectSign(x, list(myfunction, a), "+"); myfunction(xres, a) // => ~0 (more accurate) |