Matthias Kawski
School of Mathematical & Statistical Sciences Arizona State University 

MATLAB resources
Back to technology page 
0. General comments:  Getting MATLAB 
This commented index has just been completely overhauled  hope it
will be helpful! Please report any broken links!  
1. Calculus:  Numerical integration  
2. Ordinary DEs:  a. Graphical  b. Euler/RungeKutta  c. 2nd order 
3. Linear Algebra:  a. GaussJordan  b. Lin Trafo's  c. Polygons, 
d. Inner products  e. Fourier analysis  f. Diagonalization  
xx. Analysis:  a. Adv Calc  
5. PartialDiffEqns:  a. Heat eq numerically  b. Fourier & sep var's  c. Wave equation 
6. Advanced Visualization:  a. Complex Analysis  b. Differential Geometry  c. Control 
Alternatively, use the uncommented directory listings, or your browsers search/find utility for a keyword search of this commented index. 
0. General comments
0.a. Getting MATLAB 
Date: Mon, 24 Jan 2000 15:54:56 0500 From: The MathWorks 
1. Calculus
1.a. Numerical integration

directory listing  
egg.m  Numerical estimation of moment of inertia of an egg (enter data from slice, numerical integration). 
leftrite.m  script to generate lots of data to compare left/rite/mid/trap sums for int(exp(x^2),x=0..1) with n from n=1 to n=1,048,576. (Use this to generate data  but don't worry about the details. The code effectively reuses function values that already have been computed  but at the price of making the code less transparent.) (See this old classmaterial for more explanations, data tables generated, and images.) 
2. Ordinary Differential Equations
2016 Gil Strang and Cleve Moler
2.a. Graphical focus

directory listing  
slopefld.m  Modification of the MATLAB file quiver.m that draws slopefield for a differential equation with line segments of normalized lengths. (A file from the 1995 DE class.) 
RC.m  sample function file for use w/ ode23: first order diff eqn of RC circuit. 
intrDE1.m  Demonstration how to set the path, how to get help, how to use ode23. Includes plotting the soln and overlaying many solns for simultaneously solved initial value problems. Uses the file RC.m which should be saved first in suitablle directory. 
intrDE3.m  Demonstration how to overlay the direction field (quiver.m) and solution curves of a first order DE. Alternative: Use the homemade slopefld.m instead of the builtin quiver.m. Uses the file RC.m. 
intrDE4.m  Demonstration how to overlay the vector field (phase portrait) (using quiver.m) and solution curves of a second order autonomous DE. Uses the file damped.m. 
intrDE.m 
Concatenation of the
intrDE1.m
intrDE2.m
intrDE3.m
intrDE4.m
The script files intrDEn.m call the examples RC.m, forced.m, and damped.m  download these first and save them in a subdirectory in the search path.... 
2.b. Numerical integration
Euler's method, RungeKutta schemes
Numerical stability
transition to chaos
directory listing  
euler.m  Commented simple implementation of Euler's method for the unstable DE y'=t*sin(y).  
unstable.m  sample function file for use w/ ode23: good example to demonstrate unstable DE y'=t*sin(y)  which solver lasts longer?  
euler1.m  Minimalist implementation of Euler's method for the unstable DE y'=t*sin(y). damped2.m  
peneuler.m  Simple pendulum using Euler's method.  
penHeun.m  Simple pendulum using Heun's method.  
penRK4.m  Simple pendulum using a 4th order Runge Kutta method. 
2.c. Second order systems
Nonlinear versus linearized pendulum
Several useful templates in the format expected by ode23
directory listing  
cascade.m  sample function file for use w/ ode23: 2dcascade. 
forced.m  sample function file for use w/ ode23: Forced, damped, harmonic oscillator. 
intrDE2.m  Demonstration how to use ode23 to solve second order DE. Uses the example forced.m 
oscill.m  same as forced.m. 
damped.m 
similar to forced.m, but nonlinear oscillator and without forcing.

damped2.m  sample mfile (for use with ode23 etc.) to simultaneously integrate a nonlinear oscillator and its linearization. 
compare.m  sample script for simultaneous integration of a nonlinear oscillator and its linearization. Extensive comments for MATLABbeginners (from setting the path, opening mfiles for editing, calling ode23, and overlaying the plots). Good place to copy from, and edit commands for further explorations. Uses the file 
pencompare.m  Comparison of the simple pendulum and the linearized pendulum. For the latter both exact solutions and numerical RK4 approximation are supplied. 
dpend.m July 2005  Animation of double pendulum, and graphs of solution. sample image. 
3. Linear Algebra
3.a. Gauss Jordan elimination

directory listing  
rnd.m  Random matrices with integer entries in [0,N] or [N,N]. (MK July 2008). 
fitpoly.m  Polynomial interpolation (set up as system of linear equations, solve, plot). See hello.m and hellow.m for similar scripts with many more comments. 
hello.m  Very similar to fitpoly.m (this from summer 1999), but with more comments for MATLAB beginners. 
hellow.m  Analogous to hello.m, but with extensive comments for first time users. 
strangIIIe_2_3_17.m
2007 
Start w/ quadratic fit of 3 points, extend to npoints,
and generic basis functions, incl. plots.
Emphasis: Column picture, functions as columns. 
strangIIIe_2_4_26.m
2007 
Matrix multiplication as sum of outer products. 
strangIIIe_2_4_27.m
2007 
Product of two upper triangular matrices as sum of outer products. 
exa1.m  A semiautomatic example for GaussJordan elimination. Uses r1.m, r2.m, and r3.m. 
r1.m, r2.m, r3.m  Perform elementary row operations (mulitply by scalar, interchange two rows, add multiple of one row to another) 
rrefmovy.m  Like MATLABbuiltin rrefmovie, but does not clear screen at each step. Allows for scrolling back. 
hw1.m  Sample solution related to rref. 
hw11.m  Sample solution related to rref. 
hw12.m  Sample solution related to rref. 
mastquiz.m  rrefmovy applied to example of mastery quiz 
matlabintro.html  Beginner's tasks related to matrix multiplication and using MATLAB 
EM1.m, EM2.m, EM3.m  Creates elementary matrices corresponding to elmentary rowoperations. Typical use: construct LUfactorization via product of EM's. 
trigrank.m  Exploration of the linear dependence (numerical rank) of the set of functions {1,cos(x),cos(2x),cos^2(x)}. 
3.b. Linear Transformations
(linear combinations,
polygons)
, typically also uses
drawfig.m to create polygon.
(July 2000).
directory listing  
lincomb.m  Express any vector as a linear combination of two basis vectors. Draws grid corresponding to basis and overlays parallelogram. 
drawfig3.m  Draw a polygon creating an 3 x n matrix with ones in third row. Used as basic figure to explore affine trafo's. Reinforces concept of blockmuliplication (each column is one vertex). Use with ffill.m and pplot.m. 
drawfig.m  Draw a polygon creating an 2 x n matrix. Used as basic figure to explore linear trafo's. Reinforces concept of blockmuliplication (each column is one vertex). Use with ffill.m and pplot.m. 
ffill.m  Similar to fill.m, but using different data format: Vertices' coord's are columns of 2xn matrix as generated by drawfig.m 
pplot.m  Similar to plot.m, but using different data format: Vertices' coord's are columns of 2xn matrix as generated by drawfig.m 
lt2d.m  Overlays a polygon p (2 x n matrix) with its image A*p. Requires: ffill.m and pplot.m 
twoDexa.m  Defines a list of some 30 basic matrices to practice linking the numbers to the graphical roles. Typically used as initialization before using lt2d.m together with drawfig.m. (July 2000) 
rot.m  Generates 2x2 rotation matrix for given angle t.
Depending on whether t is <5 or > 5, the angle is
interpreted in radians or degrees.i
This intelligent version of the file is apparently misplaced 
lintrafo.m  Simple script that demonstrates (products of) matrices and the corresponding (compositions of) linear transformations of the plane. Uses simple polygons, then calls catt.m. 
catt.m  Using a cat's face, demonstrates linear transfo's of the plane that corresponds to given matrix (or to randomly generated matrix if called w/o parameters). 
3.c. Polygons (graphical tools, fun)
"Morphing" one polygon into another, e.g. a walking dinosaur
Polygons as ample regions for lin trafos,
and polygons as vector in 2ndimensions!
directory listing  
morph.m  Creates an animation that "morphs" one polygon into another (make sure numbers of vertices agree). Used as fun/relaxation when introducing more abstract vectors (each polygon is a point/vector in R^(2n)). 
dino.mat  .mat file from walking dinosaur. 
dino2.mat  
Xmas.m  Defines data for a polygon used as an exam polygon. Includes several comments. 
Xmassoln.m  Commented sample solution  find the affine transformation that transforms one given Xmas tree into another one. 
tree.txt  Email correspondence w/ journal article that started the tree fractals... 
origtree.m  Old: fractals and polygon's that look like real trees. 
origtri.m  
basetree.m  Old: fractals and polygon's that look like real trees. 
tree.m  Old: fractals and polygon's that look like real trees. 
3.d. Inner products:
GramSchmidt process,
Least squares approximations for "measured data points",
See section linalg/fourier for Fourier analysis of real data.
See images/compression for image compression via
svd (singular value decomposition).
directory listing  
gs3.m  Graphical illustration of GramSchmidt process: Starting with basis for R^3, show step by step each projection and each change of basis. (Updated Nov. 2003: fatter lines) 
mygs1.m mygs2.m mygs3.m mygs4.m mygs5.m 
A sequence of increasingly more sophisticated implementations of the
GramSchmidt process or QRfactorization. First script is simple transcript
of almost manual computaion w/ 3 vectors in 3space. Subsequent versions
add forloops, matrix products for projections, go from script to function
file, and finally also return the Rmatrix that records the successive
column operations. Note, in general no error checking (e.g. full col rank)
is performed.
Main use: In a class, as first programming experience  reference after the fact! Compare inclass exercise from MAT 342, fall 2003. with basis for R^3, show step by step each projection and each change of basis. (Updated Nov. 2003: fatter lines) 
leastsq.m  script for stepbystep soln of normal equns (data generated my mouseclicks). 2nd order Fourier approximation. uses drawfig.m 
uspop.m  Sample data: USpopulation each decade from 1790 to 1990. May be used for least squares fits. Note, quite surprisingly, while (dP/dt)/P is far from nearly constant, (dP/dt)/T is almost linear. 
directory listing  
3.e. Naive Fourier analysis
Naive Fourier analysis of 1Dsignals (real sound and electro cardiograms) and approximations of 2Dimages, i.e. functions z=f(x,y) See also Fourier analysis in PDE section 
Click here or on image for larger image. 
directory listing  
projectfourier.m  First example of projection, going from 3D to first Fourier example by identifying functions with long column vectors (size: 21 x 3). July 2008.  
fake.m  A quick demo of how the fft command works on a random 5th order trig polynomial. Illustrates the time and frequency (spectrum) domains graphically.  
heartbeat.html  General description of naive Fourier approximation of electrocardiogram. Compare parallel EXCEL worksheet more suitable for first explorations by students.  
ecg.tif  Sample image (rather poor quality) of 1 period of an electrocardiogram.  
ecgbw.tif  Sample greytone image (rather poor quality) of 1 period of an electrocardiogram. Use with ecgdigi.m to create data set for function approximation.  
ecgdigi.m  Graphical tool to digitize the (almost) hardcopy ecgbw.tif of an electro cardiogram as used by ecgfft.m.  
ecgdata.m  Sample digitization of electrocardiogram picture, used for function approximation with ecgfft.m.  
ecgfft.m  Reasonably fast (FFTbased ideas!) Fourier approximation of electro cardiogram. Uses ecgdata.m, and emphasizes graphical images of successive approximations.  
eric.m  Data for a real sound signal. Displays the sound graphically w/ scrolling window and exploratory FFT analysis. Nontrivial, realworld problem of shifting base frequencidea of windowingy!  
win.m  A leftover (?) looking at different windows of the sound data??? eric.m  
ericfft.m  FFT exploration of real sound data provided by EricBrewe.  
fourierpix.m  Naive implementation of Fourier approximation of a greyscale image. Uses default images einstein.gif (or in color: me.tif) , and displays sidebyside the greyscale image and the associated graph of a function of 2 variables. Key: Consider image as graph of function f(i,j) or f(x,y) 
3.f. Diagonalization
Eigenvectors and eigenvalues.
See linalg/lintrafo for more eigenvalues in 2Dplane.
See images/compression for svd used for image compression.
directory listing  
eigplot.m (1995) 2004 
Visualizing eigen vectors of 2 by 2 matrix: Appends respective images to the tip of large number of unit vectors. 
eignmovie.m (1995) 2004 
For 2 by 2 matrix animates a unit vector tracing out a circle, while its image traces out an ellipse. Vectors meet at eigendirections. 
nodet.m  Demonstration how to obtain the char poly w/o determinants, but rather from extracting dependency relations between iterates of random vector. 
eig3plot.m  An unfinished attempt to create an three dimensional version of eigplot.m using buckyballvertices for equally spaced unit vectors on the sphere. 
hw61.m  Sample solution related to diagonalization. 
hw61a.m  Sample solution related to diagonalization. 
hw62.m  Sample solution related to diagonalization. 
4. Working with images
4.a. Image compression

directory listing  
rose.tif  Sample image: A red rose as 64x56x3 .tif 
einstein.gif
einstein.tif einstein.xlsx (EXCEL !)  Sample image: Einstein's portrait as an 80 x 60 graysclae image. Used in several of the following examples as default image. 
me.tif  Sample image: My portrait as 84x60x3 .tif. Used in several of the following as default image. Problem: The image is still too large > hangups.... 
fasthaar2.m
invfasthaar2.m Aug 2008  "fast" Haar wavelet transform in 2D  unfinished, 1st experiments 
overwritiung the original matrix with its transform. Inverse is almost
the same code (one transpose, and reversed loop)  as should be expected!
For illustration use a 32 x 32 central section of einstein.gif, and play with the files (unfinished  need to add proper scaling): demohaar2.m hwv.m allhwvf.m allhwv.m 
svdpix.m  Image compression using singular decomposition.
Uses default image einstein.gif, and
displays sidebyside the original grayscale image and a sequence of increasingly better approaximations using naive SVD approximations. 
2010oct6.m  very first intro to image softening/sharpeining via left/rite multiplication/division by matrix. uses einstein.gif, compare also einstein.xlsx (EXCEL !) 
rasterpic.m  Image compression using rastering. Very crude implementation,
having lots of trouble with line breaks in file ????
Use to initiate discussion of "linear trafo", and matrix representations. Uses default image einstein.gif, and displays sidebyside the grayscale original and rastered images. 
directory
ipmovy.m ip.m basismovie.m basismovie.m maxcon.m vblock.m hblock.m dblock.m 
The first incomplete trial to create and visually display a set of matrices that are piecewise constant" (with very few pieces), and that form an intuitive orthonormal basis  so far the creation of the matrices and display work, but they are not ONB... need to do alittle math first; still the display in basismovy.m might be inspiring. This file uses hblock.m and vblock.m to create the matrices, and maxcon.m to rescale and shift them back to the usual colormap range and display them. 
5. Partial differential equations
5.a. Numerical soln of Laplace and heat equation

directory listing  
blur.m  A very naive implementation of a discretization of the heat or diffusion equation. Used to "blur" an image by smearing out the grey values. Uses me.tif as the default sample image. Use together with the MSWORD template blurme.doc to get a feeling for the structure of the very sparse matrix. 
randblur.m  Creates a random greyscale image and "blurs" and "unblurs"
the image via naive matrix multiplication (by inverse).
Sidebyside images.
Requires: blur.m (July 2000). 
blurpix.m  Illustration of (deterministically) blurring
an image. Very naive implementation that does not use the
sparse matrix structure, but rather tries to emphasize the
character of this effect as a linear transformation.
Requires: blur.m and default image einstein.gif. Main problem: Need to clip small region like blurme(30,20) as most computers hangup with full image that is too large. (July 2000, August 2004) 
sharpenme.m
sharpenpix.m 
Under reconstruction.
Complements blurme.m, exploring the inverse of the blurring matrix ("solving the heat eqn backwards"). Clips grey values at black/white but usually still crashes quite quickly. Requires: blur.m and default image me.tif. (July 2000) 
atcm98.gif  The official logo for the AsianTechConference 1998 in Japan: Starting from "atcm 1998" in any ordinary font, saved as a tiff image, I used MATLAB to solve the diffusion equation iteratively on the "complement" of the letters. The boundary data were u=0 at the edges of a rectangular box and u=1 on the letters  some magic coloring and overlay of a customized contourplot made a dramatic image which was widely seen on banners and is shown on the frontcover of the proceedings in full color. When I find a free minute I will provide documentation how to make the image.... 
5.b. PDEs using separation of variables and Fourier expansions
Fourier expansions
See also Fourier analysis in Linear Algebra section
directory listing  
current.m
matlab1.html sep7.m sep7a.m 
Real current data from industrial laser, see also the background EXCELspreadsheet. Summary of first day w/ MATLAB in class. Sample byhand numerical integration of Fourier coefficients. (Sept.2000), with sep7.m very simple code, and sep7a.m using a little slicker use of matrixproducts. 
step.m, saw.m, hat.m, myfun.m 
Sample function files whose names can be passed to the procedures below. 
simpson.m, fourcoeffs.m, fintegrand.m, fourpol.m, fapp.m, fsamples.m 
Several procedures to calculate Fourier coefficients and Fourier
approximations for functions that are given by formulas (as opposed to
functions given as data vectors in which case fft, ifft, etc. do the
corresponding job much more efficiently). The routines are not optimized,
instead meant to be reasonably transparent.
fourcoeffs.m calculates the Fourier coefficients using Simpson's rule which is coded in simpson.m (This circumvents the warnings in quad8() when that hits discontinuities). It requires the file fintegrand.m to create certain products... fourpol.m generates the corresponding Fourier approximation. fapp.m, creates a Fourier approximation (combining calculation of Fourier coefficients and constructing the associted trig polynomial). Sample uses, incl. plots of spectra and calling sequences are provided in fsamples.m. All of these are very new, and NOT YET thoroughly tested. 
heat1.m  Solution of heat equation via separtion of variables, animation of the Fourier approximations. (still unfinished) 
simpson.m, 
5.c. Wave and Laplace equation
d'Alembert's traveling wave soln of 1dim wave eqn
directory listing  
wave1.m  Animations (slices of 3d graph u(x,t) and simultaneous animation of (f(xct), f(x+ct), u(x,t) as functions of x paramterized by t. mfile takes as input any u(x,0)=f(x) data vector. 
wave2.m  Sidebyside animations of eigenmodes and combinations of linear
combinations of a vibrating membrane (2dwave equation on rectangle).
Input matrix of Fourier coefficients b(i,j) and up to two special
modes that are diaplayed in separate windows. Main animation plays
soln sum_(i,j) b(i,j)sin(i*x)sin(j*y)cos(sqrt(i^2+j^2)t).
Special attraction: Overlay two simple modes and get NONPERIODIV vibration. 
wave2disk.m  Very similar to wave2.m, but animating vibrations of a circular (disk) membrane. Experimental  have not doublechecked that all frequencies are indeed correct. Uses table of first 10 zeros of BesselJ(0, . ) through BesselJ(10, . ). 
6. Visualization in advanced math
6.a. Complex analysis

directory listing  
ccf.m
dcf.m dcfexa.m cdemo.m 
Some small updates April 2006 to ensure animation show in fixed window.
Addition of a driver to run usual examples.
Updated (2002, September) mfile to plot colormaps for functions of a complex variable; input either as formula (caution w/ arrayoperations), or as 1 x n or 2 x n numeric array for polynomial (taylor!) or rational (Laurent) functions. Many samples (incl. animations of convergence, and rootlocus plots) on helppage. See also Publications #39 for discussion in recent conference article. The new file dcf.m complements the colorplots of functions of a complex variable by visualizing their derivatives as fields of linear maps that act by "amplitwists" (c.f. Needham) on small squares. (dcfexa.m script with examples for dcf). Facilities to zoom, and color coding to detect/reject analyticity (conformality). 
icat.m
ccat.m cfill.m cplot.m 
Updated (2002, September) adaptations of similar files for visualization
of linear transformations from real plane (linear algebra, s.a.) to the
complex plane, w/ some new interactivity  e.g. select complex "multiplier"
by a mouseclick (in real case a 2x2 matrix need be entered via keyboard).
Still missing, an analogous adaptation of the file drawfig.m to generate (complex) polygons via mouseclicks.... 
laurentdemo.html  Sample images computed in MATLAB showing the convergence of a Laurent expansion of a rational function. The code might sometime be cleaned up ... Send email if you are interested in the implementation in MATLAB. 
6.x A special treat from
Tony Roberts
from the University of Southern Queensland.
Return to the top
directory listing
wiener.m
Zooming in on a random walk / Wiener process"
6.b. Differential Geometry
Return to the top
DiffGeom Spring 2000
AdvMathTech Spring 1998
Some classes (that utilized largely MAPLE) required every once in a while
much faster numerics and faster graphics  and MATLAB is the best choice here.
However, at this time I do not have any organized repository of these files
available for public use... The main MATLAB use was for generating imagery
similar to the
laurentdemo, but related to geodesic spheres etc. My goal is to
sometime code most of this in JAVA so that anyone can run it on the WWW,
w/o having to understand MATLAB code that was written for a onetimeuse.
6.c. control
Nonholonomic mechanical systems
attitude control of satellite,
planar robot ("falling cat")
Click here or on image
for larger view of sample screen.
Return to the top
ftpdirectory
Several files provide tools for
a very nice graphical interface allowing to enter
the control by drawing a curve, they display the lifted curves (holonomy)
and the physical motion of the robot.
pp.m
pp1.m
pp2.m
pp3.m
Dynmaic output feedback stabilization of Lotka Volterra predator prey system.
Very naive implementation  main purpose is illustration of the concepts,
and serve as first utility to allow playing w/ paramaters.
pp1.m linear feedback (incl. "restocking"),
pp3.m piecewise linear feedback (u=0 or u=kz),
pp2.m bangbang feedback (u=0 or u=k).
curv.m
(Not yet public). Colorplot curvature for optimal control and overlay
animation of geodesic spheres (initialized by mouseclick).
Compare the sample images shown shown here.