1
$\begingroup$

Mathematica can not solve this:

g = 9.82;
ω = 0.5;
h = 5;
y0 = 1;
v = 0;
τ = 0;  

NSolve[h + v t - (g t^2)/2 == y0 Sin[ω t], t];

The error code is:

NSolve::nsmet: This system cannot be solved with the methods available to NSolve.

Any suggestions how to solve this equation ?


Background physical sketch

I need to calculate when and where the jumping ball and sinusoidal ground will collide. For the first one we know it is falling like:

h = h0 + v0 t - g t^2 / 2

For the ground we know it is moving as:

y = y0 Sin(omega t)

If we calculate h = y, extract t we get the time of the collision. Finally I need to plot the movement of the ball and the points of collision versus real time.

$\endgroup$
2
  • $\begingroup$ FindRoot[h + v t - (g t^2)/2 == y0 Sin[\[Omega] t], {t, 0}] $\endgroup$ Commented Feb 4, 2015 at 16:59
  • 1
    $\begingroup$ Tell it to solve over the real numbers: NSolve[h + v t - (g t^2)/2 == y0 Sin[\[Omega] t], t, Reals]. $\endgroup$
    – Greg Hurst
    Commented Feb 4, 2015 at 22:53

1 Answer 1

5
$\begingroup$

Update: reply to comment to display the move of the ball. Here is a quick Manipulate. You can make improvement as needed

enter image description here

Manipulate[
 tick;

 g = 9.82; y0 = 1; v = 0;
 h = h + v*t - g t^2/2;
 ymin = y0 Sin[w t];
 If[h - radius > ymin + thick, tick = Not[tick]; t = t + delT];
 Grid[{
   {"time", "h"},
   {t, h},
   {
    Graphics[
     {
      {Black, Disk[{0, h}, radius]},
      {Blue, Rectangle[{-1, ymin}, {1, ymin + .2}]},
      If[h - radius <= (ymin + thick),
       {Red, Style[Text["Crash!", {1.5 radius, ymin + 2 thick}], 14]}
       ]
      },
     PlotRange -> {{-1, 1}, {0, 5.5}}, AspectRatio -> Automatic, Axes -> True, 
        ImageSize -> 200], SpanFromLeft
    }
   }, Spacings -> {.1, .2}, Frame -> All, FrameStyle -> LightGray]
 ,
 Button["Run", h = 5; t = 0; ymin = 0; tick = Not[tick]],
 {{w, 1, "omega?"}, 0, 10, .1, ImageSize -> Small, Appearance -> "Labeled"},
 {{delT, 0.001, "animation speed?"}, 0.0001, 0.01, .0001, ImageSize -> Small, 
       Appearance -> "Labeled"},
 {{tick, True}, None},
 {{h, 5}, None},
 {{t, 0}, None},
 {{ymin, 0}, None},
 {{thick, 0.2}, None},
 {{radius, 0.1}, None},
 TrackedSymbols :> {tick}
 ]

Original answer

If you tell NSolve that time is positive (which it is), it can solve it

g = 9.82;
w = 0.5;
h = 5;
y0 = 1;
v = 0;

NSolve[h + v  t - (g t^2)/2 == y0 Sin[w t] && t > 0, t]

Mathematica graphics

$\endgroup$
3
  • $\begingroup$ Haha, thats funny. Thanks! ;) $\endgroup$
    – Vito
    Commented Feb 4, 2015 at 18:53
  • $\begingroup$ What would be the best way to plot the movement of the ball? $\endgroup$
    – Vito
    Commented Feb 4, 2015 at 19:28
  • $\begingroup$ @Vito I do not know how to play the movement of the ball, since it falls down. I made quick manipulate, easier. $\endgroup$
    – Nasser
    Commented Feb 4, 2015 at 21:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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