Spline Toolbox | ![]() ![]() |
Find zeros of a function in a given interval
Syntax
Description
z = fnzeros(f)
provides the 2-rowed matrix z
that is an ordered list of the zeros of the univariate spline in f
in its basic interval.
z = fnzeros(f,[a b])
looks for zeros only in the interval [a
.. b
] specified by the input.
Each column z(:,j)
contains the left and right endpoint of an interval. These intervals are of three kinds:
f
is relatively small at that point.
Examples
Example 1. We construct and plot a piecewise linear spline that has each of the three kinds of zeros, use fnzeros
to compute all its zeros, and then mark the results on that 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:
In this simple example, even for the second kind of zero, the two endpoints agree to all places.
Example 2. We generate a spline function with many extrema and locate all that are in a certain interval by computing the zeros of the spline function's first derivative there.
rand('seed',23) sp = spmak(1:21,rand(1,16)-.5); fnplt(sp) z = mean(fnzeros(fnder(sp),[7,14])); zy = fnval(sp,z); hold on, plot(z,zy,'o'), hold off
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:
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.
Algorithm
fnzeros
first converts the function to B-form. It locates zero intervals by the corresponding sequence of consecutive zero B-spline coefficients. It locates the sign changes in the B-spline coefficients for the function, isolates them from each other by suitable knot insertion, and then uses the Modified Regula falsi to locate the corresponding sign changes in the function, if any.
See Also
![]() | fnval | getcurve | ![]() |