# Finding the multiple zeros within a prescribed interval

7 views (last 30 days)
Matthew Hunt on 13 Nov 2018
Commented: Torsten on 14 Nov 2018
I wish to solve the nonlinar function: =0
within a prescribed interval, say (0,100] say, I'm aware of using an annonymous function and using fzero or fsolve, but how do I get say multiple solutions?

Torsten on 13 Nov 2018
Edited: Torsten on 13 Nov 2018
deltax = 1e-4;
xright = 100;
n = floor(xright/pi);
fun = @(x)tan(x)-x;
for i=1:n
left = (2*i-1)*pi/2.0 + deltax;
right = (2*i+1)*pi/2.0 - deltax;
sol(i) = fzero(fun,[left right]);
end
sol
fun(sol)
Torsten on 14 Nov 2018
@Matthew Hunt:
You know that tan(x) -x -> -Inf for x->2*(k-1)*pi/2 from the right and tan(x) - x -> +Inf for x->2*(k+1)*pi/2 from the left. So there must be a root in the interval 2*(k-1)*pi/2 : 2*(k+1)*pi/2. Plotting the function tan(x) - x you can see that there is exactly one root in this interval. This explains my code and the fact that it captures all roots in a specified interval.