NTNUJAVA Virtual Physics LaboratoryEnjoy the fun of physics with simulations! Backup site http://enjoy.phy.ntnu.edu.tw/ntnujava/
January 22, 2021, 11:14:55 pm

"Reflect, review and renew constantly." ...Wisdom

 Pages: [1]   Go Down
 Author Topic: what is the elegant way to make EJS measure a true period of an oscillation?  (Read 7791 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: January 13, 2009, 11:07:15 am » posted from:SINGAPORE,SINGAPORE,SINGAPORE

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?
 Logged
Fu-Kwun Hwang
Hero Member

Offline

Posts: 3086

 « Embed this message Reply #1 on: January 13, 2009, 04:35:24 pm » posted from:Taipei,T'ai-pei,Taiwan

1. The AND operator operator you want is && not &.
& is bitwise AND

2.
Code:
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

Code:
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;
 Logged
lookang
Hero Member

Offline

Posts: 1796

http://weelookang.blogspot.com

 « Embed this message Reply #2 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 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, 03:41:47 pm by lookang » Logged
 Pages: [1]   Go Up
"Reflect, review and renew constantly." ...Wisdom