APS Excellence in Physics Education Award
November 2019

Education Prize Logo
Science SPORE Prize
November 2011

NSF Logo
The Open Source Physics Project is supported by NSF DUE-0442581.

Exercise 2.19 d in Introd Computer Simulation Methode post and replies

Return to the Exercise 2.19 d in Introd Computer Simulation Methode thread
Login to post to this thread

Exercise 2.19 d9 on page 40 of Introd Comp Sim Meth
Martin Jola
7 Posts

I'm not sure wether I understand this part of the exercise. In BouncingBall class I added a new methode for kinetic energy (I initialized the variables)
public void calc(){
energy = ((vx*vx)+(vy*vy)/2);

and in the App Class in doStep
for (int i=0;iball[i].calc();
totalenergy +=ball[i].energy ;
}
control.println("totalenergy = " +totalenergy);

It works well, however the results seem to be strange When I plot the result I get an up and down curve for each ball. With large number of balls the plot is almost completely full. When I add the potential energy as well (y*g) I get a streigth line upwartds. Can you comment my code and the result? Did I missunderstand the exercies?
So far all exercises in Chap 2 have not been a problem.
regards

martin

Post edited August 2, 2012 at 11:23 AM EST.


Replies to Exercise 2.19 d9 on page 40 of Introd Comp Sim Meth

Re: Exercise 2.19 d9 on page 40 of Introd Comp Sim Meth -
Wolfgang
181 Posts

Martin:  I am not sure what you are doing but it appears to me that your kinetic energy calculation is missing a factor of 0.5.  Also, are you setting the total energy variable equal to zero before you enter the loop?



Re: Re: Exercise 2.19 d9 on page 40 of Introd Comp Sim Meth -
Martin Jola
7 Posts

Hello Wolfgang

many thanks for your comments. You are right, I forgot to divide by 2 in my question, but I had included it in the source code, sorry for this.

I attached the two source codes and I'm just wondering whether my solution for the exercise is correct or not. If not what is the correct solution?

For me, the result does not make any physical sense. I'm not sure about the follwing:
a) should I use the absolute values of vx/vy? I think yes
b) are the velocities vx/vy set to random values at each step or are they constant over all steps? I believe they are constant over all time steps, they are set randomly only the first time.
c) the kinetic energy does not make sense because collision with other balls are not taken into account in the simulation.

Best regards

Martin

Attached File: BouncingBallApp.txt



Re: Re: Exercise 2.19 d9 on page 40 of Introd Comp Sim Meth -
Martin Jola
7 Posts

Hello Wolfgang

hier is the other source code file Bouncing Ball as states in my former email.

regards

Martin

Attached File: BouncingBall.txt



Re: Re: Re: Exercise 2.19 d9 on page 40 of Introd Comp Sim Meth -
Wolfgang
181 Posts

The formula for kinetic energy is incorrect.  Your code has:
((vx*vx)+(vy*vy)/2);

The correct expression for the kinetic energy is:
(vx*vx+vy*vy)/2;

Also note that the Euler method has a large numerical error and your simulation will show an increase in energy unless the time step is very very small.

Post edited August 4, 2012 at 8:36 AM EST.



OSP Projects:
Open Source Physics - EJS Modeling
Tracker
Physlet Physics
Physlet Quantum Physics
STP Book