Math 222 Numerical and Symbolic Methods in MATH/STAT


Student survey




Exam 1, Friday Sept. 21

            Some review topics

Exam 1  


Exam 2  Monday October 22


            Review topics

            Practice problems

            Things you should know about iteration.

            Exam 2 Fall 2011

            Exam 2 Fall 2010

                        Solutions .m file

                        Written parts of solution

Exam 3  Monday Dec. 3


            Review topics


Final Exam : Thursday, 3-5 PM

            Review topics (also see more detailed reviews above)

            You can find some old final exams here via links near the bottom of the page.


Course Notes

MATLAB’s Desktop Environment

Variables and Operators

Datatypes: double precision floating point numbers, creating arrays, complex arrays, function handles

            IEEE Standard 754 floating point numbers  (an article on number representation)

            Array worksheet

            More on arrays

Basic plotting

M-files and programming 

Programming tips

How MATLAB evaluates a function

Color in MATLAB

            WVU colors   WVU logos

Cellular automata

Saving data

Recursive functions



Least Squares

Plotting on rectangular grids, in three dimensions

Simulation  - simulating discrete and continuous probability distributions, random walks, assembling data from simulation bar and hist plots.










Practice exercises




8/31  Discussion of MATLAB script files and functions/function files. These are both files with the extension ‘.m’. A script file is just a series of commands that are invoked by giving the file name (without the extension) in the command window, and they are executed as if they were entered one-by-one in the command window.  Developing MATLAB functions is the central goal of this course.  We created the function quadroots.m to calculate the two roots of a quadratic ax2+bx+c given the coefficients a,b,c as arguments (inputs).


9/5  Loops and sums. If and while statements. Finding the sum of a fixed number of terms; finding a sum while the terms are “large enough”. Defining the Hilbert matrix using nested loops: myhilb.m  The same idea can be used to create and analyze general matrices.



9/7       ang.m    This is a MATLAB program to “solve a triangle” given its sides. The input is an nx3 array of side length specifications for n triangles.


9/10     Two more functions:  ulam.m  creates the sequence invented by the mathematician Ulam. Starting with a value n, the next term is the sequence is 3n+1 if n is odd, and is n/2 if n is even. The function bbsort.m sorts a one-dimensional array using the so-called bubble sort method and displays the evolution of the sorting process graphically.

Note: When plotting inside a function, the plot will not be executed until the function has finished UNLESS you include the ‘drawnow’ command, or a ‘pause’ command.


9/14  Images on the web: JPEG image of a bulding lobby. GIF image of a sunflower and a GIF precipitation forecast from the NWS. 

Cellular automata: heat1.m    This is a simple cellular automaton inspired by the heat equation in a bar or, more generally, “diffusion” processes.


Some “cellular” images: seashell.jpg   wolframdress2.jpg

Cellular automata posts:

    a program to simulate cellular automata


                        Game of Life as a computer


9/26     Two cellular automata programs:

            wolfram.m  implements Wolfram’s one dimensional cellular automata

            gol.m     implements the game of life

Here are two interesting initial states for the game of life. Download them into your current folder and then load them into your MATLAB workspace by saying load acorn, and load gun.

            acorn.mat       A long-lived game of life starting configuration

            gun.mat           The Gosper gun



Some data to download:

crefstock.xlsx  you can download into your current folder and load into MATLAB using xlsread

sierpinskir.m    A recursive construction of the Sierpinski triangle.


10/1  Iteration, fixed points, chaos

Looking for fixed points: plot(x,f(x),x,x) the intersections are the fixed points (why?)

Stability of fixed points: |f’(x*)|<1 ensures a stable fixed point; |f’(x*)|>1 means fixed point is unstable.

Where are the fixed points of f(x)=1/(1+20exp(-6x)). How do you know by looking which ones are stable and which ones are unstable?

