Homework Assignment # 10: MATH 235 - Mathematical Models in Science and Engineering
Homework Assignment # 10: MATH 235 - Mathematical Models in Science and Engineering
Homework Assignment # 10: MATH 235 - Mathematical Models in Science and Engineering
Instructions: Present your work in a neat and organized manner. Please use either the 8.5 × 11 size paper or
the filler paper with pre-punched holes. Please do not use paper which has been torn from a spiral notebook.
Please secure all your papers by using either a staple or a paper clip, but not by folding its (upper left) corner.
You must show all of the essential details of your work to get full credit. If you used Mathematica for
some of your calculations, attach a printout showing your commands and their output. If I am forced to fill in
gaps in your solution by using notrivial (at my discretion) steps, I will also be forced to reduce your score.
Please refer to the syllabus for the instructions on working on homework assignments with other students
and on submitting your own work.
Homework Assignment # 10
In Problems 1, 3, and 5 you will be asked to run a Matlab code that I posted online and also to type
some Matlab commands outside of this code. If you need help understanding the meaning or the syntax of
a particular command commandname, you may either type help commandname (e.g., help rand)
or look inside the code to see how I used that command. If you are not sure what the command name may
be, click on Matlab’s Help tab (in the right corner of the menu bar at the top of the command window)
and type in some related key word, e.g., round, into the search box. Finally, if nothing else works, asking
Google should help in most cases; e.g., try it with “triangular matrix in matlab” (omit the quotes, of
course).
(of course, rounding to the nearest integer whenever necessary) and run the code. Record the average of
the absolute value of the error in the numerically reconstructed rnum (t) for each given n. (The exact data
rexact (t) ≡ u′ (t) is computed in the code. Matlab’s command for finding the average of the absolute
difference between any two vectors f and g is mean(abs(f-g)).)
Plot these error values versus n in a separate plot. Comment on whether your plot qualitatively confirms
the behavior predicted by Eq. (9) of the Notes.
Attach plots of rnum (t) for n = nopt and one other value of n of your choice, so as to illustrate the
importance (or otherwise) of choosing a nearly optimal value for n (and hence for h).
(b) Repeat the steps in part (a) for ep=0.05. Compare the values of mean(|rnum (t) − rexact (t)|) for
n = nopt in parts (a) and (b). Does this comparison confirm the square-root dependence of the error on
the noise amplitude exhibited by the r.h.s. of Eq. (10b)?
Hint: Recall that if a quantity a = O(ǫk ) for some k, this means that a ≈ C · ǫk for some unknown
constant C. Then, if a1 and a2 are the values of a obtained for ǫ = ǫ1 and ǫ = ǫ2 , respectively, how are
the ratios (a1 /a2 ) and (ǫ1 /ǫ2 ) related to each other?
1
2. Repeat the analysis of Secs. 10.1 and 10.2 where the finite-difference approximation (3) is now replaced
with
u(t + h) − u(t − h)
u′ (t) ≈ .
2h
To obtain the error made by this approximation in the smooth part of the derivative u′ (t), use one more
order in the Taylor expansion than in the notes. To estimate the contribution to the error from the noise,
use the worst-case argument similar to that used in the notes.1 Obtain expressions for hopt and the error
for h = hopt .
To verify your answer, find and quote a formula in Lecture 10 2 that shows the dependence of the optimal
error on ǫ.
(a) At the end of Sec. 10.4 we presented a calculation to the effect that even a discontinuous gold density
w(x) will result in a smooth disturbance of the vertical force µ(x). Here you will show this by explicitly
calculating the integral in (21) for a particular discontinuous w(x). For simplicity, set γ = D = 1 and
smin = 0 and smax = 1 in the integral in Eq. (21).
Consider a very simple discontinuous function
(
0, 0 ≤ x < 0.5;
w(x) =
1, 0.5 ≤ x ≤ 1 .
Use Mathematica to compute µ(x) given by Eq. (21), and also µ′ (x) and µ′′ (x) for −1 ≤ x ≤ 2.
Hint: Although it is possible to do using the command Piecewise in Mathematica, there is an easier
and less time-consuming method to compute the required integral.
Make plots of µ(x), µ′ (x), and µ′′ (x) and attach their printouts to your work. State whether you see a
discontinuity for any values of x in any of these plots.
(b) Download the code hw10_p3.m and run it. This will set up a matrix A, defined in Sec. 10.4.2, and
a column vector xx of length n = 20.
At the prompt in the command window, define a random column-vector y of length n such that the
nominal average of this vector is to equal 1 and the nominal maximum deviation from the average is to
also equal 1.3 Next, define another vector using the command Y=mean(y)*ones(size(y)). Plot
both vectors versus the variable xx in the same figure using different line styles. Thus, you now have a
jagged vector y and its smoothened version, Y.
Now open a new figure by typing, say, figure(2). Compute and then, in figure 2, plot together “the
solution” vectors v = Ay and V = AY versus xx. Use the same line styles for these two graphs as in
the previous figure. This plot that you have just created must be the first subplot out of three that will
be plotted in this figure. Label the vertical axis of your subplot as ’v and V’ (see help ylabel).
1
The worst-case noise will be different from that considered in Secs. 10.1 and 10.3.
2
It is not displayed conspicously.
3
If you do not how to do so, reread the boldfaced preamble to this entire Assignment.
2
In the second and third subplots, plot the numerically computed first and second derivatives of your “solu-
tions” v and V. Specifically, in the second subplot, plot diff(v)./diff(xx) and diff(V)./diff(xx)
versus xx(1:end-1). In the third subplot, plot diff(v,2)./(diff(xx(1:end-1))).ˆ2 and
diff(V,2)./(diff(xx(1:end-1)).ˆ2) versus xx(1:end-2). Use the same line styles as
before and also label your vertical axes. Print out both of your figures.
Draw a common conclusion from your results in parts (a) and (b).
(c) Clear the workspace from the previous part. Inside the code, set epsilon=0.0001 and then run
the code. Examine the figures, and especially note the vertical scale of figure 11 !
Next, type figure(11); hold on in the command window. This will prevent the next plot that will
be made in this figure from erasing the graph that is already there. Do the same for figure 13. Without
clearing the workspace, run the code again. (Since you did not clear the workspace, the random vector
added to µ will be different this time.) Repeat this four more times. Print out figures 11 and 13.
Draw a conclusion from this part of the exercise.
Food for thought, to be digested in Lecture 11 In figure 13 you see the profiles of the perturbations
that you have added to µ(x) and which generated the jagged curves in figure 11. Do the profiles in figure
13 seem to have similar shapes? Can one say the same about the profiles in figure 11?
4. Illustrate the derivation of the condition number in Sec. 10.5 geometrically, using as an example
!
0.01 0
A= .
0 100
Specifically, do the following. Divide the page into two halves with a vertical line. On one side draw
vectors b and A−1 b. On the other side, draw b + ∆b and A−1 b + ∆b. Here b and ∆b are the special
vectors introduced before Eq. (28). Add a brief explanation to your drawings (i.e., how they illustrate the
concept of the condition number).
(b) For n = 10, plot all the eigenvalues of A. (The corresponding Matlab’s command is eig.) Again,
you may need to use a logarithmic scale for the vertical axis. Attach the printed plot. Also, verify that
|λmax |
cond(A) = .
|λmin |
Note: To plot a vector myvector versus its index, simply type plot(myvector).
(c) Write a short code where you can set up the matrix in Eq. (33) (not including the factor 1/h) with
any dimension n. Run this code for n = 10, 20, 50, 100, 200, 300, 500 and record the condition
numbers. Plot cond(A) as a function of n (you will not need a logarithmic scale in this case.) Attach the
printed plot along with a printout of your code.
3
Technical note: For setting up the matrix of Eq. (33), you may use a number of methods. For example,
you may use two for-loops; the corresponding syntax is explained in the Matlab Primer posted online.
Alternatively, you may once again reread the preamble to this Assignment.
(d) Compare the rates with which the condition number grows with n in parts (a) and (c).
Of the problems of inverting the matrices referred to in parts (a) and (c), which one will be more ill-
conditioned? What does this mean in terms of the error when solving Ax = b?
Bonus (worth 0.5 pt; credit will be given only if the solution is mostly correct)
If you have not been satisfied with a result in Problem 1(b), do the following. For each ep, immerse
the code of hw10_p1.m in a for-loop which will record values of mean(|rnum (t) − rexact (t)|) for
each random realization and at the end will take their average over the number N of all realizations.4 Of
course, you should save your code under a name different from hw10_p1.m.
Have your conclusion about the the dependence of mean(|rnum (t) − rexact (t)|) on ǫ following formula
(10b) improved compared to that in Problem 1(b)?
4
By default, Matlab changes the seed of the random number generator in each realization inside the for-loop. However, each time
that you run your code, you will still get (slightly) different answers. This is because the initial seed in the for-loop is chosen by
Matlab according to some internal algorithm. To obtain results that do not change from one run to another, specify this initial seed by a
command rand(’state’, any integer number, e.g., 0).