# Find all roots to an equation?

Posted 5 months ago
1222 Views
|
7 Replies
|
6 Total Likes
|
 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: 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 : 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.
7 Replies
Sort By:
Posted 5 months ago
 FindRoot[Abs[3 - t^2] + Abs[t - 1] - t^2 == 3*Sin[t], {t, #}] & /@ {-3, 1, 3}(* Starting values from Plot[]*) (* {{t -> -3.77452}, {t -> 0.762901}, {t -> 3.35745}} *) Or: NSolve[{RealAbs[3 - t^2] + RealAbs[t - 1] - t^2 == 3*Sin[t], -4 < t < 4}, t, Reals](*Why Abs[] dosen't work I don't know !.*) (* {{t -> -3.77452}, {t -> 0.762901}, {t -> 3.35745}} *) NSolve[{Abs[3 - t^2] + Abs[t - 1] - t^2 == 3*Sin[t], -4 < t < 4}, t, Complexes] (* {{t -> -3.77452}, {t -> 0.762901}, {t -> 3.35745}} *) Solve[{Abs[3 - t^2] + Abs[t - 1] - t^2 == 3*Sin[t], -4 < t < 4}, t, Reals] (*{{t -> Root[{-4 - 3 Sin[#1] + #1 &, 3.3574487606850113852}]}, {t -> Root[{2 + 3 Sin[#1] + #1 &, -3.7745180124835511931}]}, {t -> Root[{-4 + 3 Sin[#1] + #1 + 2 #1^2 &, 0.76290087955924483126}]}}*) %//N (* {{t -> 3.35745}, {t -> -3.77452}, {t -> 0.762901}} *) Reduce[{Abs[3 - t^2] + Abs[t - 1] - t^2 == 3*Sin[t], -4 < t < 4}, t, Reals] (* t == Root[{-4 - 3 Sin[#1] + #1 &, 3.3574487606850113852}] || t == Root[{2 + 3 Sin[#1] + #1 &, -3.7745180124835511931}] || t == Root[{-4 + 3 Sin[#1] + #1 + 2 #1^2 &, 0.76290087955924483126}] *) %//N (* t == 3.35745 || t == -3.77452 || t == 0.762901*) FindInstance[{Abs[3 - t^2] + Abs[t - 1] - t^2 == 3*Sin[t], -4 < t < 4}, t, Reals, 3] // N (* {{t -> 3.35745}, {t -> -3.77452}, {t -> 0.762901}} *) 
Posted 5 months ago
 This link with code by users J.M. and Thales Fernandes should be extremely useful in finding all roots: FindAllCrossings and FindRoots
Posted 5 months ago
 Read first: ?FindRoot Use it, that will be easier for you: {FindRoot[Abs[3 - t^2] + Abs[t - 1] - t^2 == 3*Sin[t], {t, -3}], FindRoot[Abs[3 - t^2] + Abs[t - 1] - t^2 == 3*Sin[t], {t, 1}], FindRoot[Abs[3 - t^2] + Abs[t - 1] - t^2 == 3*Sin[t], {t, 3}]} 
Posted 5 months ago
 There's an undocumented function SystemTRootsDumpGuessRealRoots that finds pretty good initial points for FindRoot to polish up: ReduceAnalyticRootIsolation; (* initialization *) With[{f = Function[t, -t^2 + Abs[-1 + t] + Abs[3 - t^2] - 3 Sin[t]]}, FindRoot[f, {#}] & /@ SystemTRootsDumpGuessRealRoots[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 5 months 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?
 There's an undocumented function SystemTRootsDumpGuessRealRoots that finds pretty good initial points for FindRoot to polish up: ReduceAnalyticRootIsolation; (* initialization *) With[{f = Function[t, -t^2 + Abs[-1 + t] + Abs[3 - t^2] - 3 Sin[t]]}, FindRoot[f, {#}] & /@ SystemTRootsDumpGuessRealRoots[f, {-4, 4}] ] (* {{0.762901}, {3.35745}, {-3.77452}} *)