% script to bracket a solution to the constForce.m problem % LAB1, PHYS220 Spring 2009 % givens (from problem statement) x_o = 0; v_o = 30; a = -9.81; % target values v_target = 0; % particle at rest x_target = 0; % particle returns to start %% we'll do case for v = 0 first % some constants & starting values tol = 0.05; % we'll allow a miss of up to this amount t = 2; % start at this time to find v = 0 step_t = 0.5; % coarse starting search div_t = 2; % cut step in half on each bracket % initial v vars = constForce(t,[x_o v_o],a); % for display purposes disp(' ') disp(' t (s) v (m/s) Dt (s)') disp([t vars(2) step_t]) % search over angles, cut steps in half every time we pass target, display % each step in the bracketing operation while abs(v_target-vars(2)) > tol t = t + step_t; vars = constForce(t,[x_o v_o],a); disp([t vars(2) step_t]) if sign(v_target-vars(2)) == sign(step_t) step_t = -step_t/div_t; end end %% now we'll look for x = 0 (the second instance) % note the amount of code recycling here! % some constants & starting values tol = 0.05; % we'll allow a miss of up to this amount t = 5; % start at this time to find v = 0 step_t = 0.5; % coarse starting search div_t = 2; % cut step in half on each bracket % initial v vars = constForce(t,[x_o v_o],a); % for display purposes disp(' ') disp(' t (s) x (m) Dt (s)') disp([t vars(1) step_t]) % search over angles, cut steps in half every time we pass target, display % each step in the bracketing operation while abs(v_target-vars(1)) > tol t = t + step_t; vars = constForce(t,[x_o v_o],a); disp([t vars(1) step_t]) if sign(v_target-vars(1)) == sign(step_t) step_t = -step_t/div_t; end end return