Lab11 - Engineering 7: Introduction to Programming for...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Engineering 7: Prof. Alexandre Bayen Introduction to Programming for Engineers Spring 2011 Lab 11: Ordinary Differential Equations Date Assigned: 5:00pm, Friday – April 22. Date Due: 5:00pm, Friday – April 29. The following help file for ode45 will be helpful for you during this lab. ODE45 Solve non-stiff differential equations, medium order method. [TOUT,YOUT] = ODE45(ODEFUN,TSPAN,Y0) with TSPAN = [T0 TFINAL] integrates the system of differential equations y' = f(t,y) from time T0 to TFINAL with initial conditions Y0. ODEFUN is a function handle. For a scalar T and a vector Y, ODEFUN(T,Y) must return a column vector corresponding to f(t,y). Each row in the solution array YOUT corresponds to a time returned in the column vector TOUT. To obtain solutions at specific times T0,T1,. ..,TFINAL (all increasing or all decreasing), use TSPAN = [T0 T1 . .. TFINAL]. Problem 1: The logistics equation is a simple differential equation model that can be used to relate the change in population dP/dt to the current population, P, given a growth rate, r, and a carrying capacity, K. The logistics equation can be expressed by: Write a function with header [dP] = myLogisticsEq(t, P, r, K) that represents the Logistics equation. Note that this format allows myLogisticsEq to be used as an input argument to ode45 . You may assume that the arguments dP , t , P , r , and K are all scalars, and dP is the value dP/dt given r , P , and K . Note that the input argument, t , is obligatory if myLogisticsEq is to be used as an input argument to ode45 , even though it is part of the differential equation. Note : The logistics equation has an analytic solution defined by: where P 0 is the initial population. As an exercise, you should verify that this equation is a solution to the logistics equation.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Engineering 7: Prof. Alexandre Bayen Introduction to Programming for Engineers Spring 2011 Test Cases: >> dP = myLogisticsEq(0, 10, 1.1, 15) dP = 3.6667 >> t0 = 0; tf = 20; P0 = 10; r = 1.1; K = 20; t = 0:.01:20; >> [T, P] = ode45(@myLogisticsEq, [t0 tf], P0, [], r, K); >> plot(T, P, t, K*P0*exp(r*t)./(K + P0*(exp(r*t) - 1))) >> title('Numerical and Analytic Solution of Logistic Equation') >> xlabel('time') >> ylabel('population') >> legend('Numerical Solution', 'Exact Solution') >> grid on >> axis tight 0 2 4 6 8 10 12 14 16 18 20 10 11 12 13 14 15 16 17 18 19 Numerical and Analytic Solution of Logistic Equation time population Numerical Solution Exact Solution
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 8

Lab11 - Engineering 7: Introduction to Programming for...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online