MATH528Due date: 09/05/18

Homework 02 Solution

1Exercises

Exercise. PS1.4.1

Solution. 2xydx+x2dy is an exact differential

In[1]:=

df = 2 x y dx + x^2 dy

2dxxy+dyx2

In[4]:=

{P[x_,y_],Q[x_,y_]} = {Coefficient[df,dx,1],Coefficient[df,dy,1]}

{2xy,x2}

In[5]:=

ExactDF = D[P[x,y],y] == D[Q[x,y],x]

True

In[6]:=

Exercise. PS1.4.2

Solution. x3dx+y3dy is an exact differential

In[6]:=

df = x^3 dx + y^3 dy;

{P[x_,y_],Q[x_,y_]} = {Coefficient[df,dx,1],Coefficient[df,dy,1]};

ExactDF = D[P[x,y],y] == D[Q[x,y],x];

{P[x,y],Q[x,y],ExactDF}

{x3,y3,True}

In[7]:=

Exercise. PS1.4.3

Solution. sinxcosydx+cosxsinydy is an exact differential

In[7]:=

df = Sin[x] Cos[y] dx + Cos[x] Sin[y] dy;

{P[x_,y_],Q[x_,y_]} = {Coefficient[df,dx,1],Coefficient[df,dy,1]};

ExactDF = D[P[x,y],y] == D[Q[x,y],x];

{P[x,y],Q[x,y],ExactDF}

{sin(x)cos(y),cos(x)sin(y),True}

In[8]:=

Exercise. PS1.4.4

Solution. e3θ(dr+3rdθ) is an exact differential

In[8]:=

df = Exp[3y](dx + 3x dy);

{P[x_,y_],Q[x_,y_]} = {Coefficient[df,dx,1],Coefficient[df,dy,1]};

ExactDF = D[P[x,y],y] == D[Q[x,y],x];

{P[x,y],Q[x,y],ExactDF} /. {x->r, y->theta}

{e3θ,3re3θ,True}

In[9]:=

Exercise. PS1.5.3

Solution. y'-y=5.2 is a linear, first-order ODE of form y'+p(x)y=r(x), with p(x)=-1, r(x)=5.2, and general solution

y(x)=e-h(x)(eh(x)r(x)dx+c),h=p(x)dx,

which gives

h(x)=-x
y(x)=ex(5.2e-xdx+c)=-5.2+cex.

Verify:

In[23]:=

ODE = y'[x] - y[x] == 5.2;

sol[t] = y[x] /. DSolve[ODE,y[x],x][[1,1]]

c1e1.x-5.2

In[25]:=

Integrate[-4 x Exp[-2x],x]

-4e-2x(-x2-14)

In[26]:=

Exercise. PS1.5.4

Solution. y'=2y-4x, linear ODE with p(x)=-2, r(x)=-4x, h(x)=-2x

y(x)=e2x(-4xe-2xdx+c)=e2x(2xe-2x-12e-2xdx+c)=e2x(2xe-2x+e-2x+c),

by integration by parts. Verify:

In[24]:=

ODE = y'[x] == 2y[x] -4x;

sol[t] = y[x] /. DSolve[ODE,y[x],x][[1,1]]

c1e2x-4(-x2-14)

In[25]:=

Exercise. PS1.5.5

Solution. y'+ky=e-kx, linear ODE with p(x)=k, r(x)=e-kx

In[27]:=

ODE = y'[x] + k y[x] == Exp[-k x];

sol[t] = y[x] /. DSolve[ODE,y[x],x][[1,1]]

c1e-kx+xe-kx

In[28]:=

Exercise. PS1.5.6

Solution. y'+2y=4cos2x, y(π/4)=3, is a linear ODE with p(x)=2, r(x)=4cos2x

In[29]:=

ODE = y'[x] + 2 y[x] == 4 Cos[2x];

iCond = y[Pi/4]==3;

sol[t] = Expand[y[x] /. DSolve[{ODE,iCond},y[x],x][[1,1]]]

