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
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.