Finding the multiple zeros within a prescribed interval

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?

Respuestas (1)

Torsten
Torsten el 13 de Nov. de 2018
Editada: Torsten el 13 de Nov. de 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)

7 comentarios

So basically you're splitting the domain up into smaller domains and checking for roots in each one?
Yes, with the knowledge that there is exactly one root in the interval ((2*k-1)*pi/2:(2*k+1)*pi/2)
That's assuming quite a bit. Can you do it if you take that assumption away?
Torsten
Torsten el 13 de Nov. de 2018
Editada: Torsten el 13 de Nov. de 2018
No, the strategy to find all zeros of a function in a specified interval will always depend on the behaviour of the function itself. So no general guideline can be given.
Of course you can start at x0=0.01, evaluate the function at x=x0+deltax, x=x0+2*deltax and so on until you get a sign change. Then you can call "fzero" with the interval of the last two x-values as search interval, save the root you get and continue with this strategy until you reach the right endpoint of the search interval. But this will be quite time-consuming, and - depending on deltax - it is still not ensured that you really find all zeros.
I see where the error is. You can't tell where the solutions will be, so the use of fzero is limited. I'm beginning to understand now. Is there another way?
I know that the definition of tan is from -pi/2 tp pi/2 and is pi periodic, so I search on the intervals: [0,pi/2), (pi/2,3*pi/2), (3*pi/2, 5*pi/2) and so on?
Matt J
Matt J el 13 de Nov. de 2018
Editada: Matt J el 13 de Nov. de 2018
No, the strategy to find all zeros of a function in a specified interval will always depend on the behaviour of the function itself. So no general guideline can be given.
Imagine, for example, that you were instead trying to find all roots of contained in the interval [0,a]. No matter what you choose, there would always be infinite roots in the interval.
@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.

Iniciar sesión para comentar.

Productos

Preguntada:

el 13 de Nov. de 2018

Comentada:

el 14 de Nov. de 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by