## Documentation Center |

Find zeros of function in given interval

`z = fnzeros(f,[a b])z = fnzeros(f)`

`z = fnzeros(f,[a b])` is an ordered list
of the zeros of the univariate spline `f` in the
interval [`a` .. `b`] .

`z = fnzeros(f)` is a list of the zeros in
the basic interval of the spline `f`.

A spline zero is either a maximal closed interval over which the spline is zero, or a zero crossing (a point across which the spline changes sign).

The list of zeros, `z`, is a matrix with two
rows. The first row is the left endpoint of the intervals and the
second row is the right endpoint. Each column `z(:,j)` contains
the left and right endpoint of a single interval.

These intervals are of three kinds:

If the endpoints are different, then the function is zero on the entire interval. In this case the maximal interval is given, regardless of knots that may be in the interior of the interval.

If the endpoints are the same and coincident with a knot, then the function in

`f`has a zero at that point. The spline could cross zero, touch zero or be discontinuous at this point.If the endpoints are the same and not coincident with a knot, then the spline has a zero crossing at this point.

If the spline, `f`, touches zero at a point
that is not a knot, but does not *cross* zero,
then this zero may not be found. If it is found, then it may be found
twice.

**Example 1.** The following code
constructs and plots a piecewise linear spline that has each of the
three kinds of zeros: touch zero, cross zero, and zero for an interval. `fnzeros`computes
all the zeros, and then the code plots the results on the graph.

sp = spmak(augknt(1:7,2),[1,0,1,-1,0,0,1]); fnplt(sp) z = fnzeros(sp) nz = size(z,2); hold on plot(z(1,:),zeros(1,nz),'>',z(2,:),zeros(1,nz),'<'), hold off

This gives the following list of zeros:

z = 2.0000 3.5000 5.0000 2.0000 3.5000 6.0000

In this simple example, even for the second kind of zero, the two endpoints agree to all places.

**Example 2.** The following code
generates and plots a spline function with many extrema and locates
all extrema by computing the zeros of the spline function's first
derivative there.

f = spmak( 1:21, rand( 1, 15 )-0.5 ); interval = fnbrk( f, 'interval' ); z = fnzeros( fnder( f ) ); z = z(1,:); values = fnval( f, [interval, z] ); min( values ) fnplt(f) hold on plot(z,fnval(f,z),'ro') hold off

Your plot will be different to the example following because
of the use of `rand` to generate random coefficients.

**Example 3.** We construct a spline
with a zero at a jump discontinuity and in B-form and find all the
spline's zeros in an interval that goes beyond its basic interval.

sp = spmak([0 0 1 1 2],[1 0 -.2]); fnplt(sp) z = fnzeros(sp,[.5, 2.7]) zy = zeros(1,size(z,2)); hold on, plot(z(1,:),zy,'>',z(2,:),zy,'<'), hold off

This gives the following list of zeros:

z = 1.0000 2.0000 1.0000 2.7000

Notice the resulting zero interval [2..2.7], due to the fact that, by definition, a spline in B-form is identically zero outside its basic interval, [0..2].

**Example 4.** The following example
shows the use of `fnzeros` with a discontinuous function.
The following code creates and plots a discontinuous piecewise linear
function, and finds the zeros.

sp = spmak([0 0 1 1 2 2],[-1 1 -1 1]); fnplt(sp); fnzeros(sp)

This gives the following list of zeros, in (1..2) and (0..1) and the jump through zero at 1:

ans = 0.5000 1.0000 1.5000 0.5000 1.0000 1.5000

Was this topic helpful?