Finding the first roots of a function with Mathematica

Click For Summary

Discussion Overview

The discussion revolves around finding multiple roots of a single-variable function using Mathematica, particularly focusing on methods to extract the first several roots efficiently. Participants explore various functions and techniques within Mathematica, including FindRoot and NSolve, while addressing challenges related to trigonometric functions that yield infinite solutions.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant expresses a desire to find multiple roots of a function and questions how to do so using Mathematica.
  • Another suggests using NSolve, but a subsequent reply indicates that it does not work due to the nature of the equations involved.
  • A participant proposes restricting the search range of FindRoot and tabulating results to find multiple roots.
  • Concerns are raised about how to implement a "stop" condition in FindRoot to limit the number of roots found.
  • One participant suggests writing a program that cycles through FindRoot with increasing starting points to avoid duplicate roots.
  • Another participant mentions the need to round results to avoid false duplicates when comparing roots.
  • A later reply introduces the function FindInstance as a potential solution for finding multiple roots efficiently, noting its ability to report roots in order.
  • One participant expresses satisfaction with the suggestion of FindInstance, indicating it meets their needs.

Areas of Agreement / Disagreement

Participants do not reach a consensus on a single method for finding multiple roots, with various approaches proposed and debated throughout the discussion.

Contextual Notes

Participants highlight limitations related to the nature of the functions being analyzed, particularly those involving trigonometric equations, which can yield infinite solutions. There are also unresolved issues regarding the handling of duplicate roots and the implementation of stopping conditions in the code.

Prometteus
Messages
8
Reaction score
0
Hello everyone,

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 way I can tell mathematica to find, for exemple, the first 5 or 10 roots?

As I said I am quite knew to Mathematica so this question might sound silly but any help would be much appreciated.
 
Physics news on Phys.org
Perhaps NSolve is more like what you want.
 
NSolve doesn't solve it, appears the follow message: " The equations appear to involve the variables to be solved for in an essentially non-algebraic way. "
I have to really use FindRoot, but how the equation involves trigonometry has inifinite solutions. I Just want the first 10.
Thanks
 
You can restrict the search range of FindRoot and tabulate a series of them moving the search region along the number line then stop when you find the 10th.
 
FunkyDwarf said:
You can restrict the search range of FindRoot and tabulate a series of them moving the search region along the number line then stop when you find the 10th.

But how to introduce such "stop" in FindRoot function? I have seen the entire documention and it not say anything about it.
Thanks
 
I don't think its actually possible with only using FindRoot. What you have to do is write a little program that cycles through running FindRoot with increasing start points, and have it check to see if the new ones are the same as the old. Such as :

Code:
F[t_] = Sin[t];
t0 = 0.0;
\[Delta]t = \[Pi]/5.;
count = 0;
roots[count] = 
 FindRoot[F[t], {t, t0}][[1]][[2]]; t0 += \[Delta]t; count++;
While[count < 10, roots[count] = FindRoot[F[t], {t, t0}][[1]][[2]]; 
 t0 += \[Delta]t; If[roots[count] != roots[count - 1], count++]]
Table[roots[i]/\[Pi], {i, 0, 9}]

That code doesn't work really well, and if the function changes its very very wrong, but I hope you get the idea. You get a lot of repeats of roots, but I think if you do something with the accuracy of the values you can get that 1. == 1. instead of arbitrary precision saying its not.
 
Just have a while loop for the stop command, ie when a root is returned succesfully increase the counter, counter hits 10, end.
 
But that doesn't work, like in some code i tried it would find say, the root of Sin[t] at 0, but also one at 1.56*10^-17 (basically zero). So its a false root/duplicate. there's probably a way to round everything to 3 decimal places before the comparison to throw out duplicates.

I wish there was just a way to do it with one command.
 
Ah I think I figured it out. there's a function "FindInstance"
Use it like:

FindInstance[{Sin[t] Cos[t] == 0, t > 0, t < 100}, t, 10^7]

So it finds all 10^7 roots between 0 and 100. Since only a finite number exist, it just reports all of them, and does so in ORDER.
If you only have it say, find 3 of them, when more than 3 exist, it may choose ANY THREE rather than the first three. So have it choose wayyy more than you want it to and just take the first 10.

RTemp = FindInstance[{Sin[t] Cos[t] == 0, t >= 0, t < 1000}, t, 10^7];
roots = Table[RTemp[][[1]][[2]], {i, 1, 10}]
 
  • #10
Thank you all, Hepth that exactly what i wanted. I´ll try with FindIstance.
Thanks a lot:biggrin:
 

Similar threads

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