% % code12Fa.m -- 22 nov 02 -- djm % % - two-population code clear global ODE r1 a1 r2 a2 s1 s2 % set ODE choice disp(' ') disp(' ODE choices:') disp(' 1) two limited populations') disp(' 2) grass & cattle') disp(' 3) grass & hungry cattle') disp(' 4) food-limited cattle') disp(' 5) example 2, page 495') disp(' ') setup = input('choose #/R: '); disp(' ') disp(' click to choose IV (top to continue; bottom to quit)') disp(' ') switch setup case{1} ODE = 1; r1 = 1; a1 = 0.5; r2 = 1; a2 = 0.5; s1 = 0; s2 = 0; pname = '\bf decoupled logistic populations'; case{2} ODE = 1; r1 = 1; a1 = 0.5; r2 = 1; a2 = 0.5; s1 = 0.2; s2 = 0; pname = '\bf cows eat grass'; case{3} ODE = 1; r1 = 1; a1 = 0.5; r2 = 1; a2 = 0.5; s1 = 1.2; s2 = 0; pname = '\bf hungry cows eat more grass'; case{4} ODE = 1; r1 = 1; a1 = 0.5; r2 = -1; a2 = 0.0; s1 = 1; s2 = -1; pname = '\bf cows need grass to eat'; case{5} ODE = 2; r1 = 1; a1 = 1; r2 = 0.5; a2 = 0.25; s1 = 1; s2 = 0.75; pname = '\bf example 2, page 495'; otherwise break end figure(1); clf; hold on title(pname) xlabel('\bf y(t)-axis') ylabel('\bf z(t)-axis') axis([-0.1 4 -0.1 4]); text(3, 4.2,'click to continue -> X') text(3,-0.5,'click to quit -> X') IV = []; while (isempty(IV)) click = ginput(1); IV = round(10*click)/10; % bottom to quit, top to continue if(IV(2) < -0.1) disp(['IV = quit']) break elseif(IV(2) > 4.0) IV = y(end,:); disp(['IV = continue']) else disp(['IV = ' num2str(IV)]) end % invoke runge-kutta solver opt = odeset('RelTol',1e-3,'AbsTol',1e-6); [t y] = ode45(@Fode12Wb,[0 10],IV,opt); plot(y(:,1),y(:,2),'r') plot(IV(1),IV(2),'ko') IV = []; end