What about the function f(x)=e3x(2-x)/28. Which fixed points are stable and which are unstable? How do you know? (You may need to do some calculations for this one…)


Written notes    The graphical interpretation of iteration

chaos.m  Simulates iterations for the family of functions f(x)=a*x*(1-x). Plots “long term” behavior of the iterations, so that we can “see” stable fixed points, period two orbits, period 4 orbits, ..etc, and then chaos.


Horner’s method for evaluating polynomials:

function y=mypolyval(p,x)



     for k=n-1:-1:1

     y=p(k)+x.*y; %basic step: multiply by x and add next coeff




10/3 Written notes on iteration, fixed points, stability/instability, the “arrow” graphical approach to following iteration


10/10  Basic implementation of Newton’s method. Graphical interpretation of Newton’s method: following down the tangent. Error analysis: quadratic convergence.  Written notes.


10/12  More Newton’s method – following convergence to multiple roots with one iteration. Written notes: the formula for the rate of quadratic convergence: e­n+1~[f’’(x*)/(2f’(x*))](en)2


10/19  majority rule function majrule.m  . Various worked problems: notes10_19.m


10/26  Interpolating values from a given function. Here, high degree polynomials are capable of very good approximation under certain conditions, but they are very sensitive to any errors in the data. Here if we add “noise” of size .01 to the data, the interpolant of degree 12 changes by 20 or 30 times the size of the noise; the phenomenon gets worse for higher degrees.

10/29  The Lagrange fundamental polynomials – directly show how the interpolant can be constructed and show how the interpolant depends on each y data value. For high degree these polynomials have wild swings near the boundary.   Written notes here.


11/2   Two programs we developed: polyinterp.m  “cans” the standard technique we use for polynomial interpolation.  cubeinterp.m  is a function to do piecewise cubic interpolation using data from two points on either side of a given point in the domain.


11/5  Some notes: deriving the error expression for the nearest-neighbors cubic interpolation procedure. Then, introduction to least squares: derivation of the normal equations from the orthogonal projection principle.   notes11_5.m  Performance of our cubic interpolation routine. Least-squares approximation from data input by hand.


11/7  Written notes: review of normal equations for least squares, introduction to meshgrid statement for preparing rectangular coordinate arrays.  notes11_7.m  least squares approximation of data (entered by user input), approximation of functional data, approximation of a parametric curve. The function pcolor for pseudocolor plots of a function defined at gridpoints.


11/9  pcolor, contour, surf, plot3 (for curves), using the 4th argument of surf for coloring a surface


11/12     Spherical coordinates geometric picture. Various plotting applications: a sphere via spherical coordinates, punching holes in the sphere, a cone in cylindrical coordinates, a general parametric surface.


11/14   Applications: putting holes in a sphere; a geometric pattern formed from random circles, each point colored according to how many circles it falls inside of; the moebius strip as a parametric surface; embedding an image onto a surface. Example tiger.jpg  is embedded into a sphere.

Pucci scarf  A scarf pattern similar to that shown in the notes

moebius.m The script file to animate the formation of a moebius strip

chance.m  Dropping a “ball” through a maze to wind up in a random position


11/28  Review of homework – chebyshev polynomial interpolation, interpolation and least squares problems, plotting surfaces on rectangular and circular domains, plotting a curve


11/30  Some review material



Material on simulation will be added later





Homework 1  Due Friday Sept. 7 by 11:59 PM



Homework 2  Due Monday, Sept. 17 by 11:59 PM



Homework 3  Due Monday, Oct. 15 by 11:59 PM



Homework 4  Due Thursday, Nov. 8 by 11:59 PM





Homework 5  Due Tuesday Nov. 27 by 11:59 PM

            hourglass.m  computed coefficients, the surface plot

            myhourglass.fig    the computed outline

            myhourglass2.fig  in three dimensions

  Part 2 

            ptpicker.m  Auxiliary script file

            see notes 11/28 above for worked solutions