Matlab Codes for Math 445
Here is a sample Matlab code that solves Exercise 2.4.6 from
Meerschaert. This was the example we studied in class.
In order to run this code, download the file.
If you download it with the same name it has now, it is
called pc1.m. It is a regular text file. It can be opened
like any other text file, and modified with any text editor.
You should read the comments in the file (which start with %)
before running the program.
To run the code:
Open a matlab session. At the >> prompt, type either
opt=1 or opt =2. Then type "pc1" without the quotes.
Note that the .m extension is left off when running the program.
Sample code for LP
Driver for whale model (in class)
Equations for whale model (in class)
Save both files in the same directory. At the Matlab prompt >>, type dwhale
(without the .m extension). dwhale automatically calls whale from the program
Driver for Lorentz model (in class)
Equations for the Lorentz model (in class)
Save both files in the same directory. At the Matlab prompt >>, type drlor
(without the .m extension). drlor automatically calls lor from the program.
Sample code for final exam
If you are using a version of Matlab that does not have the exprnd or normrnd commands,
you can load the following data sets of random variables and use them. (See the command
"load" for more information.)
They are both in the form of a 5000 x 60 matrix of random numbers.\\
Data set of exponentially distributed random variables with mean 5
Data set of normally distributed random variables with mean 5
variance 25 (same variance as the exponentially distributed r.v.'s)
You should run the file with the objective of understanding how
different commands correspond to different parts of the calculations
in the optimization problem. To see the output of any command, remove
the ; from the end of the line - then the result of that command will
output to the screen. If you want the code to stop running at a particular
line (e.g. if you don't want to see all of the output) just include the
command pause or return following that line.
To edit the files, e.g. to change the parameters or equation definition:
Open the file with any text editor and make changes as you would to
any text file. Save with the .m extension.
To get online help from Matlab, type "help" followed by the topic or command name.
For example, "help plot" gives you all the different options for plotting.
Other useful help commands: "lookfor" followed by a keyword.
"help help" which lists all possible help directions.
Introductory guide to Matlab.
Mark S. Gockenbach:
A practical introduction to Matlab
Kermit Sigmon: Matlab tutorial.
Anthony Hodgson: Getting started with Matlab