Chapter 4
Solutions: Design of
Computer Programs:
Writing Your Legacy
CHALLENGE 4.1. See posteddoc.m on the website.
CHALLENGE 4.2.
Data that a function needs should be specied in variables, not constants.
This is ne; C is a variable.
Code should be mod
Chapter 18
Solutions: Case Study:
Multidimensional
Integration: Partition and
Conquer
CHALLENGE 18.1. A sample program is given on the website. Method 2 gives
somewhat better results, since it averages the function values themselves rather than
just using
106
Chapter 17. Solutions: Case Study: Monte-Carlo Minimization and Counting
A third alternative is to keep track of both edges and nodes. Think of it as a
matching problem: each node can be matched with any of its four neighbors
in a dimer, or it can be
105
3500
KRS
Explicit count
3000
2500
C(k)
2000
1500
1000
500
0
1
2
3
4
5
k
6
7
8
9
Figure 17.9. Counts obtained by the KRS algorithm and by explicit counting for a 4 4 lattice. For KRS we set the probabilities to 0.5, the number of steps
between records
12
Chapter 2. Solutions: Sensitivity Analysis: When a Little Means a Lot
13
7.9
LP Example 1: perturbed solutions
x 10
LP Example 1: perturbed function values
1
0.8
7.85
0.6
0.4
0.2
7.75
0.2
x2
7.8
0
0.4
7.7
0.6
0.8
7.65
0.999
0.9992
0.9994
0.9996
0.9998
Chapter 19
Solutions: Case Study:
Models of Infection:
Person to Person
CHALLENGE 19.1. See the solution to Challenge 3.
CHALLENGE 19.2. See the solution to Challenge 3.
CHALLENGE 19.3. The results of a simulation of each of these three models
are given i
1
S
0,-1,-1
1
K
0,-1,2
1-
N
1,-1,1
1
1
G
2,-1,-1
1
R
-1,-1,-1
1
1
1
C
1,2,1
2
A
0,1,0
1
1
J
-1,-1,2
1
I
2,-1,1
H
1,2,0
M
1,-1,0
Q
0,-1,0
(1-)
(1-)
(1-)2
(1-)2
B
0,2,0
D
2,-1,2
(1-)
(1-)
2
F
1,-1,2
E
0,2,1
O
0,-1,1
1
1
1
P
-1,-1,0
1
L
2,-1,0
1-
1
1
114
16
Chapter 3. Solutions: Computer Memory and Arithmetic
CHALLENGE 3.5. The data cannot be fully explained by our simple model,
since, for example, this machine uses prefetching, two levels of cache, and a more
complicated block replacement strategy than t
113
Histogram of infection rate for nu = 0.100000
200
300
150
Number of trials
Number of trials
Histogram of infection rate for nu = 0.000000
400
200
100
0
0
20
40
60
Percent infected
80
0
10
20
30
Percent infected
40
Histogram of infection rate for nu =
Chapter 3
Solutions: Computer
Memory and Arithmetic:
A Look Under the Hood
CHALLENGE 3.1. See problem1.m on the website.
CHALLENGE 3.2. The counts of the number of blocks moved are summarized
in the following table:
column
oriented
storage
row
oriented
st
112
Chapter 19. Solutions: Case Study: Models of Infection: Person to Person
Disease Status with tau = 0.200000, delta = 0.010000, nu= 0.100000
0.9
Infected
Susceptible
Recovered
Vaccinated
0.8
Proportion of individuals
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
0
2
4
111
Disease Status with tau = 0.200000, delta = 0.010000
1
Infected
Susceptible
Recovered
0.9
0.8
Proportion of individuals
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
0
5
10
15
20
25
30
day
Figure 19.2. Proportion of individuals infected by day in a 10 10 grid
of hosp
110
Chapter 19. Solutions: Case Study: Models of Infection: Person to Person
Disease Status with tau = 0.200000
1
Infected
Susceptible
Recovered
0.9
0.8
Proportion of individuals
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
0
5
10
15
20
day
25
30
35
Figure 19.1. Proport
13
Solutions to the differential equation
1.7
1.6
1.5
y
1.4
1.3
1.2
1.1
1
0
5
10
15
20
25
t
30
35
40
45
50
Figure 2.3. Results of Challenge 2.4. The black curves result from setting
a = 0.006 and a = 0.009. The blue curves have random rates chosen for eac
Chapter 17
Case Study: Monte-Carlo
Minimization and
Counting: One, Two, . . . ,
Too Many
(coauthored by Isabel Beichl and Francis Sullivan)
CHALLENGE 17.1. The programs myfmin.m and myfminL.m on the website
solve this problem but do not make the graph.
CH
98
Chapter 16. Solutions: Monte Carlo Principles
CHALLENGE 16.4.
function y = strange_random()
% We subtract 2 from the average sample value for randmy, to make the mean 0.
% Then we divide by the standard deviation, to make the resulting variance 1.
y =
190
Chapter 31. Solutions: Case Study: Eigenvalues: Valuable Principles
since a1 (x), a2 (x) > 0.
Suppose Aw = w. Then
0 (w, Aw) = (w, w),
so 0.
(b) We know that
1 () = min
w =0
(w, Aw)
(w, w)
where the integrals are taken over and w is constrained to be
87
Lcurve for TLS
0.97
10
0.96
10
0.95
solution norm
10
0.94
10
0.93
10
0.92
10
0.91
10
0.9
10
2
1
10
10
residual norm
Figure 14.4. The L-curve for total least squares solutions.
other components should have at least some data in addition to noise. Theref
189
Errors in eigenvalues as a function of 1/h2
2
10
1
6
11
16
21
1
10
0
error in eigenvalue
10
1
10
2
10
3
10
4
10
2
3
10
4
10
5
10
10
(approx) 1/h2
Figure 31.2. The errors in the eigenvalue approximations.
The error ratios are as follows:
lambdaj
j=1
j=
188
Chapter 31. Solutions: Case Study: Eigenvalues: Valuable Principles
Figure 31.1. Eigenfunctions corresponding to the eigenvalues =
4.9348, 12.3370, 12.3370 (top row) and = 19.7392, 24.6740, 24.6740 (bottom row).
number of triangles, which is approxima