Skip to main content
edited tags
Link
user21
user21
added 189 characters in body
Source Link
cmc
  • 751
  • 1
  • 6
  • 13

This is an example in Mathematica's help document.

NDSolve[{y''[t] == -9.81, y[0] == 5, y'[0] == 0,  
   WhenEvent[y[t] == 0, y'[t] -> -0.95 y'[t]]}, y, {t, 0, 10}];
Plot[y[t] /. %, {t, 0, 10}]

I do a modification like this:

NDSolve[{y''[t] == -9.81, y[0] == 5, y'[0] == 0, a = y[t]; b=y'[t];
   WhenEvent[a == 0, b -> -0.95 b]}, y, {t, 0, 10}];
Plot[y[t] /. %, {t, 0, 10}]

It doesn't work.

If I want to keep a new symbol just as here a to represent the y[t] or some expression about y[t] in the WhenEvent, what can I do to achieve this goal?

(The error may be caused by the HoldAll attribute of WhenEvent. Why I want to replace the y[t] by a? It is important to me. Bucause I will use a dynamic a in the WhenEvent )

This is an example in Mathematica's help document.

NDSolve[{y''[t] == -9.81, y[0] == 5, y'[0] == 0,  
   WhenEvent[y[t] == 0, y'[t] -> -0.95 y'[t]]}, y, {t, 0, 10}];
Plot[y[t] /. %, {t, 0, 10}]

I do a modification like this:

NDSolve[{y''[t] == -9.81, y[0] == 5, y'[0] == 0, a = y[t]; b=y'[t];
   WhenEvent[a == 0, b -> -0.95 b]}, y, {t, 0, 10}];
Plot[y[t] /. %, {t, 0, 10}]

It doesn't work.

If I want to keep a new symbol just as here a to represent the y[t] or some expression about y[t] in the WhenEvent, what can I do to achieve this goal?

This is an example in Mathematica's help document.

NDSolve[{y''[t] == -9.81, y[0] == 5, y'[0] == 0,  
   WhenEvent[y[t] == 0, y'[t] -> -0.95 y'[t]]}, y, {t, 0, 10}];
Plot[y[t] /. %, {t, 0, 10}]

I do a modification like this:

NDSolve[{y''[t] == -9.81, y[0] == 5, y'[0] == 0, a = y[t]; b=y'[t];
   WhenEvent[a == 0, b -> -0.95 b]}, y, {t, 0, 10}];
Plot[y[t] /. %, {t, 0, 10}]

It doesn't work.

If I want to keep a new symbol just as here a to represent the y[t] or some expression about y[t] in the WhenEvent, what can I do to achieve this goal?

(The error may be caused by the HoldAll attribute of WhenEvent. Why I want to replace the y[t] by a? It is important to me. Bucause I will use a dynamic a in the WhenEvent )

Source Link
cmc
  • 751
  • 1
  • 6
  • 13

Using new symbol in WhenEvent in NDSolve

This is an example in Mathematica's help document.

NDSolve[{y''[t] == -9.81, y[0] == 5, y'[0] == 0,  
   WhenEvent[y[t] == 0, y'[t] -> -0.95 y'[t]]}, y, {t, 0, 10}];
Plot[y[t] /. %, {t, 0, 10}]

I do a modification like this:

NDSolve[{y''[t] == -9.81, y[0] == 5, y'[0] == 0, a = y[t]; b=y'[t];
   WhenEvent[a == 0, b -> -0.95 b]}, y, {t, 0, 10}];
Plot[y[t] /. %, {t, 0, 10}]

It doesn't work.

If I want to keep a new symbol just as here a to represent the y[t] or some expression about y[t] in the WhenEvent, what can I do to achieve this goal?