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/chap16sympy.ipynb
Views: 531
Modeling and Simulation in Python
SymPy code for Chapter 16
Copyright 2017 Allen Downey
Mixing liquids
We can figure out the final temperature of a mixture by setting the total heat flow to zero and then solving for .
Analysis
We can use SymPy to solve the cooling differential equation.
Here's the general solution:
We can use the initial condition to solve for . First we evaluate the general solution at
Now we set and solve for
Then we plug the result into the general solution to get the particular solution:
We use a similar process to estimate based on the observation
Here's the particular solution evaluated at
Now we set and solve for
We can use evalf
to plug in numbers for the symbols. The result is a SymPy float, which we have to convert to a Python float.