% coded by K. Stewart, reference Kahaner, Moler and Nash, p. 332 % (P8-5) in exercises for statement of problem % clear echo off clc % Consider rabbits and foxes % r'(t) = 2*r - alf * r * f % f'(t) = -f + alf * r * f % r(0) = r0; f(0) = r0 alfa=input('enter alfa for rabbits and foxes (e.g. .01) ' ); r0=input('enter initial rabbit population (e.g. 300) '); f0=input('enter initial fox population (e.g. 150) ' ); % share the parameter alfa with the derivative routine global alfa t0 = 0; tfinal=input('enter final value of time (e.g. 10) '); % a column vector y0 = [r0 f0]'; % Define initial conditions. % [t,y] = ode23('rabfox',t0,tfinal,y0); pause % Strike any key to start ODE23 solution. tol = 1.e-3; % Accuracy trace = 1; [t,y] = ode23('rabfox',t0,tfinal,y0,tol,trace); plot(t,y), title('Rabbit and Foxes model time history'), pause plot(y(:,1),y(:,2),y0(1),y0(2),'+',[y(1,1) y(2,1)],[y(1,2) y(2,2)]), ... title('Rabbit and Foxes - phase plane plot'),... text(y0(1),y0(2),'Initial Populations'),pause