Skip navigation
The Australian National University

Laboratory 1 - Matlab, Control Flow and Version Control

Aim

The aim of this lab is to get you familiar with Matlab and the Matlab programming environment. You will also write a few programs in Matlab that expose you to basic Matlab sytax, conditional execution, loops and keyboard input. It will also introduce you to using a version control system, which is important since you will be using this approach to submit your assignments.

If you cannot do all of the tasks during the lab, then please complete them outside of the lab hours. Questions can be brought up in the forums, or during the next lab.


Matlab Introduction

Preparation

Please go through the slides for lectures 1-5. As well, read chapters 1, 2 and 4 of the textbook. Try out the examples covered in the lectures and the text book.

Tools

The primary tool that you will need is the matlab programming environment. To use this, you will need to logon to a computer in one of the Computer Science labs, open up a terminal window and type the following from the command line:

matlab

Instructions

Write matlab programs that perform the following tasks. Make sure that you save your answers in scripts. Run the scripts using the matlab tool.
  1. Finds the surface area of a sphere, given its radius.
  2. Finds the volume of a cylinder, given its radius and height.
  3. Finds the surface area a barbell in the metric system, given the radius of each of the two spheres in inches and the length of the bar in feet. Check that the answer is correct by working through an example manually. Are any assumptions being made? Do you need any other data?
  4. Finds the final grade as one of HD, D, CR, P and N, given the final mark. Do this using the if statement. Can you use the switch statement for the same purpose? Modify your program so that it takes input from the keyboard. Are any assumptions being made in this case? Use the debug facility to step through the code.
  5. Finds the final mark for this course, given the marks for the two assignments, the two lab tests and the final exam. The program should take input from the keyboard for all of the above components. Use the ceil function to round off the answer. Check that the answer is correct by working through an example manually. Document your code so that it is clear what your program is doing. Ask the person sitting next to you to go through you code and provide feedback on the documentation.
  6. Study the random function rand. Use this to simulate a coin toss over a specified number of tries. From the data, find out the probability of the result being heads. What happens to this result as the number of tries increases?


Version Control

Preparation

Version control (or revision control) refers to the management of changes to information stored as computer files. Various types of information can be put under version control such as computer programs, documents and configuration files. It is really useful to use a version control tool for all your work, be it work done by yourself or in a group. It allows you to track changes and revert to earlier versions, when required. It is essential for collaborative projects. Please go through the wikipedia page on version control. You will learn more about version control during the lectures on Software Engineering.

In this exercise we will use the Subversion version control system to demonstrate the advantages of using version control in your daily work. Read the Red Bean Book for a very good introduction to Subversion. In particular, read the first two chapters.

Getting help

Subversion is already installed on the student system. Log on to the system using your uni ID and password. Open a terminal window. We will use command line to type subversion commands. The Subversion command line client is called svn. Type:

    $svn help
and see what you get. This gives you access to the client's documentation. Now type:
    $svn help import
This gives you the details of the import command.

Creating a repository

Svn stores its files in repositories. We will first create a directory called svn under which we will store all our repositories. To do this, make sure that you are in your home directory and then type:

    mkdir svn
This will create a directory called svn in your home directory. Do not touch this directory or its contents. We will now create a repository for engn2219 in this directory as follows:
    svnadmin create svn/engn2219

Creating a working copy and doing some work

We now need to create a working copy of this directory, which is where we will do all our engn2219 related work. We do this as follows (replace uxxxxxxx with your student number):
    svn checkout file:///students/uxxxxxxx/svn/engn2219
This will create a directory called engn2219 under our home folder. Make this our current directory by:
    cd engn2219
Make a directory called labs and a directory underneath this called lab1 as follows:
    mkdir -p labs/lab1
Schedule this directory to be added to the repository:
    svn add labs
Note that this adds labs as well as everything underneath it to the repository. Commit the changes:
    svn commit labs
This will open up an editor and ask you for a message to go with the commit. Enter an appropriate message and complete the commit. Change directory to lab1:
    cd labs/lab1
Create two files called test1 and test2 using your favourite editor, with some content. Schedule these for addition to the repository. Examine your changes:
    svn status
Commit the files. Note the revision numbers. Make some changes to one of the files and use svn status to examine the status of the files.

Making changes and recovery

Change one of the files. Use the svn diff command to see your changes. Commit this file.

Change the other file. Now, use the svn revert command to go back to the last committed version of the file.

Delete one of the files. Now, use the svn update command to get back the deleted file. Note that this can work at the directory level as well.

Use the svn log command to get a log of the changes committed to the repository. You can use svn log test1 to look at the changes for test1. The version numbers are also listed in the log. Use svn update -r to revert to a particular revision of a file. Run svn help update to get the documentation for the update command.

Try some other commands listed in Chapter 2 of the Red Bean Book. Place some of your own files under version control. You can use the svn import command to bring existing directories under version control. Chapter 2 of the book has an example.

Windows commands and their Linux equivalents

For those who are a little rusty on Windows or Linux, the following table lists Windows commands and their Linux equivalent.

WindowsLinux
cdcd
copycp
delrm
dir/wls -a
typecat

Updated:  Fri Jun 14 14:28:30 EST 2013 / Responsible Officer:   JavaScript must be enabled to display this email address. / Page Contact:   JavaScript must be enabled to display this email address.