If you already know this stuff, skip ahead to the MATLAB Introduction.
The Math lab PC's use the LINUX operating system. LINUX is a "dialect" of UNIX, which means that if you already know one, you know the other. We're only going to need to know how to do use the operating system to perform some simple tasks, so that we can create places to work, store information in files, run programs like MATLAB, OCTAVE and NETSCAPE, and send mail.
To use any of the Math Lab PC's, you need to type in your Pitt username and password. Once the machine gives you access, you begin your session with a work area known as your home directory. You will be assigned a limited amount of space that you can arrange as you like, and which will be available to you the next time you log in, no matter which machine you log into. Your sessions always start in this place.
Unix organizes all the work areas of all the users into a hierarchical system. At the very top is a single directory called "/" or slash. Beneath this are subdirectories. On AFS systems, in which one set of files is shared by many computers, the very first subdirectory is called afs. On systems where the files are not shared, this first set of subdirectories might include /bin for certain executable programs, /lib for compiled program libraries, and /usr, where users (like us!) are put.
Each subdirectory can have further subdirectories beneath it. For instance, under the /usr directory there is probably a subdirectory called /local, which is referred to as /usr/local; the /man directory under that is /usr/local/man and so on. At some point in this system, Joe Blow's personal directory will show up, with a full name that might be:
Exercise: Your home directory has a "name". To find out what this name is, use the present working directory command:
There may already be a few files in your home directory. To see a listing of the files in your current directory, type:
lsFor more details, try the "long" listing:
We will often use Netscape to copy files from the Math 2071 web page. Let's try that now.
Exercise: start the Netscape program by typing:
netscapeInside of the program, specify my home page:
http://www.psc.edu/~burkardtOnce my home page is displayed, select the highlighted item Math 2071. Now, on the Math 2071 page, scroll down until you find the item root.m. Select this item, so that its text appears on your screen. Now save a copy of this file by going up to the Netscape File menu, and selecting Save or Save As.... Now exit the Netscape program.
Exercise: Use the ls command to verify that you have a new file root.m in your current directory. Use the ls -l command, and note whether the creation date seems reasonable. One number in the listing will also tell you how many characters are contained in the file. (There should be about 200.) The file size is a useful thing to know in case you exceed your disk quota and have to delete some files!
Exercise: One way to display a file is to use the more command. Try the command
more root.mroot.m is a very simple MATLAB file.
We will need to create our own text files using an editor program. If you have a favorite editor, and it's available on the lab machines, use it. Otherwise, there's a simple editor called xedit.
To enter or alter text is very simple, position the cursor in the desired location and click. You can highlight text to be cut and then paste it elsewhere or discard it.
Search is done using Control-S, and replace with Control-R. Other menu options allow you to save the file, read in a different file, or quit.
Exercise Create a file called branch.m using xedit. The file might contain the text:
for i = 1 : 10 x(i,1) = i; x(i,2) = root ( i ); end xWhen you're done, check your work by typing cat branch.m.
Occasionally, you will want to get rid of a file, either to clean up, or because you've exceeded your disk quota. Delete files with the rm ("remove") command:
rm file_nameYou can use wildcards, especially the "*", so that a command like
rm math*gets rid of all the files whose names begin with "math", while
rm *.mremoves files with the ".m" extension. The deadly command
rm *deletes all files in the current directory.
Exercise: Create an "empty" file by using the touch command:
touch einstein.fSimilary, create euler.f, and euclid.c. Now use a single rm command to get rid of euler.f, and euclid.c but not einstein.f.
You could store all your files in your home directory, but it's a better idea to make separate directories for various projects. Such a directory will be a "subdirectory" of your home directory; you can even make sub-sub-directories if you want. The subdirectories are like connected rooms of a house. You are always in one room of this house (your "present working directory"), but it's easy to move around.
To make a subdirectory of your current directory, use the "make directory" command:
Exercise: When using MATLAB or OCTAVE, it helps to have a subdirectory of your home directory which is actually called matlab. MATLAB will expect to find the programs you write in this directory. Create such a subdirectory now. Use the ls command to confirm that this worked. Now use the ls -l command, and see how the operating system reminds you that matlab is actually a subdirectory, and not a file.
If you ever want to delete a directory, the corresponding "remove directory" command is:
Once you've made a subdirectory, you'll probably want to put some files there. One way to do this is with the cp command. Two simple forms of the command are:
cp file copy_nameThe first command simply makes a copy with a new name. The second makes a copy, with the same name, but in a new place, that is, a subdirectory.
cp file new_place
Exercise: Let's try to place a copy of the root.m file in the matlab subdirectory:
cp root.m matlabYour first ls command should confirm that you still have the original file. The second one should show you that a copy has been placed in the matlab subdirectory.
More often, you actually want to move a file from one place to another. The mv command does that. Two simple forms of the command are:
mv file new_nameso we can think of the command as doing either a rename or a move.
mv file new_place
Exercise: Let's move the branch.m file to the matlab subdirectory:
mv branch.m matlabYour first ls command should confirm that you no longer have the original file in your home directory. The second one should show you that branch.m has been moved to the matlab subdirectory.
The reason you make a subdirectory is so you can stick a file there that you don't want to look at all the time. Now that root.m is in the matlab subdirectory, how could we access it? If we're careful typists, and we only need the file for a single command, we can use the filename with the subdirectory as a prefix:
Or we could copy the file back to our current directory, using the command:
cp matlab/root.m root.mIn this case, we might need to delete our copied file after we are done with it.
But in many cases, the easiest thing is to move your working directory to where the file is. The command to do this is the change directory command, or cd. To move to the matlab directory, we type:
cd matlaband now we can "see" all the files that are in that directory.
Exercise: move to the matlab directory, type out the file root.m, and use the ls command to see all the files there.
Once we're done in the subdirectory, how do we get back home? Again, there are a couple ways to do this. We could type one of the two commands:
cd .. (go up one level)The "go home" command can be used anywhere. You might need the "go up one level" command in cases where you have sub-subdirectories.
cd ~ (go home)
By the way, your current directory, whatever it is, has the special name of "." or dot. There's no reason to use this name with the cd command, (what would the command cd . do?) but we'll see its uses later.
Exercise: Use a version of the cd command to return to your home directory. Now use the "go up one level" command once. Where are you? How can you get back home?
If you know your way around the Pitt computing system, you may be able to get access to MATLAB directly. I think you need to log in on another machine, (though I'm not sure which one) and issue the commands
setup matlaband then, to run the program, you simply type:
setenv DISPLAY 128.182.37:0.0 (...you need your local machine number here.)
Otherwise, on the lab PC's, there is a "lookalike" program called OCTAVE. There are no special "setup" commands required for OCTAVE. You probably have to move to your matlab subdirectory and then start the program. Try typing:
cd matlabFor the basic commands we will normally need, it won't matter which one you use. However, OCTAVE is not a perfect copy of MATLAB. There are some nice features of MATLAB that are not available, and there are frequent cases where MATLAB behaves one way and OCTAVE another. Keep this in mind as one possible explanation for some of the problems and inconsistencies we will run into from time to time.
Exercise: try to run MATLAB or OCTAVE. If you have properly placed the files root.m and branch.m in the matlab directory, then you should be able to type the following commands while running MATLAB:
help rootTry these commands now. We'll talk about what they are doing later.
On the Math PC's, the mail program is called pine. You can use the mail program interactively, by typing
pinein which case you will see a menu of options that allow you to compose a message, specify a recipient, append a text file, or exit.
Assignment: Use the date command to get the current date and time, then write a mail message:
"I have completed lab #1 at current date and time."and mail this message to me.