MATH528 mLab03: Investigating ODE models

First-order linear ODE models

Heating and cooling of a building (PS1.5.32)

Building ambient temperature

(Subscript[T, a])[t_]=A-c Cos[2 Pi t/24]

Rate of change of temperature in building

ODE=T'[t]==(Subscript[k, 1]) (T[t]-(Subscript[T, a])[t])+ (Subscript[k, 2]) (T[t]-(Subscript[T, w]))+P

h[t_] = -((Subscript[k, 1])+(Subscript[k, 2]))t

r[t_]=(Subscript[k, 1]) (Subscript[T, a])[t]- (Subscript[k, 2])(Subscript[T, w])+P

TGenSol[t_]=FullSimplify[Exp[-h[t]](Integrate[Exp[h[t]] r[t],t]+B)]

TGenSol[0]

Bsol=Solve[TGenSol[0]==(Subscript[T, 0]),B][[1,1]]

T[t_] = FullSimplify[TGenSol[t] /. Bsol]

T[0]

Manipulate[T[t] /. {(Subscript[T, 0])->T0},{T0,65,75}]

Manipulate[T[t] /. {(Subscript[T, 0])->T0,(Subscript[T, w])->Tw},{T0,45,95},{Tw,65,72}]

Manipulate[T[t] /. {(Subscript[T, 0])->T0,(Subscript[T, w])->Tw,(Subscript[k, 1])->k1,(Subscript[k, 2])->k2,P->Pval,A->Aval,c->cval},{T0,65,75},{Tw,65,72},{k1,-1,-0.1},{k2,-10,-1},{Pval,1,10},{Aval,0,100},{cval,20,40}]

Manipulate[
Plot[T[t] /. {(Subscript[T, 0])->T0,(Subscript[T, w])->Tw,(Subscript[k, 1])->k1,(Subscript[k, 2])->k2,P->Pval,A->Aval,c->cval},{t,0,24},
Axes->False,Frame->True,FrameLabel->{"time (hrs)","Temperature (F)"},GridLines->Automatic,PlotLabel->"Building heating/cooling",PlotRange->{{0,24},{50,90}}],
{T0,65,75},{Tw,65,72},{k1,-1,-0.1},{k2,-10,-1},{Pval,1,10},{Aval,0,100},{cval,20,40}]

Continual harvesting of renewable resources (PS1.5.36)

Logistic equation model

ODE = y'[t] == (A-H) y[t] - B ((y[t])^2)

iCond = y[0]==y0

sol[t_,A_,B_,H_,y0_] = FullSimplify[y[t] /. DSolve[{ODE,iCond},y[t],t][[1,1]]]

sol[0]

Manipulate[Plot[sol[t,A,B,H,y0],{t,0,10},PlotRange->{{0,10},{0,100}},Axes->False,Frame->True,FrameLabel->{"Time","Resource"},GridLines->Automatic,PlotLabel->"Harvesting renewable resources"] ,{H,0.1,A},{A,1,10},{B,0.1,2},{y0,1,100}]

Intermittent harvesting renewable resources (PS1.5.36-38)

The step function HeavisidePi is useful for this problem.  Here’s a plot. Notice the scaling of the argument to obtain the desired 3-year harvesting period.

Plot[HeavisidePi[t/3-.5],{t,-1,4}]

Now, construct a sum of HeavisidePi step functions to cover a time span of 30 years

Hi[t_] = Sum [HeavisidePi[t/3-.5-k],{k,0,9,2}]

Plot[Hi[t],{t,-3,33}]

Redefine the ODE to model intermittent harvesting

ODE = y'[t] == (A-H Hi[t]) y[t] - B ((y[t])^2)

iCond = y[0]==y0

Analytical solution, though possible, is exceedingly complicated. A numerical solution is readily obtainable

soli[t_,Av_,Bv_,Hv_,y0v_] := y[t] /. NDSolve[{ODE,iCond} /. {A->Av, B->Bv, H->Hv, y0->y0v} ,y[t],{t,0,30}][[1,1]]

The numerical solution is represented by an interpolation

soli[t,3.,10.,1.,5.]

Plot[Evaluate[soli[t,3.,10.,1.,5.]],{t,0,30}]

Manipulate[Plot[{Evaluate[soli[t,A,B,H,y0]],sol[t,A,B,H,y0]},{t,0,30},PlotRange->{{0,30},{0,25}},Axes->False,Frame->True,FrameLabel->{"Time","Resource"},GridLines->Automatic,PlotStyle->{Black,Red},PlotLabel->"Harvesting renewable resources"] ,{H,0.1,A},{A,1,10},{B,0.05,1},{{y0,10},0,25}]