% Matlab diary from cs110a, Feb 25 2005. % % This is what I typed in class. % % Type it into Matlab yourself to % reproduce the output I showed. help ode23tx help ode45 clc edit f type f function ydot = f(t,y) % F : function ydot = f(t,y) for ODE solution % % t: scalar time % y: vector, y = y(t), unknown function % % ydot: vector of dy / dt ydot = y/2; ode45( @f, [0 10], 1); ode45( @f, [0 10], 1);title('y(t) defined by ydot=f(t,y)'); xlabel('t'); ylabel('y'); exp(5) g = inline('y/2', 't', 'y') f(1,1) g(1,1) ode45( g, [0 10], 1);title('y(t) defined by ydot=g(t,y)'); xlabel('t'); ylabel('y'); h = @(t,y) y/2 h(1,1) ode45( h, [0 10], 1);title('y(t) defined by ydot=h(t,y)'); xlabel('t'); ylabel('y'); exp(5) ans = 148.4132 clc opts = odeset('reltol',10^-6); opts ode45( h, [0 10], 1, opts);title('y(t) defined by ydot=h(t,y)'); xlabel('t'); ylabel('y'); clc edit f type f function ydot = f(t,y) % F : function ydot = f(t,y) for ODE solution % % t: scalar time % y: vector, y = y(t), unknown function % % ydot: vector of dy / dt ydot = -y/2; ode45( @f, [0 10], 1);title('y(t) defined by ydot=f(t,y)'); xlabel('t'); ylabel('y'); edit f type f function ydot = f(t,y) % F : function ydot = f(t,y) for ODE solution % % t: scalar time % y: vector, y = y(t), unknown function % % ydot: vector of dy / dt ydot = t; ode45( @f, [0 10], 1);title('y(t) defined by ydot=f(t,y)'); xlabel('t'); ylabel('y'); clc edit lve type lve n ydot = lve(t,y) % LVE : ydot as a function of t and y(t) for Lotka-Volterra eqns % % t : time % y : vector y = [rabbits(t) ; foxes(t)] alpha = .01; ydot = [ 2*y(1) - alpha * y(1)*y(2) ; -y(2) + alpha*y(1)*y(2) ]; lve(2,[3 ; 4]) ans = 5.8800 -3.8800 clc ode45( @lve, [0 20], [300 ; 150]); legend('rabbits','foxes') ode45( @lve, [0 20], [15; 22]); legend('rabbits','foxes') ode45( @lve, [0 20], [102, 198]); legend('rabbits','foxes') ode45( @lve, [0 20], [100, 200]); legend('rabbits','foxes')