question.rb
solution.rb
playground.rb
1 require_relative "../physics" 2 3 question :a_block_on_a_spring do 4 kind :numerical 5 describes "A block whose mass is %{mass} is fastened to a spring. The spring has a spring constant of %{constant}. " \ 6 "The block is pulled to a distance x = %{amplitude} from its equilibrium position at x = 0 on a " \ 7 "frictionless surface from rest at t = 0. %{energy} when it is %{place} away from the mean position, in " \ 8 "joules?" 9 given mass: "1 kg" 10 given constant: "50 N/m" 11 given amplitude: "10 cm" 12 given place: "5 cm" 13 asks energy: "What is the kinetic energy of the block" 14 end
1 require_relative "../questions/a_block_on_a_spring" 2 require_relative "../science/oscillations/spring_oscillator" 3 4 solve :a_block_on_a_spring , using: SpringOscillator do 5 objects :block 6 axes :x 7 block . goes ( :oscillating ) 8 9 take mass: block . mass 10 take constant: block . spring_constant 11 take amplitude: block . amplitude 12 take place: block . final_position 13 14 energy = block . kinetic_energy ( at: oscillating . end ) 15 answer energy :, in: "J" , figures: 2 16 17 conclusion "The oscillator's energy stays half the spring constant times the amplitude squared; halfway " \ 18 "out, the spring holds a quarter of it and the rest is the block's motion." 19 end
1 require_relative "../solutions/a_block_on_a_spring" 2 3 play_with :a_block_on_a_spring do 4 title "A Block on a Spring" 5 end