1require_relative "../physics"23question :pendulum_by_dimensions do4 describes "A pendulum of length %{length} and bob of mass %{mass} swings where gravity is %{gravity}. %{period}?"5 given :length6 given :gravity7 given :mass8 asks period: "How does its period depend on what it is made of"9end
1require_relative "../questions/pendulum_by_dimensions"2require_relative "../science/units_and_measurement/dimensional_analysis"34solve :pendulum_by_dimensions, using: DimensionalAnalysis do5 take length: :l, gravity: :g, mass: :m6 assume k: 2 * pi7 find_value :x8 find_value :y9 find_value :z10 take period: :T11 find_value :period1213 conclusion "Only powers that make the dimensions match are allowed: x + y = 0 for length, " \14 "−2y = 1 for time and z = 0 for mass. So T = k√(l ⁄ g). The mass drops out, and " \15 "dimensions alone could never have told you that k is 2π."16end
1require_relative "../solutions/pendulum_by_dimensions"2require_relative "../science/motion_in_a_plane/gravity"34play_with :pendulum_by_dimensions do5 title "A Pendulum by Dimensions"67 input :l, 0.1..3.0, in: "m", step: 0.05, default: 1.0, as: "length"8 input :g, 1.0..25.0, step: 0.01, default: 9.81, marks: GRAVITY, as: "gravity"9 input :m, 0.1..10.0, step: 0.1, default: 1.0, as: "mass in kilograms"1011 output :x, as: "power of length"12 output :y, as: "power of gravity"13 output :z, as: "power of mass"14 output :T, in: "s"15end