forked from hplgit/scipro-primer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherratalist4th.html
299 lines (216 loc) · 10.4 KB
/
erratalist4th.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
<!--
Automatically generated HTML file from DocOnce source
(https://github.com/hplgit/doconce/)
-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="DocOnce: https://github.com/hplgit/doconce/" />
<meta name="description" content="Erratalist for 4th Edition of A Primer on Scientific Programming with Python">
<title>Erratalist for 4th Edition of A Primer on Scientific Programming with Python</title>
<style type="text/css">
/* bloodish style */
body {
font-family: Helvetica, Verdana, Arial, Sans-serif;
color: #404040;
background: #ffffff;
}
h1 { font-size: 1.8em; color: #8A0808; }
h2 { font-size: 1.6em; color: #8A0808; }
h3 { font-size: 1.4em; color: #8A0808; }
h4 { color: #8A0808; }
a { color: #8A0808; text-decoration:none; }
tt { font-family: "Courier New", Courier; }
/* pre style removed because it will interfer with pygments */
p { text-indent: 0px; }
hr { border: 0; width: 80%; border-bottom: 1px solid #aaa}
p.caption { width: 80%; font-style: normal; text-align: left; }
hr.figure { border: 0; width: 80%; border-bottom: 1px solid #aaa}
div { text-align: justify; text-justify: inter-word; }
</style>
</head>
<!-- tocinfo
{'highest level': 3,
'sections': [('Page 4', 3, None, '___sec0'),
('Page 11', 3, None, '___sec1'),
('Page 95', 3, None, '___sec2'),
('Page 99', 3, None, '___sec3'),
('Page 130', 3, None, '___sec4'),
('Page 158', 3, None, '___sec5'),
('Page 189', 3, None, '___sec6'),
('Page 189', 3, None, '___sec7'),
('Page 216', 3, None, '___sec8'),
('Page 273', 3, None, '___sec9'),
('Page 315', 3, None, '___sec10'),
('Page 426', 3, None, '___sec11'),
('Page 447', 3, None, '___sec12'),
('Page 508', 3, None, '___sec13'),
('Page 676', 3, None, '___sec14'),
('Page 756', 3, None, '___sec15'),
('Page 775', 3, None, '___sec16'),
('Page 776', 3, None, '___sec17'),
('Page 780', 3, None, '___sec18'),
('Page 836', 3, None, '___sec19'),
('Page 843', 3, None, '___sec20'),
('Page 844', 3, None, '___sec21')]}
end of tocinfo -->
<body>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: {
equationNumbers: { autoNumber: "AMS" },
extensions: ["AMSmath.js", "AMSsymbols.js", "autobold.js", "color.js"]
}
});
</script>
<script type="text/javascript"
src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<!-- ------------------- main content ---------------------- -->
<center><h1>Erratalist for 4th Edition of A Primer on Scientific Programming with Python</h1></center> <!-- document title -->
<p>
<!-- author(s): Hans Petter Langtangen -->
<center>
<b>Hans Petter Langtangen</b>
</center>
<p>
<!-- institution(s) -->
<br>
<p>
<center><h4>Sep 20, 2015</h4></center> <!-- date -->
<br>
<h3 id="___sec0">Page 4 </h3>
<p>
The one-line program to be written in a text editor must have
<code>t**2</code> and not <code>t^2</code>.
<h3 id="___sec1">Page 11 </h3>
<p>
<code>%0xd</code> is not an integer padded with <code>x</code> leading zeros, but an integer written
with a minimum field width of <code>x</code>, where any leading spaces are replaced
by zeros.
<h3 id="___sec2">Page 95 </h3>
<p>
In the program <code>c2f.py</code>, the <code>print</code> statement has a wrong formatting
of the <code>F(C)</code> value: <code>%.51f</code> must read <code>%5.1f</code>, i.e., the same formatting
as used for the <code>C</code> value.
<h3 id="___sec3">Page 99 </h3>
<p>
Heading in Section 3.1.5 should be <em>Function argument or global variable?</em>
(<em>or</em> instead of <em>of</em>).
<h3 id="___sec4">Page 130 </h3>
<p>
In Exercise 3.6, Equation (3.10), the sum must be \( \sum_{i=0}^{n-1} \).
<h3 id="___sec5">Page 158 </h3>
<p>
The terminal output for the integral \( \int_0^{\pi/2}\sin x\,dx \) should read
<code>1</code>, not <code>0.583009</code>.
<h3 id="___sec6">Page 189 </h3>
<p>
In the <code>mymod.py</code> module, an <code>import sys</code> is needed in the test block before
<code>print add1(float(sys.argv[1]))</code>.
<h3 id="___sec7">Page 189 </h3>
<p>
The last code showing the test block of the <code>interest</code> module needs two
corrections: division by 365 if the expression for <code>years</code> and an <code>f</code>
in the <code>print</code> statement:
<p>
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span style="color: #008000; font-weight: bold">if</span> __name__ <span style="color: #666666">==</span> <span style="color: #BA2121">'__main__'</span>:
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">sys</span>
p <span style="color: #666666">=</span> <span style="color: #008000">float</span>(sys<span style="color: #666666">.</span>argv[<span style="color: #666666">1</span>])
years <span style="color: #666666">=</span> days(<span style="color: #666666">1</span>, <span style="color: #666666">2</span>, p)<span style="color: #666666">/365.0</span>
<span style="color: #008000; font-weight: bold">print</span> <span style="color: #BA2121">'With p=</span><span style="color: #BB6688; font-weight: bold">%.2f</span><span style="color: #BA2121"> it takes %.f1 years to double'</span> <span style="color: #666666">%</span> (p, years)
</pre></div>
<h3 id="___sec8">Page 216 </h3>
<p>
In Exercise 4.17, the reference to the program <code>user_formula.py</code>
should be <code>integrate.py</code>. The name of the resulting program is
then better named <code>integrate2.py</code> than <code>user_formula2.py</code>.
<h3 id="___sec9">Page 273 </h3>
<p>
In the first code block, <code>x3 = mat(x).transpose()</code> should be
<code>x3 = mat(x1).transpose()</code>.
<h3 id="___sec10">Page 315 </h3>
<p>
End of first paragraph: <code>Sun</code> is to be replaced by <code>Apple</code>.
<h3 id="___sec11">Page 426 </h3>
<p>
The argument in the <code>raise ValueError</code> call, after <code>if c*d <= 0</code>, needs
a final <code>% other</code>.
<h3 id="___sec12">Page 447 </h3>
<p>
The title of the chapter should be <em>Random numbers and simple games</em>.
<h3 id="___sec13">Page 508 </h3>
<p>
Exercise 8.13: Since \( 4\leq n\leq 10 \) balls are drawn, one must investigate
cases where \( n\in [4,10] \), say \( n=4,7.10 \) (and not \( n=1,5,10,20 \) which
does not make sense).
<h3 id="___sec14">Page 676 </h3>
<p>
The last line of the <code>integrate_ode.py</code> program should not contain
<code>u'(t)=t**3</code>, but read
<p>
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span style="color: #008000; font-weight: bold">print</span> <span style="color: #BA2121">"Numerical solution of u'(t)=</span><span style="color: #BB6688; font-weight: bold">%s</span><span style="color: #BA2121">: </span><span style="color: #BB6688; font-weight: bold">%.4f</span><span style="color: #BA2121">"</span> <span style="color: #666666">%</span> \
(f_formula, integrate(T, n, u0))
</pre></div>
<p>
The four terminal output sessions below are then also wrong: instead of
<code>u'(t)=t**3</code> it should be <code>u'(t)=t**exp(t**2)</code>.
<h3 id="___sec15">Page 756 </h3>
<p>
Exercise E.1: The exact solution is \( u(t)=0.2e^{0.1t} \).
<p>
== Page 768 ===
<p>
Exercise E.24: The first constant on the right-hand sides of equations
(E.70) and (E.72) must be 3 and 4, not 2 and 3.
<h3 id="___sec16">Page 775 </h3>
<p>
Below the equation with \( I(t+\Delta t) \), it must read
\( \Delta t\rightarrow 0 \) (not \( \infty \)).
<h3 id="___sec17">Page 776 </h3>
<p>
Exercise E.42: The last element of the returned list in the
<code>ProblemSIR.__call__</code> method should not have a minus sign; it should
be <code>self.nu(t)*I</code>.
<h3 id="___sec18">Page 780 </h3>
<p>
Exercise E.46: A value for \( I(0) \) is not given. Set \( I(0)=0 \).
<h3 id="___sec19">Page 836 </h3>
<p>
The text says "The import statements can actually be dropped since
functions from <code>numpy</code> and <code>matplotlib</code> are imported by default when
running the notebook in the browser or by supplying the command-line
argument <code>--pylab</code> when starting notebooks locally on your
machine.". Now, the use of <code>--pylab</code> is discouraged. Also, the
functions from <code>numpy</code> and <code>matplotlib</code> are not any longer
automatically imported - you have to do that explicitly.
<p>
The recommended way of using IPython notebooks with <code>numpy</code> and
<code>matplotlib</code> is to do
<p>
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">numpy</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">np</span>
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">matplotlib.pyplot</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">plt</span>
<span style="color: #666666">%</span>matplitlib inline
</pre></div>
<p>
If you want the notebook to behave more as Matlab and not use
the <code>np</code> and <code>plt</code> interface, you can instead write
<p>
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span style="color: #666666">%</span>pylab
</pre></div>
<h3 id="___sec20">Page 843 </h3>
<p>
To succesfully execute the <code>c2f.py</code> program, <code>cmd</code> must be <code>python c2f.y 21</code>
or <code>./c2f.py 21</code> (if <code>c2f.py</code> is an executable file) unless <code>.</code> is in
the user's <code>PATH</code> variable.
<h3 id="___sec21">Page 844 </h3>
<p>
Under <b>Split file or folder name</b>, the directory name <code>user</code> in the text
should be replaced by <code>/home/hpl</code> according to the interactive session.
<!-- ------------------- end of main content --------------- -->
</body>
</html>