FF505/FY505 - Computational Science - MATLAB Section

Getting Started

This short note is for getting you started with the computer system at the IMADA terminal room, where the matlab sessions will take place.

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 machine using your IMADA account. It is not the same as your SDU account. Those of you who do not have an IMADA account will be provided one by logging in at this page.

(Note, it is possible to use in the study group hours also the machines in the room U26B. You log in to those machines with your SDU account. Once logged in, you can use Matlab from those machines. Note that those machines are just clients booting from a remote server. When you log out all your data are lost. You can copy back and forth data from your IMADA system with the command: scp -Y login1.imada.sdu.dk:FF505 ..)

  1. Change your password in the IMADA account. To do this, go 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.
  2. Create a folder in your home directory called FF505:
    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.

  3. Never forget to log out using the button on the top right! Your data will remain saved in your IMADA home directory and will be there when you log in again.

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 Linux 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.
  1. 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.
  2. 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.
  1. Quit Matlab by typing in the command window exit or quit.

Printing source code

You should try to avoid printing code since you will not gain much from reading it in black and white on a paper rather than with color highlights on the screen. However, if you really need you can print source code by using the matlab editor or some text processing software. 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.

Date: 2014-02-04T18:58+0100

Author: Marco Chiarandini

Org version 7.9.3f with Emacs version 24

Validate XHTML 1.0