Group Abstract Group Abstract

Message Boards Message Boards

Find all roots to an equation?

Posted 8 years ago

Hello. I'm spending my friday night trying to learn Mathematica, and so far it's been going decent. This is only my second day using the program, so bare with me.

I'm currently on an exercise where I'm supposed to plot these two functions in the same graph: enter image description here

For that I used

Plot[{Abs[3 - t^2] + Abs[t - 1] - t^2, 3*Sin[t]}, {t, -3.8, 4.6}]

Which gave me this : enter image description here

Now, what I'm wondering is, how do I find all of the roots to my equation ( h(t) = g(t) )? My e-book suggests using FindRoot, but I don't know how/where. Thanks for your help.

POSTED BY: Jhn Doe
8 Replies

There's an undocumented function System`TRootsDump`GuessRealRoots that finds pretty good initial points for FindRoot to polish up:

Reduce`AnalyticRootIsolation; (* initialization *)
With[{f = Function[t, -t^2 + Abs[-1 + t] + Abs[3 - t^2] - 3 Sin[t]]},
 FindRoot[f, {#}] & /@ System`TRootsDump`GuessRealRoots[f, {-4, 4}]
 ]
(*  {{0.762901}, {3.35745}, {-3.77452}}  *)

Here's another way to get the starting points:

rootapprox = Plot[(Abs[3 - t^2] + Abs[t - 1] - t^2) - (3*Sin[t]), {t, -3.8, 4.6},
   MeshFunctions -> {#2 &}, Mesh -> {{0}}, MeshStyle -> {Red}, PlotStyle -> None];
Cases[Normal@rootapprox, Point[{x_, _}] :> x, Infinity]
(*  {0.761897, 3.35785, -3.77457}  *)
POSTED BY: Michael Rogers

In my problem, SystemTRootsDumpGuessRealRoots works 10 to 300 times slower than Ted Ersek's RootSearch.

POSTED BY: Igor Kotelnikov

There's an undocumented function System`TRootsDump`GuessRealRoots that finds pretty good initial points for FindRoot to polish up:

Reduce`AnalyticRootIsolation; (* initialization *)
With[{f = Function[t, -t^2 + Abs[-1 + t] + Abs[3 - t^2] - 3 Sin[t]]},
 FindRoot[f, {#}] & /@ System`TRootsDump`GuessRealRoots[f, {-4, 4}]
 ]
(*  {{0.762901}, {3.35745}, {-3.77452}}  *)
POSTED BY: Michael Rogers
POSTED BY: Neil Singer
Posted 8 years ago
POSTED BY: Jim Baldwin
POSTED BY: Mariusz Iwaniuk
POSTED BY: Mariusz Iwaniuk
Posted 8 years ago

Ah okay. The first one is definitely the one I'll be using then. You used -3,1,3 for the interval, why was that?

POSTED BY: Jhn Doe
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard