4
$\begingroup$

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:

enter image description here

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?

Thanks in advance.

$\endgroup$
3
  • $\begingroup$ 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. $\endgroup$
    – Michael E2
    Commented Dec 9, 2018 at 15:14
  • $\begingroup$ @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] $\endgroup$
    – Bob Hanlon
    Commented Dec 9, 2018 at 22:25
  • $\begingroup$ @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. $\endgroup$
    – Michael E2
    Commented Dec 9, 2018 at 23:58

1 Answer 1

8
$\begingroup$

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}}

$\endgroup$
7
  • $\begingroup$ When i try NSolve i get nothing back as output? Also, the FindAllCrossings isn't working either. $\endgroup$
    – jhndoe2
    Commented Dec 9, 2018 at 12:34
  • $\begingroup$ @wznd You should input the interval of interest. $\endgroup$
    – zhk
    Commented Dec 9, 2018 at 12:38
  • $\begingroup$ @wznd. For me NSolve and FindAllCrossings works fine,I checked on Mathematica 10.2 and 11.3. $\endgroup$ Commented Dec 9, 2018 at 12:50
  • 1
    $\begingroup$ @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] $\endgroup$ Commented Dec 9, 2018 at 14:28
  • 1
    $\begingroup$ @MichaelE2 "11.0.1 for Microsoft Windows (32-bit)" $\endgroup$
    – zhk
    Commented Dec 9, 2018 at 14:35

Not the answer you're looking for? Browse other questions tagged or ask your own question.