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

In summary, the conversation discusses the use of MATLAB to find the roots of a function, specifically x*tan(x)-A=0 where "A" is an arbitrary constant. The use of fzero or fsolve is suggested to find the root closest to a given guess. However, the possibility of finding the first 5 roots of the function is also mentioned, but it is noted that this may not always be possible or may require multiple initial guesses. The conversation ends with the suggestion of using froot and creating an algorithm to find the roots in small intervals.
  • #1
Curl
758
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
  • #2
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:
  • #3
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.
 

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

What is the function of the "fzero" command in MATLAB?

The "fzero" command in MATLAB is used to find the roots of a given function. It takes two arguments - the function to be evaluated and an initial guess for the root. It then uses an iterative algorithm to find the root of the function.

Can the "fzero" command be used to find roots of trigonometric functions?

Yes, the "fzero" command can be used to find roots of any continuous function, including trigonometric functions. In the case of finding roots of x*tan(x)-A=0, the function needs to be expressed as a MATLAB function and then passed as an argument to the "fzero" command.

What is the significance of the initial guess in finding roots using the "fzero" command?

The initial guess is important as it determines the starting point for the iterative algorithm used by the "fzero" command. A good initial guess can help the algorithm converge faster and find the root accurately. However, if the initial guess is too far from the actual root, the algorithm may fail to converge or find a wrong root.

How can I plot the roots of x*tan(x)-A=0 in MATLAB?

To plot the roots of a function, you can use the "fplot" command in MATLAB. You can first define the function as a MATLAB function and then use the "fplot" command to plot the function over a range of values. The roots will be visible as the points where the function crosses the x-axis.

Can the "fzero" command find multiple roots of a function?

Yes, the "fzero" command can find multiple roots of a function. However, it can only find one root at a time, so you will need to use the command multiple times with different initial guesses to find all the roots of the function.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
12
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • Thermodynamics
Replies
3
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
2K
  • Calculus and Beyond Homework Help
Replies
13
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
Back
Top