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