Skip to content

Commit 15955d7

Browse files
committed
Updating examples
1 parent 820b280 commit 15955d7

16 files changed

Lines changed: 142 additions & 150 deletions

‎examples/bungee1.ipynb‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,19 @@
8383
"\n",
8484
"3. After the cord is fully extended, it obeys [Hooke's Law](https://en.wikipedia.org/wiki/Hooke%27s_law); that is, it applies a force to the jumper proportional to the extension of the cord beyond its resting length.\n",
8585
"\n",
86-
"4. The jumper is subject to drag force proportional to the square of their velocity, in the opposite of their direction of motion.\n",
86+
"4. The jumper is subject to drag force proportional to the square of their velocity, opposite to their direction of motion.\n",
8787
"\n",
8888
"Our objective is to choose the length of the cord, `L`, and its spring constant, `k`, so that the jumper falls all the way to the tea cup, but no farther! \n",
8989
"\n",
90-
"First I'll create a `Param` object to contain the quantities we'll need:\n",
90+
"First I'll create a `Params` object to contain the quantities we'll need:\n",
9191
"\n",
9292
"1. Let's assume that the jumper's mass is 75 kg.\n",
9393
"\n",
94-
"2. With a terminal velocity of 60 m/s.\n",
94+
"2. Let's assume the jumper's terminal velocity is 60 m/s.\n",
9595
"\n",
96-
"3. The length of the bungee cord is `L = 40 m`.\n",
96+
"3. The length of the bungee cord is `L = 25 m`.\n",
9797
"\n",
98-
"4. The spring constant of the cord is `k = 20 N / m` when the cord is stretched, and 0 when it's compressed.\n"
98+
"4. The spring constant of the cord is `k = 40 N / m` when the cord is stretched, and 0 when it's compressed.\n"
9999
]
100100
},
101101
{
@@ -155,7 +155,7 @@
155155
"cell_type": "markdown",
156156
"metadata": {},
157157
"source": [
158-
"Let's make a `System`"
158+
"Let's make a `System`."
159159
]
160160
},
161161
{
@@ -173,7 +173,7 @@
173173
"source": [
174174
"`spring_force` computes the force of the cord on the jumper.\n",
175175
"\n",
176-
"If the spring is not extended, it returns `zero_force`, which is either 0 Newtons or 0, depending on whether the `System` object has units. I did that so the slope function works correctly with and without units."
176+
"If the cord is not extended, it returns 0."
177177
]
178178
},
179179
{
@@ -187,7 +187,7 @@
187187
" \n",
188188
" y: height of the jumper\n",
189189
" \n",
190-
" Uses these variables from system|\n",
190+
" Uses these variables from system:\n",
191191
" y_attach: height of the attachment point\n",
192192
" L: resting length of the cord\n",
193193
" k: spring constant of the cord\n",
@@ -390,7 +390,7 @@
390390
"cell_type": "markdown",
391391
"metadata": {},
392392
"source": [
393-
"After reaching the lowest point, the jumper springs back almost to almost 70 m and oscillates several times. That looks like more oscillation that we expect from an actual jump, which suggests that there is some dissipation of energy in the real world that is not captured in our model. To improve the model, that might be a good thing to investigate.\n",
393+
"After reaching the lowest point, the jumper springs back almost to 70 m and oscillates several times. That looks like more oscillation than we expect from an actual jump, which suggests that there is some dissipation of energy in the real world that is not captured in our model. To improve the model, that might be a good thing to investigate.\n",
394394
"\n",
395395
"But since we are primarily interested in the initial descent, the model might be good enough for now.\n",
396396
"\n",
@@ -450,7 +450,7 @@
450450
"source": [
451451
"Although we compute acceleration inside the slope function, we don't get acceleration as a result from `run_solve_ivp`.\n",
452452
"\n",
453-
"We can approximate it by computing the numerical derivative of `ys`:"
453+
"We can approximate it by computing the numerical derivative of `results.v`:"
454454
]
455455
},
456456
{
@@ -561,7 +561,7 @@
561561
"metadata": {},
562562
"outputs": [],
563563
"source": [
564-
"event_func.direction = 10"
564+
"event_func.direction = 1"
565565
]
566566
},
567567
{

‎examples/bungee2.ipynb‎

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,13 @@
9191
"\n",
9292
"3. After the cord is fully extended, it obeys [Hooke's Law](https://en.wikipedia.org/wiki/Hooke%27s_law); that is, it applies a force to the jumper proportional to the extension of the cord beyond its resting length.\n",
9393
"\n",
94-
"4. The jumper is subject to drag force proportional to the square of their velocity, in the opposite of their direction of motion.\n",
94+
"4. The jumper is subject to drag force proportional to the square of their velocity, opposite to their direction of motion.\n",
9595
"\n",
96-
"First I'll create a `Param` object to contain the quantities we'll need:\n",
96+
"First I'll create a `Params` object to contain the quantities we'll need:\n",
9797
"\n",
9898
"1. Let's assume that the jumper's mass is 75 kg and the cord's mass is also 75 kg, so `mu=1`.\n",
9999
"\n",
100-
"2. The jumpers's frontal area is 1 square meter, and terminal velocity is 60 m/s. I'll use these values to back out the coefficient of drag.\n",
100+
"2. The jumper's frontal area is 1 square meter, and terminal velocity is 60 m/s. I'll use these values to back out the coefficient of drag.\n",
101101
"\n",
102102
"3. The length of the bungee cord is `L = 25 m`.\n",
103103
"\n",
@@ -168,7 +168,7 @@
168168
"cell_type": "markdown",
169169
"metadata": {},
170170
"source": [
171-
"Let's make a `System`"
171+
"Let's make a `System`."
172172
]
173173
},
174174
{
@@ -238,12 +238,12 @@
238238
"outputs": [],
239239
"source": [
240240
"def cord_acc(y, v, system):\n",
241-
" \"\"\"Computes the force of the bungee cord on the jumper:\n",
241+
" \"\"\"Computes the acceleration of the jumper due to the cord.\n",
242242
" \n",
243243
" y: height of the jumper\n",
244-
" v: velocity of the jumpter\n",
244+
" v: velocity of the jumper\n",
245245
" \n",
246-
" returns: acceleration in m/s\n",
246+
" returns: acceleration in m/s**2\n",
247247
" \"\"\"\n",
248248
" L, mu = system.L, system.mu\n",
249249
" \n",
@@ -487,7 +487,7 @@
487487
"metadata": {},
488488
"outputs": [],
489489
"source": [
490-
"spring_force(56, system1)"
490+
"spring_force(54, system1)"
491491
]
492492
},
493493
{
@@ -570,7 +570,7 @@
570570
"cell_type": "markdown",
571571
"metadata": {},
572572
"source": [
573-
"Here's how we run Phase 2, setting the direction of the event function so it doesn't stop the simulation immediately. "
573+
"Here's how we run Phase 2."
574574
]
575575
},
576576
{
@@ -635,7 +635,7 @@
635635
},
636636
{
637637
"cell_type": "code",
638-
"execution_count": 33,
638+
"execution_count": 29,
639639
"metadata": {},
640640
"outputs": [],
641641
"source": [
@@ -660,7 +660,7 @@
660660
},
661661
{
662662
"cell_type": "code",
663-
"execution_count": 34,
663+
"execution_count": 30,
664664
"metadata": {},
665665
"outputs": [],
666666
"source": [
@@ -669,7 +669,7 @@
669669
},
670670
{
671671
"cell_type": "code",
672-
"execution_count": 35,
672+
"execution_count": 31,
673673
"metadata": {},
674674
"outputs": [],
675675
"source": [
@@ -678,7 +678,7 @@
678678
},
679679
{
680680
"cell_type": "code",
681-
"execution_count": 36,
681+
"execution_count": 32,
682682
"metadata": {},
683683
"outputs": [],
684684
"source": [
@@ -688,7 +688,7 @@
688688
},
689689
{
690690
"cell_type": "code",
691-
"execution_count": 37,
691+
"execution_count": 33,
692692
"metadata": {
693693
"scrolled": true
694694
},
@@ -700,7 +700,7 @@
700700
},
701701
{
702702
"cell_type": "code",
703-
"execution_count": 38,
703+
"execution_count": 34,
704704
"metadata": {},
705705
"outputs": [],
706706
"source": [
@@ -709,7 +709,7 @@
709709
},
710710
{
711711
"cell_type": "code",
712-
"execution_count": 39,
712+
"execution_count": 35,
713713
"metadata": {},
714714
"outputs": [],
715715
"source": [
@@ -748,7 +748,7 @@
748748
"name": "python",
749749
"nbconvert_exporter": "python",
750750
"pygments_lexer": "ipython3",
751-
"version": "3.10.13"
751+
"version": "3.13.11"
752752
}
753753
},
754754
"nbformat": 4,

‎examples/filter.ipynb‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
"\n",
7878
"![Circuit diagram of a low-pass filter](https://github.com/AllenDowney/ModSim/raw/main/figs/Lowpass_Filter_RC.png)\n",
7979
"\n",
80-
"A \"filter\" is a circuit takes a signal, $V_{in}$, as input and produces a signal, $V_{out}$, as output. In this context, a \"signal\" is a voltage that changes over time.\n",
80+
"A \"filter\" is a circuit that takes a signal, $V_{in}$, as input and produces a signal, $V_{out}$, as output. In this context, a \"signal\" is a voltage that changes over time.\n",
8181
"\n",
8282
"A filter is \"low-pass\" if it allows low-frequency signals to pass from $V_{in}$ to $V_{out}$ unchanged, but it reduces the amplitude of high-frequency signals.\n",
8383
"\n",
@@ -116,7 +116,7 @@
116116
"source": [
117117
"## Params and System objects\n",
118118
"\n",
119-
"Here's a `Params` object to contain the quantities we need. I've chosen values for `R1` and `C1` that might be typical for a circuit that works with audio signal."
119+
"Here's a `Params` object to contain the quantities we need. I've chosen values for `R1` and `C1` that might be typical for a circuit that works with audio signals."
120120
]
121121
},
122122
{
@@ -138,11 +138,11 @@
138138
"cell_type": "markdown",
139139
"metadata": {},
140140
"source": [
141-
"Now we can pass the `Params` object `make_system` which computes some additional parameters and defines `init`.\n",
141+
"Now we can pass the `Params` object to `make_system`, which computes some additional parameters and defines `init`.\n",
142142
"\n",
143143
"* `omega` is the frequency of the input signal in radians/second.\n",
144144
"\n",
145-
"* `tau` is the time constant for this circuit, which is the time it takes to get from an initial startup phase to \n",
145+
"* `tau` is the time constant for this circuit, which determines how long the initial startup phase lasts.\n",
146146
"\n",
147147
"* `cutoff` is the cutoff frequency for this circuit (in Hz), which marks the transition from low frequency signals, which pass through the filter unchanged, to high frequency signals, which are attenuated.\n",
148148
"\n",
@@ -183,7 +183,7 @@
183183
"cell_type": "markdown",
184184
"metadata": {},
185185
"source": [
186-
"Let's make a `System`"
186+
"Let's make a `System`."
187187
]
188188
},
189189
{
@@ -239,7 +239,7 @@
239239
"cell_type": "markdown",
240240
"metadata": {},
241241
"source": [
242-
"And then run the simulation. I suggest using `t_eval=ts` to make sure we have enough data points to plot and analyze the results. "
242+
"And then run the simulation."
243243
]
244244
},
245245
{
@@ -519,7 +519,7 @@
519519
"source": [
520520
"## Estimating phase offset\n",
521521
"\n",
522-
"The delay between the peak of the input and the peak of the output is call a \"phase shift\" or \"phase offset\", usually measured in fractions of a cycle, degrees, or radians.\n",
522+
"The delay between the peak of the input and the peak of the output is called a \"phase shift\" or \"phase offset\", usually measured in fractions of a cycle, degrees, or radians.\n",
523523
"\n",
524524
"To estimate the phase offset between two signals, we can use cross-correlation. Here's what the cross-correlation looks like between `V_out` and `V_in`:"
525525
]
@@ -788,7 +788,7 @@
788788
"cell_type": "markdown",
789789
"metadata": {},
790790
"source": [
791-
"For low frequencies, the phase offset is near 0. For high frequencies, it approaches 90 degrees."
791+
"For low frequencies, the phase offset is near 0. For high frequencies, it approaches -90 degrees."
792792
]
793793
},
794794
{
@@ -805,7 +805,7 @@
805805
"\n",
806806
"$ \\phi = \\arctan (- R C \\omega)$ \n",
807807
"\n",
808-
"**Exercise:** Write functions that take an array of input frequencies and returns $A(f)$ and $\\phi(f)$ as `SweepSeries` objects. Plot these objects and compare them with the results from the previous section.\n"
808+
"**Exercise:** Write functions that take an array of input frequencies and return $A(f)$ and $\\phi(f)$ as `SweepSeries` objects. Plot these objects and compare them with the results from the previous section.\n"
809809
]
810810
},
811811
{

‎examples/glucose.ipynb‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@
5757
"cell_type": "markdown",
5858
"metadata": {},
5959
"source": [
60-
"In the previous chapter we implemented the glucose minimal model using given parameters, but I didn't say where those parameters came from.\n",
60+
"In Chapter 18 we implemented the glucose minimal model using given parameters, but I didn't say where those parameters came from.\n",
6161
"This notebook solves the mystery.\n",
6262
"\n",
6363
"We'll use a SciPy function called `leastsq`, which stands for \"least squares\"; that is, it finds the parameters that minimize the sum of squared differences between the results of the model and the data.\n",
6464
"\n",
6565
"You can think of `leastsq` as optional material. We won't use it in the book itself, but it appears in a few of the case studies.\n",
6666
"\n",
67-
"You can read more about `leastsq` in [the SciPy documentation](https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.leastsq.html). It uses the Levenberg-Marquart algorithm, which you can read about [on Wikipedia](https://en.wikipedia.org/wiki/Levenberg%E2%80%93Marquardt_algorithm)."
67+
"You can read more about `leastsq` in [the SciPy documentation](https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.leastsq.html). It uses the Levenberg–Marquardt algorithm, which you can read about [on Wikipedia](https://en.wikipedia.org/wiki/Levenberg%E2%80%93Marquardt_algorithm)."
6868
]
6969
},
7070
{
@@ -190,7 +190,7 @@
190190
"cell_type": "markdown",
191191
"metadata": {},
192192
"source": [
193-
"Because we specify `t_eval=data.index`, the results are evaluated at the some time stamps as the data."
193+
"Because we specify `t_eval=data.index`, the results are evaluated at the same timestamps as the data."
194194
]
195195
},
196196
{
@@ -298,7 +298,7 @@
298298
"\n",
299299
"But notice that it does not return all of the errors; rather, it uses `iloc` to select only the elements with index 3 or more.\n",
300300
"In other words, it omits the elements with index 0, 1, and 2.\n",
301-
"Note: You can read more about this use of `iloc` [in the Pandas documentation](https://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-integer).\n",
301+
"Note: You can read more about this use of `iloc` [in the Pandas documentation](https://pandas.pydata.org/docs/user_guide/indexing.html#selection-by-position).\n",
302302
"\n",
303303
"Since we don't expect the model to fit the data in this regime, we'll leave it out.\n",
304304
"\n",
@@ -407,7 +407,7 @@
407407
"outputs": [],
408408
"source": [
409409
"data.glucose.plot(style='o', alpha=0.5, label='data')\n",
410-
"results.G.plot(style='-', color='C0', label='model')\n",
410+
"results2.G.plot(style='-', color='C0', label='model')\n",
411411
"\n",
412412
"decorate(xlabel='Time (min)',\n",
413413
" ylabel='Concentration (mg/dL)')"
@@ -622,7 +622,7 @@
622622
"name": "python",
623623
"nbconvert_exporter": "python",
624624
"pygments_lexer": "ipython3",
625-
"version": "3.10.13"
625+
"version": "3.13.11"
626626
}
627627
},
628628
"nbformat": 4,

‎examples/hiv_model.ipynb‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
"The most obvious explanation for the decline is an immune response that destroys the virus or controls its replication.\n",
7878
"However, at least in some patients, the decline occurs even without any detectable immune response.\n",
7979
"\n",
80-
"In 1996 Andrew Phillips proposed another explanation for the decline (\"Reduction of HIV Concentration During Acute Infection: Independence from a Specific Immune Response\", available from <https://people.math.gatech.edu/~weiss/uploads/5/8/6/1/58618765/phillips1996.pdf>).\n",
80+
"In 1996 Andrew Phillips proposed another explanation for the decline (\"Reduction of HIV Concentration During Acute Infection: Independence from a Specific Immune Response\", *Science*, 1996, available from <https://doi.org/10.1126/science.271.5248.497>).\n",
8181
"\n",
8282
"Phillips presents a system of differential equations that models the concentrations of the HIV virus and the CD4 cells it infects.\n",
8383
"The model does not include an immune response; nevertheless, it demonstrates behavior that is qualitatively similar to what is seen in patients during the first few weeks after infection.\n",
@@ -95,7 +95,7 @@
9595
"\n",
9696
"The model has four state variables, `R`, `L`, `E`, and `V`. Read the paper to understand what they represent.\n",
9797
"\n",
98-
"Here are the initial conditional we can glean from the paper. "
98+
"Here are the initial conditions we can glean from the paper. "
9999
]
100100
},
101101
{
@@ -224,7 +224,7 @@
224224
"source": [
225225
"The next few cells plot the results on the same scale as the figures in the paper.\n",
226226
"\n",
227-
"**Exericise:** Compare your results to the results in the paper.\n",
227+
"**Exercise:** Compare your results to the results in the paper.\n",
228228
"Are they consistent?"
229229
]
230230
},
@@ -278,7 +278,7 @@
278278
"cell_type": "markdown",
279279
"metadata": {},
280280
"source": [
281-
"**Exercise:** Read [this response to Phillips's article](https://science.sciencemag.org/content/sci/272/5270/1960.full.pdf) and Phillips's response to the response. What do you think of the arguments on both sides. Do you think the model Phillips proposed is sufficient to make his argument, or do you think it leaves out essential features of the real world?"
281+
"**Exercise:** Read [this response to Phillips's article](https://doi.org/10.1126/science.272.5270.1960) and Phillips's response to the response. What do you think of the arguments on both sides? Do you think the model Phillips proposed is sufficient to make his argument, or do you think it leaves out essential features of the real world?"
282282
]
283283
},
284284
{

0 commit comments

Comments
 (0)