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

Information about this web site => Question related to Physics or physics related simulation => Topic started by: mickey2times on April 03, 2012, 06:41:25 pm



Title: Problem with Extra energy in vertical spring simulation
Post by: mickey2times on April 03, 2012, 06:41:25 pm
I am creating a simulation that models a spring loaded launcher throwing a projectile straight up into the air, and then pauses at the top.  When creating graphs of the PEsp, PEg, KE and ME of the system I noticed that there is an increase in total energy when the projectile is launched.  After the launch everything seems to be fine, but I cannot figure out why there is an increase in energy in the beginning.  The PEg, should go up, the KE should go up and the PEsp should go down, but they should all balance out.

The only guess I have is that is might have something to do with the solver (I am using Euler-Richardson on 0.02 increments)  I tried lowering the increment to 0.01, 0.001 and it seemed to help but I could never get rid of the energy increase in the beginning.  Just not sure if this is a error in my programing, or something that it a limitation of how the DEq is being run.

I attached my .ejs file, so hopefully someone with different eyes might spot something.

thanks in advance,
Mike


Title: Re: Problem with Extra energy in vertical spring simulation
Post by: Fu-Kwun Hwang on April 05, 2012, 01:43:00 pm
You have the following code at Evolution Page:
Code:
dv/dt=-k*y2/m-9.8
However, y2 is re-calculated at "Fixed Relation" Page,
which is processed after  "Evolution Page".

Code:
if (y < 0 ) y2 = y;
else y2 = 0;

At "Custom page": Click to create a page
You will find default code like the following
Code:
public void lib_Page () {
}

Change it to
Code:
public double myYvalue(double y){
 if(y<0)return y;
 return 0;
}

Then in the "Evolution Page"
Code:
dv/dt = -k*myYvalue(y)/m-9.8

You can change myYvalue to any name you want, however, you need to use the same name in the evolution page.

The function myYvalue will be called in the evolution page (at the time it is needed).



Title: Re: Problem with Extra energy in vertical spring simulation
Post by: lookang on April 10, 2012, 08:57:34 am
hi mickey2times,
i suspect the KE is giving your simulation a problem in displaying a constant value throughout the motion

when
y = -ve, KE = ok
y = -some value below zero, KE0- = ok
y = some value above zero, KE0+ = a bit different from KE0-

i could not solve this problem but i suspect it could be overcome by setting up an event handler to calculate the KE at y = 0, assign the KE0 into the release KE at some t in between the t KE0- and t KE0+

attached is my attempt to implement Prof Hwang custom method myYvalue(y) which works!


Title: Re: Problem with Extra energy in vertical spring simulation
Post by: mickey2times on April 12, 2012, 07:04:55 am
thanks lookang and Prof. Hwang.  I implemented your changes and got it the way I wanted.  There is still a tiny error in the beginning but it does not affect any numbers.  thank you again for your continued help, and for helping to support EJS.  my EJS sims have become invaluable to student learning in my physics class.