Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/notebooks/chap15.ipynb
Views: 531
Modeling and Simulation in Python
Chapter 15
Copyright 2017 Allen Downey
The coffee cooling problem
I'll use a State
object to store the initial temperature.
And a System
object to contain the system parameters.
The update function implements Newton's law of cooling.
Here's how it works.
Here's a version of run_simulation
that uses linrange
to make an array of time steps.
And here's how it works.
Here's what the results look like.
And here's the final temperature:
Encapsulation
Before we go on, let's define a function to initialize System
objects with relevant parameters:
Here's how we use it:
Exercises
Exercise: Simulate the temperature of 50 mL of milk with a starting temperature of 5 degC, in a vessel with the same insulation, for 15 minutes, and plot the results.
By trial and error, find a value for r
that makes the final temperature close to 20 C.