MATH528Due date: 09/05/18

Homework 02 Solution

1Exercises

Exercise. PS1.4.1

Solution. 2x⁡y⁡dx+x2⁡dy is an exact differential

In[1]:=

df = 2 x y dx + x^2 dy

2⁢dxx⁢y+dyx2

In[4]:=

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

{2⁢x⁢y,x2}

In[5]:=

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

True

In[6]:=

Exercise. PS1.4.2

Solution. x3⁡dx+y3⁡dy 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. sin⁡x⁡cos⁡y⁡dx+cos⁡x⁡sin⁡y⁡dy 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+3r⁡dθ) 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⁢θ,3⁢r⁢e3⁢θ,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.2∫e-x⁡dx+c)=-5.2+c⁡ex.

Verify:

In[23]:=

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

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

c1⁢e1.⁢x-5.2

In[25]:=

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

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

In[26]:=

Exercise. PS1.5.4

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

y(x)=e2⁡x(-4∫x⁡e-2x⁡dx+c)=e2⁡x(2x⁡e-2x-⁡12∫e-2x⁡dx+c)=e2⁡x(2x⁡e-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]]

c1⁢e2⁢x-4⁢(-x2-14)

In[25]:=

Exercise. PS1.5.5

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

In[27]:=

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

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

c1⁢e-k⁢x+x⁢e-k⁢x

In[28]:=

Exercise. PS1.5.6

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

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]]]

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

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

{ d⁡Ydt=-r⁡Y Y(0)=240 .

with Y=T(t)-Tr, with solution Y(t)=240⁡e-r⁡t, or T(t)=240⁡e-r⁡t+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]]]

240⁢e-r⁢t+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]]

r→0.0538997

In[22]:=

Find time at which cake temperature reaches 61 degrees

In[22]:=

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

t→101.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-c⁢cos⁡(π⁢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+c⁢cos⁡(π⁢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+c⁢cos⁡(π⁢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-c⁢cos⁡(π⁢t12))-k2⁢Tw+P

In[5]:=

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

-A⁢k1-k2⁢Tw+Pk1+k2+B⁢e(k1+k2)⁢t-12⁢π⁢c⁢k1⁢sin⁡(π⁢t12)144⁢(k1+k2)2+π2+144⁢c⁢k1⁢(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-r⁡d

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+c1⁢e-r⁢t

In[7]:=

Problem. PS1.5.35 Lake Erie

Solution. Volume V=450⁡km3, flow rate Q=175⁡km3/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.01⁢e-0.388889⁢t⁢(3.+1.⁢e0.388889⁢t)

In[8]:=

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

{t→2.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'+p⁡y=r1+r2.

Proof. Compute y'+p⁡y=y1'+y2'+p(y1+y2)=(y1'+p⁡y1)+(y2'+p⁡y2)=r1+r2