# NTNUJAVA Virtual Physics LaboratoryEnjoy 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 January 13, 2009, 11:07:15 am

 Title: what is the elegant way to make EJS measure a true period of an oscillation? Post by: lookang on January 13, 2009, 11:07:15 am what is the elegant way to make EJS measure a true period of an oscillation?I want to make a pendulum to measure the true period.i tried if ( omega < 0.001 & omega > -0.001 ) {  // my inital idea how to detect the end points of the oscillation  count = count+1;                               // make count increase by 1 if condition met}if (  count ==2 ) {              // count =2  T1 = t ;                                      // T1 = t}it doesn't work.any tips work to do it? Title: Re: what is the elegant way to make EJS measure a true period of an oscillation? Post by: Fu-Kwun Hwang on January 13, 2009, 04:35:24 pm 1. The AND operator operator you want is && not &. & is bitwise AND2. Code:if ( omega < 0.001 && omega > -0.001 )  is not a good conditionWhat if acceleration is very small, omega still smaller then 0.001 in two or more time step.And if the pendulum starts with omega=0, you might get half period only. What about define a omegas to store previous omega and change the condition to Code:if( omega*omegas<0){ count=count+1;}omegas=omega;/save old valueif(count==2){ T=t-ts;// period=time differences, not necessary starts from t=0  ts=t; count=0;//you need to reset the counter, unless you only want to calculate the first period}However, the above code work only if the pendulum starts with omega=0; Title: Re: what is the elegant way to make EJS measure a true period of an oscillation? Post by: lookang on January 13, 2009, 10:00:43 pm indeed an elegant/clever way to find true period.thanks!will try to implement into my pendulum asapif( omega*omegas<0){ count=count+1;}omegas=omega;//save old valueif(count==2){ T=t-ts;// period=time differences, not necessary starts from t=0  ts=t; count=0;//you need to reset the counter, unless you only want to calculate the first period}will update my progress on your forum soon :)