NTNUJAVA Virtual Physics LaboratoryEnjoy the fun of physics with simulations! Backup site http://enjoy.phy.ntnu.edu.tw/ntnujava/
January 20, 2021, 05:42:10 am

 Pages: [1]   Go Down
 Author Topic: not sure why but total energy is not conserved in this model, can help debug?  (Read 4538 times) 0 Members and 1 Guest are viewing this topic. Click to toggle author information(expand message area).
lookang
Hero Member

Offline

Posts: 1796

http://weelookang.blogspot.com

 « Embed this message on: June 11, 2012, 05:12:15 pm » posted from:SINGAPORE,SINGAPORE,SINGAPORE

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!
 weird.png (50.93 KB, 758x634 - viewed 437 times.) *** There are 1 more attached files. You need to login to acces it! « Last Edit: June 11, 2012, 05:14:42 pm by lookang » Logged
Fu-Kwun Hwang
Hero Member

Offline

Posts: 3086

 « Embed this message Reply #1 on: June 11, 2012, 09:00:02 pm » posted from:Taipei,T'ai-pei,Taiwan

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.

 Logged
lookang
Hero Member

Offline

Posts: 1796

http://weelookang.blogspot.com

 « Embed this message Reply #2 on: June 12, 2012, 11:20:20 am » posted from:SINGAPORE,SINGAPORE,SINGAPORE

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!
 *** There are 1 more attached files. You need to login to acces it! Logged
 Pages: [1]   Go Up