# Finding all the roots of a function with Mathematica

• Mathematica
• LucianImago
His code is as follows:f = Log[Erf[x/7]] - Cos[x^2 - 1] + 1;rts = Reduce[f == 0 && 1 < x < 6, x]myvals = N[x /. {ToRules[rts]}]f = Log[Erf[x/7]] - Cos[x^2 - 1] + 1;rts = Reduce[f == 0 && 1 < x < 6, x];myvals = N[x /. {ToRules[rts]}]f = Log[Erff

#### LucianImago

Hi guys and girls of physics forums,

I have just created my account here and so this is my first post and I would like to appologise if my question may have been posted by someone else.

I am new to mathematica but I am very found of the program. So much so that I am trying to use it for one of my research projects as an alternative for mathcad which I've been using for many years and with many frustrations.

I have managed to work my way through functions and what not (I am still learning) but at the moment I've reached a delicate problem. I have this single variable function which has many roots and I would like to know how can I find them all.

I can use FindRoot and get one root at the time given I chose the proper starting value. But is there a vay I can tell mathematica to find the rest of the roots automatically? I am attaching a plot of the function which shows all the positions of the roots for a given set of parameters.

As I said I am quite knew to Mathematica so this question might sound silly but any help would be much appreciated.

Cheers

#### Attachments

• Energy levels r=4.png
20 KB · Views: 749
Use Reduce:

Code:
f = Log[Erf[x/7]] - Cos[x^2 - 1] + 1;
rts = Reduce[f == 0 && 1 < x < 6, x]
myvals = N[x /. {ToRules[rts]}]

I just used an example in Mathematica with a bunch of transcendental roots and then called Reduce to find all the zeros between 1 and 6. Reduce returns a list of logical expressions x= x1 || x=x2 || or x=x3 || and so forth.

The ToRules converts the list of logical expressions to a list of rules x->x1, x->x2, x->x3, and so forth. The N[x/.{ToRules[rts]}] then converts this to a list of numeric values.

Maybe an easier way.

Thank you very much for your reply. This is exactly what I want to do.

My programming experience is in the likes of Matlab and fortran. I am not used to this sort of structure but I a learning by doing.

Again thanks again.

Hello everybody,
I am a new user of Mathematica. I have a problem of finding the real roots of a complex function. My equation is a dispersion relation which gives the complex wave growth for the corresponding wave number . I need help to solve this equation in Mathematica 6

\[Rho] = 0.01;
we = 1000;
oh = 0.1;
k =.;
n =.;
m = (Sqrt[k^2 + n^2]);
F[ome_] = (ome + I (we)^0.5 k + 4 m^2 oh)*(ome + I (we)^0.5 k) Tanh[
m] + 4 m^3 oh^2 *(m Tanh[
m] - (m^2 + (ome + I (we)^0.5 k)/oh)^0.5 *
Tanh[(m^2 + (ome + I (we)^0.5 k)/oh)^0.5]) + \[Rho] ome^2 +
m^3;

n = 1;

m = (Sqrt[k^2 + n^2]);
t = Table[{k,
Re[ome /.
FindRoot[F[ome] == 0, {ome, {(1.5 + I)}},
MaxIterations -> 500]]}, {k, 1, 100, 1}]

ListPlot[t, PlotJoined -> True]

I have pasted the corresponding lines from my Mathematica note book i used to solve the equation. I want to make plot for the real part of ome in the y-axis versus wave number K on the x axis.
I am really in need of help as I have been trying to solve it on for weeks by now.
Any body can help me . also contact me at kumar.kannan@uni.lu.

I am having problem in giving the initial guess root.

bye
with regards
K.Suresh kumar