2eπ2-2x+sin(2x)+cos(2x)

In[30]:=

2Problems

Problem. PS1.5.31 Newton's law of cooling

Solution. Assume cooling rate is proportional to temperature difference T(t)-Tr, with time denoted by t and Tr the room temperature. The problem can be formulated as

{ dTdt=-r(T-Tr) T(0)=300 .

and also written

{ dYdt=-rY Y(0)=240 .

with Y=T(t)-Tr, with solution Y(t)=240e-rt, or T(t)=240e-rt+60

In[20]:=

ODE = T'[t] == -r (T[t]-60);

sol[t_] = Expand[T[t] /. DSolve[{ODE,T[0]==300},T[t],t][[1,1]]]

240e-rt+60

In[21]:=

Find the decay rate r by imposing the condition T(10)=200

In[21]:=

rsol = FindRoot[sol[10.] == 200., {r,0.1}][[1]]

r0.0538997

In[22]:=

Find time at which cake temperature reaches 61 degrees

In[22]:=

tsol = FindRoot[sol[t]==61 /. rsol,{t,20}][[1]]

t101.682

In[23]:=

Verify the solution

In[14]:=

sol[t] /. {rsol,tsol}

61.

Problem. PS1.5.32 Heating and cooling of a building

Solution. Define the ODE and solve

In[1]:=

Ta[t_] = A - c Cos[2 Pi t/24]

A-ccos(πt12)

In[2]:=

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

T'(t)=k1(-A+ccos(πt12)+T(t))+k2(T(t)-Tw)+P

In[3]:=

The above is a linear ODE of form T'+p(t)T=r(t), with

p(t)=-(k1+k2),r(t)=k1(-A+ccos(πt12))-k2Tω+P

The general solution is

T(t)=e-h(t)(eh(t)r(t)dt+B),h=p(t)dt=-(k1+k2)t.

In[3]:=

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

(k1+k2)(-t)

In[4]:=

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

k1(A-ccos(πt12))-k2Tw+P

In[5]:=

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

-Ak1-k2Tw+Pk1+k2+Be(k1+k2)t-12πck1sin(πt12)144(k1+k2)2+π2+144ck1(k1+k2)cos(πt12)144(k1+k2)2+π2

In[6]:=

The above terms are, in order:

  1. temperature balance between ambient, wanted, occupant temperatures

  2. decay of initial temperature

  3. 4. variation due to change in ambient temperature

A more detailed investigation is presented in mLab03.

Problem. PS1.5.33 Drug injection

Solution. Let d(t) be the amount of drug in the bloodstream. The model is written as

d'=A-rd

with A the injection rate and r the removal rate per unit of drug in bloodstream. This is a linear ODE

In[6]:=

ODE = d'[t] == A - r d[t];

sol[t] = d[t] /. DSolve[ODE,d[t],t][[1,1]]

Ar+c1e-rt

In[7]:=

Problem. PS1.5.35 Lake Erie

Solution. Volume V=450km3, flow rate Q=175km3/year (in and out). Let p(t) denote pollution concentration, with p(0)=0.04. The inflow pollution is p1=p(0)/4=0.01. The model is

p'=QV(p1-p),p(0)=0.04.

In[7]:=

V=450; Q=175; p0=0.04; p1=p0/4; ODE = p'[t] == Q/V (p1-p[t]); iCond = p[0]==p0;

sol[t] = p[t] /. DSolve[{ODE,iCond},p[t],t][[1,1]]

0.01e-0.388889t(3.+1.e0.388889t)

In[8]:=

FindRoot[sol[t]==p0/2,{t,1}]

{t2.825}

In[10]:=

2.825*175

494.375

In[11]:=

3Projects

3.1PS2.1.16

The sum y=y1+y2 is a solution of y'+py=r1+r2.

Proof. Compute y'+py=y1'+y2'+p(y1+y2)=(y1'+py1)+(y2'+py2)=r1+r2