 Author Topic: what is the elegant way to make EJS measure a true period of an oscillation?  (Read 8014 times)

lookang

• Hero Member
•     • • Posts: 1774
• http://weelookang.blogspot.com what is the elegant way to make EJS measure a true period of an oscillation?
« on: January 13, 2009, 12:07:15 pm »
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?

Fu-Kwun Hwang

• Hero Member
•     • • Posts: 3062 Re: what is the elegant way to make EJS measure a true period of an oscillation?
« Reply #1 on: January 13, 2009, 05:35:24 pm »
1. The AND operator operator you want is && not &.
& is bitwise AND

2.
if ( omega < 0.001 && omega > -0.001 )
is not a good condition
What 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

if( omega*omegas<0){
count=count+1;
}
omegas=omega;/save old value
if(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;

lookang

• Hero Member
•     • • Posts: 1774
• http://weelookang.blogspot.com Re: what is the elegant way to make EJS measure a true period of an oscillation?
« Reply #2 on: January 13, 2009, 11:00:43 pm »
indeed an elegant/clever way to find true period.

thanks!

will try to implement into my pendulum asap

if( omega*omegas<0){
count=count+1;
}
omegas=omega;//save old value
if(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 « Last Edit: January 14, 2009, 04:41:47 pm by lookang »