# Part (a): # m = 0.25 g = 9.8 k = 0.2 x0 = 30 x = function(t){ x0 - (g*m*t)/k + ( (g*m^2)/(k^2) ) * ( 1 - exp(-k*t/m) ) } v = function(t){ ((g*m)/k)*( exp(-k*t/m) - 1 ) } ts = seq( 0, 5, length.out=100 ) xs = x(ts) plot(ts, xs, type='l') grid() library(stats) res = uniroot( x, c(3, 4) ) t_g = res\$root v_g = v(t_g) print( sprintf('t_g= %f v(t_g)= %f', t_g, v_g) ) # Part (b): # x0_lt = 10 # velocity on impact is less than 10 m/s x0_gt = 30 # velocity on impact is greater than 10 m/s while( abs(x0_gt-x0_lt)>0.01 ){ x0 = 0.5 * ( x0_lt + x0_gt ) # What time do we hit the ground: res = uniroot( x, c(0, 4) ) # What is our impact velocity when we hit: v_impact = v(res\$root) if( abs(v_impact)>10 ){ x0_gt = x0 }else{ x0_lt = x0 } print( c(x0_lt, x0_gt) ) } # Part (c): # x0 = 30 # set x0 back to 30 k_gt = 0.2 # velocity on impact is greater than 10 m/s k_lt = 0.5 # velocity on impact is less than 10 m/s while( abs(k_gt-k_lt)>0.001 ){ k = 0.5 * ( k_lt + k_gt ) # What time do we hit the ground: res = uniroot( x, c(0, 10) ) # What is our impact velocity when we hit: v_impact = v(res\$root) if( abs(v_impact)>10 ){ k_gt = k }else{ k_lt = k } print( c(k_gt, k_lt) ) }