Finding all the roots of a function with Mathematica

Click For Summary

Discussion Overview

The discussion revolves around finding all the roots of functions using Mathematica, particularly focusing on techniques for identifying multiple roots of single-variable functions and addressing challenges with complex functions. Participants share their experiences and methods related to root-finding in Mathematica.

Discussion Character

  • Exploratory
  • Technical explanation
  • Homework-related

Main Points Raised

  • One participant expresses a desire to find all roots of a single-variable function in Mathematica, mentioning their experience with FindRoot and seeking a method for automatic root finding.
  • Another participant suggests using the Reduce function to find all zeros of a given function within a specified range, providing an example with transcendental roots.
  • A third participant thanks the second for the suggestion, indicating their background in other programming languages and their ongoing learning process with Mathematica.
  • A different participant describes a complex function related to a dispersion relation and seeks assistance in finding real roots, sharing their Mathematica code and expressing difficulty with initial guesses for roots.

Areas of Agreement / Disagreement

Participants generally share methods and experiences without reaching a consensus on a single approach, as multiple techniques and challenges are presented. The discussion remains unresolved regarding the best practices for root finding in complex functions.

Contextual Notes

Some limitations include the dependence on initial guesses for root finding and the complexity of the functions being analyzed, which may affect the ability to find all roots effectively.

LucianImago
Messages
6
Reaction score
0
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
    Energy levels r=4.png
    15.2 KB · Views: 867
Physics news on Phys.org
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
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 9 ·
Replies
9
Views
7K
  • · Replies 0 ·
Replies
0
Views
2K