echo on clc % ODE23 and ODE45 are functions for the numerical solution of % ordinary differential equations. They employ automatic step % size Runge-Kutta-Fehlberg integration methods. ODE23 uses a % simple 2nd and 3rd order pair of formulas for medium accuracy % and ODE45 uses a 4th and 5th order pair for higher accuracy. pause % Strike any key to continue. clc % Consider rabbits and foxes % r'(t) = 2*r - alfa * r * f % f'(t) = -f + alfa * 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 variable alfa between 'driver' and derivative routine 'rabfox' global alfa % % disp('the m file with derivatives '); type rabfox clc % To simulate the differential equation defined in RABFOX over the % interval 0 < t < 10, we invoke ODE23: t0 = 0; tfinal=input('enter final value of time (e.g. 12)'); y0 = [r0; f0]; % Define initial conditions. 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 % now plot Phase Portrait 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'),... xlabel('Rabbit Population'), ylabel('Fox Population'),... text(y0(1),y0(2),'Initial Populations'),pause