# Finding all roots to equation [duplicate]

I'm currently doing some Mathematica exercises, and I'm stuck on this one task where you're supposed to plot the functions h(t)= |3-t^2|+|t-1|-t^2 , g(t)=3sin(t) in the same grap, and then find all the roots. This is what I've got so far:

The instructions say that I should use FindRoot to exactly decide all the roots, but I don't think I've done it right. What should I change with the function in order to make it find all of the roots?

## marked as duplicate by Szabolcs, Daniel Lichtblau, AccidentalFourierTransform, Michael E2 equation-solving StackExchange.ready(function() { if (StackExchange.options.isMobile) return; $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() { var$hover = $(this).addClass('hover-bound'),$msg = $hover.siblings('.dupe-hammer-message');$hover.hover( function() { $hover.showInfoMessage('', { messageElement:$msg.clone().show(), transient: false, position: { my: 'bottom left', at: 'top center', offsetTop: -7 }, dismissable: false, relativeToBody: true }); }, function() { StackExchange.helpers.removeMessages(); } ); }); }); Dec 9 '18 at 18:17

• Solve[{Abs[3 - t^2] + Abs[t - 1] - t^2 == 3*Sin[t], -5 <= t <= 5}, t] works for me in V11.3, but not NSolve for some reason. – Michael E2 Dec 9 '18 at 15:14
• @MichaelE2 - I would guess that NSolve uses a derivative and cannot handle Abs. Since the values are real, a workaround is NSolve[{Abs[3 - t^2] + Abs[t - 1] - t^2 == 3*Sin[t] /. Abs[z_] :> Sqrt[z^2], -5 <= t <= 5}, t] – Bob Hanlon Dec 9 '18 at 22:25
• @BobHanlon You can see in the comments to @zhk's answer below that NSolve works in earlier versions of Mma. While there's some plausibility in your suggestion, it stills seems a backslide. – Michael E2 Dec 9 '18 at 23:58

You can use NSolve to find multiple roots,

NSolve[{Abs[3 - t^2] + Abs[t - 1] - t^2 == 3*Sin[t], -5 <= t <= 5}, t]


{{t -> -4.92954}, {t -> -3.77452}, {t -> 0.762901}, {t -> 3.35745}}

or FindAllCrossings from here,

FindAllCrossings[Abs[3 - t^2] + Abs[t - 1] - t^2 == 3*Sin[t], {t, -10, 10},
WorkingPrecision -> 20]


{-4.9295434376879868373, -3.7745180124835511931, 0.76290087955924483126, 3.3574487606850113852}

or FindRoot providing good initial guesses,

FindRoot[{Abs[3 - t^2] + Abs[t - 1] - t^2 == 3*Sin[t]}, {t, #}] & /@ {-5, -3, 1, 4}


{{t -> -4.92954}, {t -> -3.77452}, {t -> 0.762901}, {t -> 3.35745}}

• When i try NSolve i get nothing back as output? Also, the FindAllCrossings isn't working either. – wznd Dec 9 '18 at 12:34
• @wznd You should input the interval of interest. – zhk Dec 9 '18 at 12:38
• @wznd. For me NSolve and FindAllCrossings works fine,I checked on Mathematica 10.2 and 11.3. – Mariusz Iwaniuk Dec 9 '18 at 12:50
• @MichaelE2. With little modification works on MMA 11.3: NSolve[{RealAbs[3 - t^2] + RealAbs[t - 1] - t^2 == 3*Sin[t], -5 <= t <= 5}, t] – Mariusz Iwaniuk Dec 9 '18 at 14:28
• @MichaelE2 "11.0.1 for Microsoft Windows (32-bit)" – zhk Dec 9 '18 at 14:35