Here we'll present Mathematica code from Appendix B of Mathematical Models in the Biosciences, 1 by Michael Frame, Yale University Press, 2020. Explanations for the code, and what the code is written to do, can be found in that volume.
Copy the text inside the box, paste it into Mathematica, and evaluate the cell.
B.1 Cycles and their stability. | ||||||
|
B.2 Chaos. | |||||||||
This computes a numerical approximation to the Liapunov exponent. | |||||||||
| |||||||||
Here is code to generate iterates of f and count the number ct1 and ct2 of times the iterates land in
the interval | |||||||||
|
B.3 A simple cardiac model. | ||||
|
B.4 The Norton-Simon model. | ||||
|
B.5 Log-log plots. | ||||
Paste your own data between the brackets of xlst={}; | ||||
|
B.6 Vector fields and trajectories. | |||
Paste your own vector field after | |||
|
B.7 Differential equations software. | |||||||
First, we plot the nullclines. Paste your own vector field after | |||||||
| |||||||
Now we'll superimpose a plot of a trajectory and a plot of the vector field. In this
example the vector field is | |||||||
|
B.8 Predator-prey models. | ||||||
First, generate the solution. | ||||||
| ||||||
Now plot the x(t) and y(t) curves, | ||||||
| ||||||
and plot the trajectory (x(t), y(t))). | ||||||
|
B.9 The Fitzhugh-Nagumo equations. | |||||
The square pulse function is defined by | |||||
| |||||
To solve the Fitzhugh-Nagumo equations, use this code. Modify the parameter values as you wish. | |||||
| |||||
To plot the population curves in a single graph use this code. | |||||
| |||||
and to plot the trajectory use | |||||
|
B.10 Eigenvalues and eigenvectors. | |||
To find the eigenvalues and eigenvectors of the matrix m, entered in this example as a list of lists, use these commands. Enter your own matrix, of coure. | |||
|
 
Here we'll present Mathematica code from Appendix B of Mathematical Models in the Biosciences, 2 by Michael Frame, Yale University Press, 2021. Explanations for the code, and what the code is written to do, can be found in that volume.
B.11 Eigenvalues in higher dimensions. | |||
We can find eigenvalues of any square matrix. But while for | |||
|
B.12 SIR calculations. | ||||||
First, generate the solution with this code. | ||||||
| ||||||
To plot the three population curves on the same graph, use | ||||||
| ||||||
and to plot the trajectory use | ||||||
|
B.13 Michaelis-Menten calculations. | ||||||
We generate the solution with this code | ||||||
| ||||||
To plot the four population curves individually, use | ||||||
| ||||||
To plot the four population curves on the same graph, use | ||||||
|
B.14 Virus dynamics. | |||||||
We generate the solution with this code. | |||||||
| |||||||
To plot the w and z curves in the same graph, use this code. | |||||||
|
B.15 Immune system dynamics. | ||||||||
We generate the solution with this code. | ||||||||
| ||||||||
To plot the y and w curves in the same graph, use this code. | ||||||||
|
B.16 The Hodgkin-Huxley equations. | |||||||||||||||||||||||||
We'll plot trajectories, find the nullclines, and locate the fixed points. First, generate two solutions with slightly different initial points. | |||||||||||||||||||||||||
| |||||||||||||||||||||||||
To plot the (m(t), V(t)) trajectories for both solutions, use | |||||||||||||||||||||||||
| |||||||||||||||||||||||||
To plot the m and V nullclines, use | |||||||||||||||||||||||||
| |||||||||||||||||||||||||
Code to generate periodic rectangular pulses | |||||||||||||||||||||||||
| |||||||||||||||||||||||||
To find approximate coordinates of the fixed points, use | |||||||||||||||||||||||||
|
B.17 Chaos in predator-prey models. | |||||||
First, generate a solution with this code. | |||||||
| |||||||
To plot the trajectory in 3 dimensions, use this code. | |||||||
|
B.18 The Duffing equation. | |||||||||||
First we'll generate solutions for two slightly different initial points. | |||||||||||
| |||||||||||
To plot the x(t) curves for both systems, use | |||||||||||
| |||||||||||
To plot the differences of the x(t) curves, use | |||||||||||
|
B.19 Control of chaos. | ||||||||||||||
Here are codes to generate two figures from this section. | ||||||||||||||
| ||||||||||||||
|
B.20 Sensitivity analysis. | |
Probably this one you don't need to copy and paste this. | |
|
B.21 The Clancy-Rudy models. | ||||||
Run these bits of code in the order presented. | ||||||
| ||||||
Now we generate the cumulative probability matrix. | ||||||
| ||||||
Start with a random state. Initialize the list of states. Initialize the state counters ot 0. | ||||||
| ||||||
Next we generate a sequence of random numbers, and based on the current state and the cumulative probability matrix, determine the next state and augment the appropriate state counter. This may take a few moments to run. | ||||||
| ||||||
Finally, to compare the counts with the fractions calculated in Practice Problem 16.4.1 (b) use this command. | ||||||
|
B.22 A genetic toggle switch | |||||||
Here is code to plot the curves | |||||||
|
B.23 Transcription networks. | ||||||||
|
B.24 Topological methods | ||||||||||||||||||||||
First, symbol-driven IFS. Paste a sequence of c, t, g, and a between the brackets of dlst = {}; | ||||||||||||||||||||||
| ||||||||||||||||||||||
Here is code to plot the driven IFS for numerical data, entered in as comma-separated numbers in dlst, and to calculate the address occupancies. | ||||||||||||||||||||||
For equal-size bins the bin boundaries are | ||||||||||||||||||||||
| ||||||||||||||||||||||
For equal-size bins the bin boundaries are | ||||||||||||||||||||||
| ||||||||||||||||||||||
For median-centered bins with parameter d the bin boundaries are | ||||||||||||||||||||||
| ||||||||||||||||||||||
Paste the choice of bin boundaries immediately after the dlst = {}; line. | ||||||||||||||||||||||
To generate the driven IFS image use this code. | ||||||||||||||||||||||
| ||||||||||||||||||||||
To find the number of points with address 124, for example, after the program has run use the command | ||||||||||||||||||||||
|