10.10 Introduction to Chemical Engineering

NMM Chapter 2: Getting Started With MATLAB

The first thing you need to do is to get comfortable using Matlab. You need to give yourself a couple of hours to play with Matlab, sit down at an Athena terminal (or purchase and install Matlab on your PC), open Matlab up, and start running some demos. If you type
>> helpdesk
a Web page will open with links to all sorts of demos and reference information.

It is an excellent idea to type in the commands in NMM sections 2.1 and 2.2, to see what they do, and to get familiar with using the Matlab command line. (But don’t worry about the comparison with FORTRAN towards the end of 2.2). Experiment! Nothing you type will break the computer; if you get confused you can type

>> clear
which will erase all the variables you have defined, and give you a clean slate.

Pay attention to the use and special meaning of these symbols in Matlab, misuse can lead to confusing bugs:

; : ( ) [ ] ‘ “ %
Also, beware of the critical difference between * and .*, between / and ./, and between ^ and .^
Unless you intend to do a matrix operation or dot product, you will want to use the versions with the dots.

For scientific notation, type

>> y=4e8
not
>> y=4x10^8

Beware that Matlab is case-sensitive, i.e. capital letters and lower-case letters are usually treated as complete different, and essentially all of the functions provided by Matlab are written in lower-case only. If you type

>> help plot
Matlab will give you all sorts of documentation about how the Matlab plot function works. In the Matlab documentation, it refers to some functions using ALL CAPITAL LETTERS, but when you use those functions you must actually type them in lower case, not in capitals.

You can skip sections 2.3 and 2.4 the first time through. You definitely must learn how to make ordinary 2-d plots; sections 2.5.1 and 2.5.2 are a good introduction. Note that with the new version of Matlab, you can make all sorts of changes using the menu at top of the plot window, and double-clicking parts of the plot usually brings up an appropriate menu. The other sections of 2.5 can be skipped (until you need to make a fancy plot).

After you feel comfortable running single Matlab commands from the command line, you are ready to start saving a sequence of commands in a “script m-file” with a name that ends with .m; when you type the name of the script file on the command line (without the .m), Matlab executes all of the commands in the file. NMM Section 3.1 gives some good examples.


Next Chapter: Defining Functions
Back to Study Guide Index
Back to 10.10 home page
last modified: August 29, 2002