Calculus - Florida Institute of Technologymy.fit.edu/~rvw/Lectures/Calculus 2005.pdfCalculus dN/dt =...

Preview:

Citation preview

CalculusCalculus

CalculusCalculus

dN/dtdN/dt = (= (bb--dd).N).NRate of change in population size with respect Rate of change in population size with respect to time.to time.Right side of equation is the product of the Right side of equation is the product of the population size N, multiplied by the difference population size N, multiplied by the difference between instantaneous births and deathsbetween instantaneous births and deaths

r = (r = (bb--dd), is the intrinsic rate of increase (or ), is the intrinsic rate of increase (or instantaneous growth rate. instantaneous growth rate.

dN/dtdN/dt = r. N,= r. N,

When r = 0, births and deaths are When r = 0, births and deaths are balanced, individuals merely replace balanced, individuals merely replace themselves.themselves.

LongLong--versionversionIntegrate Integrate dN/dtdN/dt = r. N,= r. N,First First dNdN = = r.Nr.N dtdt,,Then Then dNdN/N = r. /N = r. dtdtThen integrate, summing changes in population size over the inteThen integrate, summing changes in population size over the interval from rval from ttoo to t, to t, ln.N(t) – ln.N(to) = rt – rto

Rearrange againRearrange againexp exp ln.N(tln.N(t) ) –– ln.N(toln.N(to)) = = expexprtrt--rtorto

N(t)/N(toN(t)/N(to) = exp ) = exp rtrt--rtorto

If to = 0, then If to = 0, then N(tN(t) = ) = N(tN(too).).eertrt

or or

lnln N(tN(t) = ) = lnln N(tN(too) + ) + r.tr.t

CalculusCalculus

function ndot=expgrow(t,n);global r;ndot=r*n;

global r;r=0.5;[t,n]=ode23('expgrow',0:10,2);plot(t,n)

function dx= calculus(r,N)function dx= calculus(r,N)dx = r*N;dx = r*N;

fodesol('calculusfodesol('calculus', 0, 2, 0 , 10)', 0, 2, 0 , 10)

help fodesolhelp fodesol

function function fodesol(F,tmin,tmax,xmin,xmaxfodesol(F,tmin,tmax,xmin,xmax))

fodesol obtains an approximate solution to the ODEfodesol obtains an approximate solution to the ODEdx/dx/dtdt = = f(x,tf(x,t) by the ) by the RungeRunge--KuttaKutta--FehlbergFehlbergmethod ODE23 supplied with MATLAB (2nd/3rdmethod ODE23 supplied with MATLAB (2nd/3rdorder version) and compares the solutionsorder version) and compares the solutionswith a "grain" (or field) plot.with a "grain" (or field) plot.

F is a string containing the name of a realF is a string containing the name of a realfunction function f(x,tf(x,t), supplied in an M), supplied in an M--file.file.e.g. e.g. fnxt.mfnxt.m

tmin,tmaxtmin,tmax andandxmin,xmaxxmin,xmax are limits for the plotare limits for the plot

usage e.g.usage e.g.fodesol('fnxt',0, 2.5, fodesol('fnxt',0, 2.5, --3 , 3)3 , 3)

Pick initial tPick initial t--value: 0 value: 0 Pick initial xPick initial x--value: 2value: 2please wait...please wait...

Initial and final points (Initial and final points (t,xt,x) of solution were) of solution wereInitial FinalInitial Final0 20 2

2.0000 14.76392.0000 14.7639

function dx= calculus(r,N)function dx= calculus(r,N)global kglobal kdx = r*N*(kdx = r*N*(k--N/k);N/k);

The solution isThe solution is

X(tX(t) = K/(1) = K/(1--(1(1--K/xK/xoo).exp).exp--r.tr.t))

>> k= 2;>> k= 2;>> fodesol('calculus2',0,2,0,10)>> fodesol('calculus2',0,2,0,10)

The solution isThe solution is

X(tX(t) = K/(1) = K/(1--(1(1--K/xK/xoo).exp).exp--r.tr.t))

Pick initial tPick initial t--value: 0value: 0Pick initial xPick initial x--value: 1value: 1please wait...please wait...

Initial and final points (Initial and final points (t,xt,x) of solution were) of solution wereInitial FinalInitial Final0 20 2

1.0000 15.92181.0000 15.9218

ODE23 Solve nonODE23 Solve non--stiff differential stiff differential equations, low order method.equations, low order method.

[T,Y] = ODE23(ODEFUN,TSPAN,Y0) [T,Y] = ODE23(ODEFUN,TSPAN,Y0) with TSPAN = [T0 TFINAL] integrates thewith TSPAN = [T0 TFINAL] integrates the

system of differential equations y' = system of differential equations y' = f(t,yf(t,y) from time T0 to TFINAL with) from time T0 to TFINAL with

initial conditions Y0.initial conditions Y0.

Example Example [[t,yt,y]=]=ode23ode23(@vdp1,[0 20],[2 0]); (@vdp1,[0 20],[2 0]); plot(t,y(:,1));plot(t,y(:,1));

solves the system y' = vdp1(t,y), using the solves the system y' = vdp1(t,y), using the default relative errordefault relative error

tolerance 1etolerance 1e--3 and the default absolute 3 and the default absolute tolerance of 1etolerance of 1e--6 for each6 for each

component, and plots the first component of component, and plots the first component of the solution. the solution.

global r c D a k1 k2 k3global r c D a k1 k2 k3%copy above into command window%copy above into command windowr=0.4; c=0.05; D=0.05;r=0.4; c=0.05; D=0.05;k1=0.01; k2=0.01; k3 = 0.01;k1=0.01; k2=0.01; k3 = 0.01;a=0.1;a=0.1;%copy above into command window%copy above into command window[t a]=ode45('recruits', 0:0.1:50,[r;c;D]);[t a]=ode45('recruits', 0:0.1:50,[r;c;D]);h=figure; hold onh=figure; hold onplot(t,a(:,1),':')plot(t,a(:,1),':')plot(t,a(:,2),'plot(t,a(:,2),'--')')plot(t,a(:,3),'plot(t,a(:,3),'----')')axis([0 50 0 2])axis([0 50 0 2])xlabel('Timexlabel('Time (years)')(years)')ylabel('Instantaneousylabel('Instantaneous rate of change')rate of change')

function function ndotndot ==recruits(t,nrecruits(t,n))global r c D a k1 k2 k3;global r c D a k1 k2 k3;ndot(1,1) = ndot(1,1) = --k1*r + k2*D; k1*r + k2*D; ndot(2,1) = k1*r ndot(2,1) = k1*r -- k3*c/(1+a*c);k3*c/(1+a*c);ndot(3,1) = k3*c/(1+a*c) ndot(3,1) = k3*c/(1+a*c) -- k2*D;k2*D;

pdepepdepe

Partial differential equations…Partial differential equations…

Maybe another day…Maybe another day…

Recommended