Skip to content

Instantly share code, notes, and snippets.

@mrampton
Created February 17, 2015 19:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrampton/ebcc6deeb388f2ed3b18 to your computer and use it in GitHub Desktop.
Save mrampton/ebcc6deeb388f2ed3b18 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
# example using problem 4.28 from Halliday Physics book
# ••28 In Fig. 4-34, a stone is pro-jected at a cliff of height h
# with an initial speed of 42.0 m/s directed at angle u0 􏰀 60.0° above
# the horizontal. The stone strikes at A, 5.50 s after launching. Find
# (a) the height h of the cliff, (b) the speed of the stone just before
# impact at A, and (c) the maximum height H reached above the ground.
class Fixnum
def to_rads
self * Math::PI / 180;
end
end
if __FILE__ == $PROGRAM_NAME
# given variables
velocity_i = 42; # m/s
theta_i = 60; # degrees
time_f = 5.5; # s
# find
h_max = nil;
h_final = nil;
v_final = nil;
# lemma variables
velocity_iy = Math.sin(theta_i.to_rads) * velocity_i;
gravity = -9.8; # m/s^2
# equation of motion
# v_f^2 = v_i^2 + 2g(r_f - r_i)
# => 0 = velocity_iy^2 + 2 * gravity * h_max
h_max = -velocity_iy**2 / (2 * gravity);
puts "Maximum height is: #{h_max} m";
# r_f - r_i = v_i * t + 1/2*a*t
h_final = velocity_iy * time_f + 0.5 * gravity * time_f**2;
puts "Final height is: %.2f m" % #{h_final};
v_final = Math.sqrt( (velocity_i * Math.cos(theta_i.to_rads))**2 + (velocity_iy + gravity * time_f)**2);
puts "Final Velocity is: %.2f m/s" % v_final;
# Output:
###########
# Maximum height is: 67.5 m
# Final height is: 27.35 m
# Final Velocity is: 27.35 m/s
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment