Message Boards Message Boards

2
|
8090 Views
|
9 Replies
|
10 Total Likes
View groups...
Share
Share this post:

Impact of a ball against a wall

Posted 9 years ago
Attachments:
POSTED BY: Varun Kulkarni
9 Replies
Posted 9 years ago

No problem. I enjoy this. I'm always learning something new in this forum. If the new question is on another topic, you might consider putting it in a new post. No one on this site minds seeing a lot of questions!

POSTED BY: David Keith
Posted 9 years ago
POSTED BY: Varun Kulkarni
Posted 9 years ago

And for "How do I simulate the impact of a ball with a wall a finite number of times (say 5)?"

This code counts bounces, and stops the integration at the top after the 5th bounce:

eqs = {x''[t] == 0, x'[0] == 10, x[0] == 0, y''[t] == -10., 
   y'[0] == 50, y[0] == 0};

events = {
   WhenEvent[y[t] < 0, {y'[t] -> -.9 y'[t], counter = counter + 1}],
   WhenEvent[y'[t] < 0, If[counter >= 5, "StopIntegration"]]
   };

counter = 0; {xx, yy} = 
 NDSolveValue[{eqs, events}, {x, y}, {t, 0, Infinity}];

ParametricPlot[{xx[t], yy[t]}, {t, 0, xx[[1, 1, 2]]}]

enter image description here

POSTED BY: David Keith
Posted 9 years ago

Hi David,

Is there any way to animate a 2-D body like a rectangle or a square that follows the same motion as the ball above for 5 bounces using elastic impacts so that the height of the bounce is equal everytime?

Thanks.

POSTED BY: Varun Kulkarni
Posted 9 years ago
Attachments:
POSTED BY: David Keith
Posted 9 years ago

Hi,

Works well. Thanks

I had a doubt regarding another question that I saw, would it be ok if I ask.

Hope that I am not bothering you with my trivial queries.

Thanks

POSTED BY: Varun Kulkarni
Posted 9 years ago
q = {{x[t]}, {y[t]}};

dq = D[q, t];
ddq = D[dq, t];


dx = D[x, t];
dy = D[y, t];
ddx = D[dx, t];
ddy = D[dy, t];


KE = 0.5 m (x'[t]^2 + y'[t]^2);
PE = m*g*y[t];

L = KE - PE;

(*The constraint*)
\[Phi] = y;
d\[Phi] = D[\[Phi], q];

Eq = (Thread[D[D[L, dq\[Transpose]], t] - D[L, q\[Transpose]] == 0]);

ELtemp = Solve[Eq[[1]] && Eq[[2]], Flatten[ddq]];

EL = {x''[t] == ELtemp[[1, 1, 2]], y''[t] == ELtemp[[1, 2, 2]]};

p = D[L, dq\[Transpose]];
H = p.dq - L;

m = 1;
g = 9.8;

ICnt = 5;
xzero = 0; xdzero = 3; yzero = 10; ydzero = 0; Tzero = 0;
x1 = {}; y1 = {}; Time = {}; P1 = {}; Hset = {};

(*The calculations of the Lagrangian just before and after impact \
with the wall*)
FullSimplify[D[L, dq]*dq - L];
(*This is the condition just before impact and is constrained to hit \
the wall along x=0*)
FullSimplify[
  eq1 = (Thread[(D[L, dq] /. t -> Tplus) - (D[L, dq] /. 
         t -> Tminus) == \[Lambda]*d\[Phi]])];
(*This is the condition just after inpact and there is no constraint*)


FullSimplify[
  eq2 = (Thread[((D[L, dq]*dq - L) /. 
         t -> Tplus) - ((D[L, dq]*dq - L) /. t -> Tminus) == 0])];
ImpactTemp = 
  Solve[eq1[[1]] && eq2[[1]], 
   Join[{x'[Tplus]}, {y'[Tplus]}, {\[Lambda]}]];

For[i = 0, i < ICnt, i++, 
  InitCon = {\[Theta][Tzero] == xzero && 
     yzero, \[Theta]'[Tzero] == -xdzero && -ydzero};
  sol = NDSolve[Join[EL, Initial], {x, y}, {t, Tzero, 30}, 
    Method -> {"EventLocator", "Event" -> y, 
      "EventAction" :> 
       Throw[{Tend = t, yend = y[t], ydotend = y'[t]}, 
        "StopIntegration"]}];
  xsol = x[t] /. sol[[1]]; ysol = y[t] /. sol[[1]]; 
  Hsol = H /. sol[[1]];
  x1 = Append[x1, xsol]; y1 = Append[y1, ysol]; 
  Time = Append[Time, Tend];
  Hset = Append[Hset, {Hsol, Tzero < t <= Tend}]; 
  P1 = Append[P1, {xsol && ysol, Tzero < t <= Tend}];
  yzero = yend; ydzero = ydotend;
  Tzero = Tend
  ];
    \[Theta]finalsol = Piecewise[P1];
    Hfinalsol = Piecewise[Hset];



(*InitCon={x'[0]\[Equal]3, x[0]==0, y[0]==10, y'[0]==0};


sol=NDSolve[Join[EL,InitCon],{x,y},{t,0,30}] ;
xsol=x[t]/.sol[[1]];
ysol=y[t]/.sol[[1]];*)

(*PLOTS*)
Plot[xsol, {t, 0, 2}, AxesLabel -> {t, x}]
Plot[ysol, {t, 0, 2}, AxesLabel -> {t, y}]
ParametricPlot[{xsol, ysol}, {t, 0, 2}, AxesLabel -> {x, y}]

(*Hamiltonian and its Plot*)
Plot[\[Theta]finalsol, {t, 0, Tend}, 
 AxesLabel -> {t, HoldForm[\[Theta]]}]
Plot[Hfinalsol, {t, 0, Tend}, AxesLabel -> {t, HoldForm[H]}]

(*Plot[xsol,{t,0,10}, AxesLabel\[Rule]{t,x}]
Plot[ysol,{t,0,10}, AxesLabel\[Rule]{t,y}]*)
X[\[Tau]_] := R*Sin[\[Theta]finalsol] /. t -> \[Tau];
Y[\[Tau]_] := -R*Cos[\[Theta]finalsol] /. t -> \[Tau];


(*ANIMATION*)
X[\[Tau]_] := xsol /. \[Theta]finalsol /. t -> \[Tau];
Y[\[Tau]_] := ysol /. \[Theta]finalsol /. t -> \[Tau];

Animate[Graphics[{PointSize[0.05], Point[{ X[\[Tau]], Y[\[Tau]]}], 
   Line[{{-10, 0}, {10, 0}}], Line[{{0, -10}, {0, 10}}]}], {\[Tau], 0,
   2}]

I tried this to get a ball to bounce to 5 times and then stop. But it gives me certain errors like equations are not a quantified system of equalities and some replacement rules are not valid.

Any suggestions on how to proceed?

Thanks Varun

Attachments:
POSTED BY: Varun Kulkarni
POSTED BY: Nasser M. Abbasi
Posted 9 years ago

Works perfectly.

Say if I want to use Event Locator[] like the one I have used for the pendulum and solve an impact equation, do i use it inside Manipulate?

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

Group Abstract Group Abstract