FF505/FY505 - Computational Science - MATLAB Section

Getting Started

This short note is for getting you started with the computer system at IMADA terminalrum for use during the course FF505.

IMADA Terminalrum

The computers at IMADA run a version of the Linux operating system called "Ubuntu" with "Gnome" as the default desktop. It is operated similarly to other Linux distributions, to Mac OS X, and in many ways also to Windows. Please go through the following list to set up your account for use with FF505:

  1. Log into a terminal room machine using your IMADA account. If you did not receive an account yet, please contact the servicedesk or Marco Chiarandini as soon as possible. (Note, for the computers in the room U26B you need a different account and you need to contact Dariosh N.~Rizi from IT-service.)
  2. Change your password, by going to Applications -> Accessories -> Terminal: This starts a terminal prompt, where you can interact with Linux. Write yppasswd and follow the instructions to select a new password. Your password should have at least 8 characters and include lower-case letters, upper-case letters, and digits.
  3. Create a folder FF505 for the course:
    mkdir ~/FF505
    

    You can change into the folder by using cd FF505 from your home directory. If you are unsure whether you are in your home directory, just type pwd to find out where you are and cd to change to your home directory. It might be useful to create some subfolders for individual weeks, projects etc.

  4. Never forget to log out using the button on the top right!

Starting Matlab

  1. Start Matlab. If you are on a Windows systems, Matlab should be under the "Start" menu or often there is a shortcut on your desktop. On a Linux/UNIX system, open a terminal and type matlab &. On a Mac, double click on the "MATLAB R2012a" icon located in your Matlab directory in Applications.
  2. No matter what system you're on, once Matlab starts, you will get exactly the same thing. In particular, you will get the Matlab Desktop made of the Command Window, and probably several other Matlab windows like Workspace and History.

Command Basics

  1. The Matlab command window is the center of the Matlab universe. The job of the command window is to sit there blinking, waiting for you to type something. Your job is to enter commands that tell Matlab what to do. This is very much like working from a UNIX or DOS command prompt.
  2. Try a few commands, eg, 1+1 or some more complicated expressions. Matlab interprets parentheses in the usual, algebraic way. Compare the answers for 10-2*3 vs. (10-2)*3. What's different and why?
  3. Now, let's create some variables. Type ten=10 and hit return. You can now enter ten instead of 10 in the expressions above. Try it. Matlab has a few built-in constants like pi (3.1416).
  4. Variables like ten and pi are known as scalar variables. A more interesting class of variables are arrays. Enter arr1d=[1 5 10] at the command prompt. You have now created a table of numbers with 1 row and 3 columns and given it the name arr1d. To get numbers out of arr1d you use parentheses: arr1d (3) should return 10. As its name implies, arr1d is a one-dimensional array. 1D arrays are also known as vectors, and vectors can be both row vectors (like arr1d) or column vectors. To turn arr1d into a column vector, type arr1d=arr1d' ; The ; prevents Matlab from printing the output, this is useful for big arrays and if you already know the answer. To verify that arr1d is now a column, just type its name to see it printed.
  5. Let's create a 2D array: arr2d=[1 2 3; 9 8 7]. The semicolon ";" tells Matlab to start a new row. To access data in arr2d, we need to use two numbers, e.g. arr2d(j,k), where j specifies the row and k specifies the column. What do you need to type to access the 8 in arr2d? Try replacing the 8 with –8.
  6. In a typical Matlab session, you will create several variables, and its important to know what variables are in your workspace and their sizes. To list the contents of your workspace, type whos. If you have a variable that you no longer need, you can delete the variable by typing clear = followed by the name of the variable (or variables you want to delete). Type =clear ten and then whos to make sure ten is gone. Type clear to clear everything.
  7. Quit Matlab by typing in the command window exit or quit.

Printing source code

You can print source code by using the matlab editor or some text processing software. But for a good result, consider using the command a2ps at your terminal prompt:

a2ps -Pd3 hello.m

a2ps is an abbreviation for "Anything to PostScript" and -Pd3 specifies that you want to use the printer "d3" outside the terminal room.

Author: Marco Chiarandini <marco@imada.sdu.dk>

Date: 2013-01-31 07:52:45 CET

HTML generated by org-mode 6.33x in emacs 23