Hackety Hacking Problem Spring Oscillation TernaryOperator: Difference between revisions

From OLPC
Jump to navigation Jump to search
(New page: == Problem Statement == Your physics teacher is teaching you the principles of Oscillations. In a demonstration, She shows you how a spring oscillates. After compressing it to 1cm, accor...)
 
Line 3: Line 3:
Your physics teacher is teaching you the principles of Oscillations. In a demonstration, She shows you how a spring oscillates.
Your physics teacher is teaching you the principles of Oscillations. In a demonstration, She shows you how a spring oscillates.
After compressing it to 1cm, according to Hooke's Law, which is formulated as F = -K*x , the spring starts oscillating. Write a program which could plot the variation of force with change in length of the spring?
After compressing it to 1cm, according to Hooke's Law, which is formulated as F = -K*x , the spring starts oscillating. Write a program which could plot the variation of force with change in length of the spring?


== Sample Output ==

<pre>
Please enter the Spring Constant of Spring and press ENTER: 10
The Force at Compressed State = -10 N
The Force at Relaxed State = 0 N
The simulation of Spring motion is as : 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 9 , 8 , 7 ,6 , 5 , 4 , 3 , 2 , 1 , 0
</pre>

Revision as of 20:35, 9 October 2007

Problem Statement

Your physics teacher is teaching you the principles of Oscillations. In a demonstration, She shows you how a spring oscillates. After compressing it to 1cm, according to Hooke's Law, which is formulated as F = -K*x , the spring starts oscillating. Write a program which could plot the variation of force with change in length of the spring?


Sample Output

Please enter the Spring Constant of Spring and press ENTER: 10
The Force at Compressed State = -10 N
The Force at Relaxed State = 0 N 
The simulation of Spring motion is as : 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 9 , 8 , 7 ,6 , 5 , 4 , 3 , 2 , 1 , 0