NTNUJAVA Virtual Physics Laboratory
Enjoy the fun of physics with simulations!
Backup site http://enjoy.phy.ntnu.edu.tw/ntnujava/

Easy Java Simulations (2001- ) => Questions related to EJS => Topic started by: lookang on June 11, 2012, 05:12:15 pm



Title: not sure why but total energy is not conserved in this model, can help debug?
Post by: lookang on June 11, 2012, 05:12:15 pm
hi prof,

not sure why but total energy is not conserved in this model, can help debug?

ke = 0.5*mtest*vxtest*vxtest;
//pe = -G*mtest*m2/Math.abs(x2-xtest)-G*mtest*m1/Math.abs(x1-xtest);
pe = Vy*mtest;
te = ke+pe;

i have been looking at this on and off, but cannot figure out what is wrong. te should be a constant value

the total energy of the mtest, te decays which is not suppose to happen. weird

:)

appreciate any help
thanks!


Title: Re: not sure why but total energy is not conserved in this model, can help debug?
Post by: Fu-Kwun Hwang on June 11, 2012, 09:00:02 pm
I downloaded your code, but it is too complicate.

It took me a lot of time try to understand it.


The problem I found is :

The evolution equations are:


d(xtest)/dt=vxtest;

d(vxtest)/dt=gy;


However, the gy is defined at constraint page (which is calculated after evolution page was done).

The evolution equations were calculated 4 times (when Runge-Kutta method was selected). -- This has something to do with numerical method.

However, gy was a constant in your code (and it was calculated after evolution page was processed).
You should use user defined function to return gy while evolution was processed.

And all the conditions related gy need to be done inside user's function.

I do not understand what you were doing so I do not know how to help you change your code.



Title: Re: not sure why but total energy is not conserved in this model, can help debug?
Post by: lookang on June 12, 2012, 11:20:20 am
hi prof!

the tip worked very well!

thank you very much again for helping teachers all over the world in customizing computer models to suit our learning and teaching needs. :)

attached is the corrected version thanks to engrg1's (we are colleagues in the same workplace)
help after discussion.

will post the refined simulation up ASAP. at http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=1924.0

the people who use Easy Java simulation are awesome!