function [ ] = prob_2_25 % % Written by: % -- % John L. Weatherwax 2005-05-07 % % email: wax@alum.mit.edu % % Please send comments and especially bug reports to the % above email address. % %----- options = odeset('Events',@events,'RelTol',1d-5,'AbsTol',1d-10); y0 = [ 0 1 ]; [ts,ys,te,ye,ie] = ode45( @f, [0, 20*pi], y0, options ); figure; plot( ts, ys(:,1), '-og' ); hold on; grid on; plot( te, ye(:,1), 'ob' ); figure; plot( abs(diff( te )-pi), '-o' ); y0 = [ 0 0.1 ]; [ts,ys,te,ye,ie] = ode45( @f, [0, 20*pi], y0, options ); figure; plot( ts, ys(:,1), '-og' ); hold on; grid on; plot( te, ye(:,1), 'ob' ); figure; plot( abs(diff( te )-pi), '-o' ); y0 = [ 0 0.01 ]; [ts,ys,te,ye,ie] = ode45( @f, [0, 20*pi], y0, options ); figure; plot( ts, ys(:,1), '-og' ); hold on; grid on; plot( te, ye(:,1), 'ob' ); figure; plot( abs(diff( te )-pi), '-o' ); return; function [dydt] = f(t,y) % % y is 2x1 % dydt = [ y(2); -sin(y(1)) ]; return; function [value,isterminal,direction] = events(t,y) global g nu; value = y(1); isterminal = 0; direction = 0; return;