Graphics Programs Reference
In-Depth Information
EXAMPLE 4.3
Find all the zeroes of f ( x )
=
x
tan x in the interval(0
,
20) by themethod of bisection.
Utilize the functions rootsearch and bisect .
Solution Note thattan x issingular and changes sign at x
= π/
2
,
3
π/
2
,...
. To prevent
=
bisect frommistaking these pointforroots,we set filter
1 . The closeness of roots
to the singularities is anotherpotential problem thatcan be alleviatedbyusing small
x in rootsearch.Choosing
x
=
0
.
01, we arrive at the following program:
% Example 4.3 (root finding with bisection)
a=0.0;b=20.0;dx=0.01;
nroots = 0;
while 1
[x1,x2] = rootsearch(@fex4
_
3,a,b,dx);
if isnan(x1)
break
else
a=x2;
x = bisect(@fex4
_
3,x1,x2,1);
if ˜isnan(x)
nroots = nroots + 1;
root(nroots) = x;
end
end
end
root
Recall that in MATLAB the symbol @ before a function namecreates a handle for
the function. Thus the input argument @fex4 3 in rootsearch is a handle for the
function fex4 3 listedbelow.
functiony=fex4
3(x)
% Function used in Example4.3
y=x-tan(x);
_
Running the program resultedinthe output
>> root =
0
4.4934
7.7253
10.9041
14.0662
17.2208
Search WWH ::




Custom Search