Math 240 Scientific Computation Class Information 2019

The Syllabus: Math 240 2019

Advice on how to organize this course in a classroom setting and solutions to the tests and quizzes are available to instructors upon request.

Here are all the class files on this page (at least those I have not changed since the last mod date) in one zipfile.  Last modified on 11/9/20 at 18:50.

Find below the tests, homework, schedule fine-tuning and other important course information including the daily MATLAB scripts (reviewed in class) and m-files, all of which students can use (without attribution---just use them) for tests and HW.

Before Anything: Get the Book and Easy Access to a Working Installation of MATLAB.

If you purchase a MATLAB license you can access a MATLAB server at MathWorks from this link through a web browser interface on any computer (such as any BC campus computer) or also from a mobile device such as an iPad or smartphone using the MATLAB Mobile app. Apparently (I haven't tried it) you can do almost everything through this app and store files at your account in MATLAB Drive, a cloud account shared by all your devices. Pretty cool. One year a student did everything on his phone. Pretty deranged. (But he got a good grade so .... whatever!)

Script 1 for Week 1  Last modified on 11/1/19 at 10:40.
Basic commands, logical variables, loops, first modeling example, Euler's Method, first plots
Script 2 for Week 1  Last modified on 05/20/19 at 14:28.
reading and writing to files, the machine epsilon of a number and finite precision arithmetic, more on plotting possibilities, First steps in solving Matrix equations.
Script 3 for Week 1  Last modified on 11/13/19 at 16:09.
M-files and functions, LinRegPlots.m and LinearRegression.m.
Script 1 for Week 2  Last modified on 11/18/19 at 16:55.
more plots and user input and eps, isinf, NaN, fprint, cell arrays, strings, nice tables, errors
Script 2 for Week 2  Last modified on 11/18/19 at 17:09.
The M-files for root-finding: incsearch.m and bisect.m and newtraph.m. Also facts about generating and manipulating polynomials in MATLAB.
Script 3 for Week 2  Last modified on 11/20/19 at 11:10.
varargin, fixed point again, more on 3-d graphs and the modified secant algorithm: modsec.m.
Script 1 for Week 3  Last modified on 04/27/19 at 11:09.
fminbnd and fminsearch, visualizing 4-d, minima over irregular regions
Script 2 for Week 3  Last modified on 09/28/19 at 12:59.
Discussion of the min-finders generally and, in particular, goldmin.m and parabmin2.m and the tridiagonal system solver Tridiag.m.

Also: comparing the speeds of backslash, inverse and rref methods of solving linear systems.

Script 3 for Week 3  Last modified on 12/14/19 at 16:47.
Vector Spaces, Solving Systems in General, Least-Squares Solutions
Script 1 for Week 4  Last modified on 12/20/19 at 16:53.
Sorting, GaussNaive.m and LUNaive.m and illustration and comments about various matrix factorizations: LU, Cholesky, QR and applications of the Singular Value Decomposition, including an example of image compression using the SVD.

Bitmap imagefile for SVD practice.

Addendum: Unhealthy Obsession with the efficiency of the LU algorithm.  Last modified on 11/1/19 at 13:10.

Script 2 for Week 4  Last modified on 09/28/19 at 13:11.
Norms and Condition Number. Both Linear and Nonlinear Gauss-Seidel (with relaxation) and multi-variable Newton-Raphson. We look at an interesting example displaying a certain kind of instability: with tiny variations in initial seed newtmult.m can produce solutions that are relatively far apart.

GSLR.m and GSNR.m and newtmult.m.

Also, here is a link to a note I put together giving more explicit form to the error inequalities and condition number.

Script 3 for Week 4  Last modified on 09/26/19 at 20:21.
The visualization M-file eigpics.m. Discussion of Eigenvalues and the Power Method. Discussion of complex eigenvalues.
Script 1 for Week 5  Last modified on 05/4/19 at 11:22.
Numerical Solution of Diagonalizable Linear DE systems and Eigensolutions
Script 2 for Week 5  Last modified on 09/10/19 at 09:09.
Some Statistics and an example of Monte Carlo simulation. Also the M-file fivenum.m.
bplot.m, a Boxplotter by Jonathan Lansey

fourplot.m, a useful statistics visualization M-file created by Jos van der Geest


Script 1 for Week 6  Last modified on 05/4/19 at 11:51.
All there is to know about least-squares fitting of a real (or complex) response to a linear combination of real (or complex) valued functions OF ANY KIND. Except for efficiency tweaks (see FFT later in the course) this is the last word on the subject.
Script 2 for Week 6  Last modified on 09/8/19 at 20:18.
fseries2.m creates Fourier Series Coefficients. You invoke it as [alpha,a,b] = fseries2(N,@(x)q(x)) where N is the number of terms and q is the function to be approximated. This is the orthogonal projection I am Groot of q onto the subspace of functions spanned by the first N sine and cosine terms. The individual terms themselves are orthogonal to each other.
Script 3 for Week 6  Last modified on 05/4/19 at 12:16. The Discrete Fourier Transform

Here are the two DFT function M-files, DFTtest.m and RealDFT.m.

Here is a link to some notes I created about the vocabulary and theory behind the DFT.

Script 1 for Week 7 Last modified on 05/4/19 at 14:45. Script to explore the Fast Fourier Transform and sunspot cycle

Sunspot Data: name it spotdata.txt and put in the working MATLAB directory

Example Problem from Chapra, Chapter 16, Problem 12

Here are eleven function M-files (some from Chapra): Lagrange.m and Newtint.m and natspline.m and trap.m and trapuneq.m and cumsimp13.m and cumsimp38.m and OneThirdSimp.m and ThreeEighthSimp.m and simp13.m and simp38.m. OneThirdSimp.m and ThreeEighthSimp.m are way faster than simp13.m and simp38.m, but the latter might behave substantially better in the presence of noisy data. The Richardson Approximation/Big and Little O slides, and an EXTREMELY BRIEF version.


Script 1 for Week 8 Last modified on 05/4/19 at 15:21. This and the next scripts deal with (combined) spline interpolation and the built-in integration utilities and numerical integration using the trapezoid and Simpson rules. Script 2 for Week 8 Last modified on 05/4/19 at 15:21.

More on spline interpolation and the built-in integration utilities and numerical integration using the trapezoid and Simpson rules.

Script 3 for Week 8 Last modified on 05/4/19 at 15:21. We compare cumtrapz and cumsimp13 and cumsimp38.
Script 1 For Week 9 The Richardson technique to improve an approximation scheme and the Gauss-Legendre formulas. Last modified on 05/4/19 at 15:31.

Also, Chapra's Romberg Integration M-file, romberg.m.

Script 2 For Week 9 A variety of numerical differentiation formulae and associated M-files, and more on the Richardson technique. Last modified on 09/28/19 at 13:28. A Little Exploration of Quaternions Last modified on 06/19/19 at 20:53.

A Detailed Discussion of Quaternions and Complex Numbers and Rotations in the plane and in space.

The phenomenon described in the Wikipedia articles on the belt or plate or Balinese cup trick (same principle) can be explained using quaternions. The property of Gimbal Lock can be avoided using quaternions. Plus they have many cool properties and historical interest---Maxwell wrote A Treatise on Electricity And Magnetism using them.

Script 1 for Week 10 An intro to the built-in DE solvers. Last modified on 09/28/19 at 12:42.
Here are the DE solvers/utilities: dirfield.m and eulerode.m and eulersys.m and rk4sys.m

dirfield.m will create a direction field imagefile.

Here is a very brief introduction to Resampling, Bootstrap and Permutation methods for statistical inference, at a useful but basic level. The idea of a hypothesis test and the meaning of a confidence interval is assumed. Without that you will have to start from scratch with sampling distributions and so forth, which would take several days at least.(Last modified on 09/17/19 at 10:23.)
Here is a script about rigid body motion. Of independent interest, we see how to create a movie from a sequence of graphs. Last modified on 09/17/19 at 10:36.

Here are seven function M-files to handle various calculations about rigid body motion: Skew3.m and RotFromVector.m and RotUsingRodriguesFormula.m and EulerAngsFromRot.m and RotFromEulerZYX.m and RigidTransform.m and PlotMovingFrame.m

Script 1 for Week 11 A discussion of predictors and a mere mention of the words: Kalman Filter, PID Controller. Depending on your future classes (anything involving robotics, for instance) you may study these. Last modified on 05/5/19 at 10:48. Script 2 for week 11 Last modified on 05/4/19 at 14:58. The Soundscript


Script 3 for Week 11 Last modified on 05/4/19 at 14:58. A few last words ...

Comment on Chapra's Problem 23.15. (More in the "last words" note above.) Last modified on 05/4/19 at 12:24.

You can copy a screen segment directly into the clipboard for pasting into a document on a Mac by command-control-shift-4 and then highlight the desired part of your screen. In Windows it is Ctrl+C in the snipping tool.

You can copy a graph directly into the clipboard from within MATLAB using the edit menu.

To stop execution of whatever is currently running in MATLAB, on a Windows machine press Ctrl+C or Ctrl+Break in MATLAB. On an Apple machine you can use Command+. (i.e. the Command key and the period key).

Test and Homework numberes reference our text, Steven Chapra's "Applied Numerical Methods with MATLAB 4th Ed."

Homework 1 Due by class time on Monday of Week 3

Octave Online. Interesting, somewhat limited.

Test 1, Due by class time on Monday of Week 4:
Text Problems 5.1, 5.2, 5.7, 5.12, 5.20, 6.2, 6.18, 6.19, 6.20, 6.27, 7.7, 7.21, 7.27, 7.35

Homework 2, Due by class time on Monday of Week 5:
Text Problems 8.6, 8.11, 9.1, 9.10, 10.3, 10.12

Test 2, Due by class time on Monday of Week 6:
Text Problems 11.6, 11.10, 11.12, 11.14, 11.18, 12.6, 12.9, 12.11, 13.5, 13.10, 13.11, 13.12

Homework 3, Due by class time on Monday of Week 7:
Text Problems 14.3, 14.6, 14.25, 14.29, 15.5, 15.6, 15.8, 15.10, 15.13, 15.20, 15.22, 15.26

Jeff Musiak, Algorithm Development Lead, Airspace & Operational Efficiency at Boeing will speak to us on February 14. This is an opportunity to hear about the career arc of a real Engineer and what it is like "out there" in his world.
Here is a link to more info about Jeff.

Test 3, Due by class time on Monday of Week 8:
Text Problems 16.7 (first 4 nonzero terms, assume T=1), 16.8 (first 4 nonzero terms), 16.10 (all 4 terms plus the constant term), 16.11, 16.16, My FFT Problem, 17.7, 17.21

Homework 4, Due by class time on Monday of Week 9:
Text Problems 18.3, 18.7, 18.15, 19.3, 19.7, 19.14, 19.22, 19.23
The script described on the second column of Page 482 (Problem 18.15) makes no sense to me. You may ignore anything beyond the 8th line in that column. On all problems, for full credit graphs must be given wherever that would be useful and have titles (always) and axis labels (if x and y have units) and legends (if there are multiple graphs in the same figure.)

Test 4, Due by class time on Monday of Week 10:
My problem 1 and Text Problems 20.5, 20.14, 20.16, 21.1, 21.5, 21.12, 21.13

HW 5, Due by class time on Monday of Week 11:
Text Problems 22.4, 22.7, 22.8, 23.1, 23.13, 23.15, 24.1, 24.2

Dan Sola, a groundwater Engineer and geologist at SCS Engineers will speak to us (by Skype) for about an hour at the time of the final. Dan is a hydrogeologist and project manager with more than 30 years of experience. He serves as SCS's Arizona/New Mexico project director and leads the firm's Phoenix office. His experience includes groundwater modeling, hydrogeological evaluation, remediation, contaminant fate and transport, risk assessment, natural attenuation, expert witness work, and environmental review. He has extensive experience with VOCs, creosote/PCP, PCBs, and metals, including Cr(VI). He worked with the University of Minnesota on innovative technology research projects including phytoremediation and direct hydrogen injection for chlorinated VOC treatment. Mr. Sola is a registered geologist in Arizona. He earned a bachelor's degree in geology from Michigan Technological University. Here is a recent article about Dan.

Final, due by the beginning of our posted final time:
Eliminate or substantially attenuate the tone near the end of the wav soundfile prob.wav while leaving the spoken words essentially unaltered as best you can.

I will listen to your soundfile looking for clarity of the words, lack of tones (don't remove the theramin music, just the tones which are toward the end of the soundfile) and a minimum of "pop-and-click" artifacts of your cleaning process.

Your solution will consist of script M-file containing all and only the steps which will produce the clean(er) soundfile from the problem soundfile, step by step in order, and the zipped soundfile thereby created. This test is highly unusual for us, in that no explanations or comments are necessary or wanted. Just send me the script and soundfile, two files, submitted as a single zipped email attachment.

I will examine this and then run your script and compare the result to the soundfile you sent to me: they must exactly match.

Your solution cannot use the MATLAB toolboxes for signal processing, the audio toolbox, symbolic toolbox etc. You may use just the built-in vanilla MATLAB functions like fft and ifft or scripts we created in class (which you will likely modify) in your solution!

Here is a book by a man every engineer should know about, Richard Hamming. It's title is "The Art of Doing Science and Engineering" and, technically, its content overlaps that of our course. But it is about much more: it is about how to become excellent, and why that is a good idea. Enjoy.

Sample of a Practically Perfect Paper

Homework Cover Sheet

Test Cover Sheet.

Specific Homework and Test Instructions.

Goal: To create stylish, convincing, easy-to-read, documented, illustrated reports using MATLAB.

The answer is not the point: of course you will get an answer to most HW and Test questions. But an answer concealed in a blob of verbiage and scripts is useless.

Remember the "Rule of Three." (1) Tell 'em what you are going to tell 'em. (2) Tell them. (3) Then tell them what you told them.

Find below a checklist of a good organization of a long problem. Though not all problems will require separate sections for each, a list of "answers" will never get any credit. Period.

You may assume that your reader knows MATLAB and is generally conversant with any physical scenario but otherwise each problem solution should be a self-contained report, as if you are trying to explain the issue to your bosses ... or their bosses. Engineers tell me that the problem with newly hired engineers is not their knowledge base. It is that they can't create an intelligible, professional-level report to save their professional lives---upon which such reports, largely, depend. This class will help with the issue.

You are creating reports in the HW and tests, not listing answers.

I can be contacted by e-mail at .

This page was last modified on 11/9/20 at 18:55.