Finding Roots of x*tan(x)-A=0 in MATLAB

  • Topic: MATLAB 
  • Thread starter Thread starter Curl
  • Start date Start date
  • Tags Tags
    Matlab Roots
Join the discussion
Registration is free. Start your own thread to ask a follow-up.
2 replies · 6K views
Curl
Messages
756
Reaction score
0
I want to find roots of a function using MATLAB. The function is x*tan(x)-A=0. "A" is an arbitrary constant.
If I use fzero or fsolve, it will find the root closest to the guess.

Is there any way of getting, say, the first 5 roots of this function? I don't know where the roots are at, so I can't do a loop with multiple guesses since I have no idea what to guess.

There's got to be a way, can anyone help?
 
Physics news on Phys.org
Curl said:
Is there any way of getting, say, the first 5 roots of this function?

What do you mean by this? If you're talking about the 5 closest roots to x = 0, this sometimes does not exist. Take for example, f(x) = sin(1/x)

Also note that some functions have an infinite number of roots. e.g. f(x) = sin(x), f(x) = cos(x) ...

Curl said:
I don't know where the roots are at, so I can't do a loop with multiple guesses since I have no idea what to guess.

Unfortunately, that's the crux of root-finding problems. You need to find the roots and unless you know more information depending on the type of problem you're given, the best you can do is give an initial guess. Then you leave it to the numerical method to find the root. My best advice for you is to do multiple initial guesses insides of a big range ( [-1000000,1000000]) and call froot for each value you choose.

edit: fixed sin(1/x)
 
Last edited:
since xtan(x) is symmetric, yes I meant first zeroes from x=0. I just wanted to know if someone wrote an algorithm that makes guesses on its own.

You can go through the function in small intervals and check when the function changes sign. If it does, make a mark. Then go back and use fzero on each of those... I guess I could write one but I don't want to do it if it already exists.