# Kreyszig: Example 1.3

Question: Suppose that you turn off your heat in your home 2 hours before you go to bed; call this time t=0. If the temperature T at t-0 is 66°F and at the time you go to bed (t=2) has dropped to 63°F, what temperature can you expect in the morning, say, 8 hours later (t=10)? Of course, this process of cooling off will depend on the outside temperature TA, which we assume to be constant at 32°F.

Solution:

dT/dt = k(T – TA)  = k(T – 32)

Solving the equation we get the equation with two constants, shown below

T(t) = k + c Exp(k*t)

We can solve for the constants using the following data from the question

1. T(0) = 66°F
2. T(2) = 63°F

and we finally get the equation

T(t) = 32 + 34 Exp(-0.046187 t)

In the next section, we will plot the equations and for various initial conditions and see how the plots change. We will be using Wolfram Mathematica for the calculations and the valuations

Simulation:

Step 01: Varying the outside temperature while keeping everything else constant. The family of the solutions for this set of conditions is plotted below. Step 02: Varying the T while keeping the outside temperature at 32°F. The family of the solutions for this set of conditions is plotted below. Code

I have used Mathematica 12 for simulation. The code from the notebook is given below.

```Module[{solutions, outsides, constants},
outsides = Range[0, 60, 2];
solutions =
Table[DSolve[{T'[t] == k (T[t] - outside), T == 66}, T[t], t][[1,
1, 2]], {outside, outsides}];
constants =
N[Solve[(# /. t -> 2) == 63 && k < 0, k]][[1, 1, 2]] & /@ solutions;
solutions = MapThread[#1 /. k -> #2 &, {solutions, constants}];
Plot[Evaluate[solutions], {t, 0, 200}, ImageSize -> 788,
AspectRatio -> 1, Frame -> True,
PlotLegends ->
Placed[("y = " <> ToString[#] <> "\[Degree]C" & /@ outsides),
Below], PlotLabel -> Style["y[t] vs. t", 20],
GridLines -> {Range[20, 200, 5], outsides},
FrameTicks -> {Range[20, 200, 5], outsides},
PlotRange -> {{0, 200}, {0, 70}}]
]

Module[{solutions, twoHourTemps = Range[33, 63, 1], constants},
solutions =
DSolve[{T'[t] == k (T[t] - 32), T == 66}, T[t], t][[1, 1, 2]];
constants =
N[Solve[(solutions /. t -> 2) == # && (k < 0 || k > 0), k]][[1, 1,
2]] & /@ twoHourTemps;
solutions = MapThread[solutions /. k -> # &, {constants}];
Plot[Evaluate[solutions], {t, 0, 200}, ImageSize -> 788,
AspectRatio -> 1, Frame -> True,
PlotLegends ->
Placed[("T = " <> ToString[#] <> "\[Degree]C" & /@
twoHourTemps), Below], PlotLabel -> Style["y[t] vs. t", 20],
GridLines -> {Range[20, 200, 5], twoHourTemps},
FrameTicks -> {Range[20, 200, 5], twoHourTemps},
PlotRange -> {{0, 200}, {0, 70}}]
]```

End of the post 🙂