Mathematics University of Queensland Mathematics

Introduction to Matlab


Graeme Chandler



1  Introduction.

1.1  Learning Matlab

Matlab is one of the fastest and most enjoyable ways to solve problems numerically. The computational problems arising in most undergraduate courses can be solved much more quickly with Matlab, than with the standard programming languages (Fortran, C, Java, etc.). It is particularly easy to generate some results, draw graphs to look at the interesting features, and then explore the problem further. By minimizing human time, Matlab is particularly useful in the initial investigation of real problems; even though they may eventually have to be solved using more computationally efficient ways on super computers.

This introduction gives a quick way to become familiar with the most important parts of Matlab. The first five sections emphasize simple arithmetic, matrix-vector operations (including solving systems of equations), and graphing functions and data. The later sections describe some more advanced features, including 3D graphics. There are also some suggestions about using Matlab to do larger projects, and including Matlab results and graphs in reports.

The best way to used this introduction is to sit down at a computer and type in the commands as they are described. Look at Matlab's response, and check that the answers are what you expect. It is also a good idea to do the small exercises. It makes sure that the commands become part of an active Matlab vocabulary. Each lesson should take less than one hour. More information about any Matlab command can be found by using the on line help features described in lesson 3.

These notes assume basic familiarity with the Windows interface.. For instance, you need to know about

If you are unsure about this, seek help from another student or tutor.

1.2  Further References

The complete Matlab Manuals are available on line in the Mathematics department's PC laboratories. They contain an introductory guide for new users, and an especially good introduction to Matlab's graphics.

More information on Matlab can be found in the books

  1. D.M. Etter; Engineering Problem Solving with Matlab, Prentice-Hall, 1993.

  2. Duane C. Hanselman & Bruce Littlefield; Mastering MATLAB 5: A Comprehensive Tutorial and Reference, Prentice Hall, 1998

  3. Kermit Sigmon, A Matlab Primer, 4 th Ed. 1995

or try the Mathworks web site
http://www.mathworks.com

If you wish to use Matlab at home, the student edition of Matlab is available from bookshops at the cost of about $100.00 (or you can borrow a copy from the library.) The student version is `crippled' and only works for small problems. Nevertheless, it should suffice for almost all assignments in undergraduate courses. It is usually possible to develop a program on the student version and do the final full size problem on the Mathematics Department's computers if necessary.

1.3  Starting Matlab

Here we describe the steps needed to start Matlab on the PC's in the Mathematics Computer Laboratories (Rooms 519 and 420). On other machines the start-up procedure will be different. However the Matlab commands are the same on all machines.

  1. First sit down at a PC. If necessary, close any programs left running by a previous user. The simplest way is to use the Windows `Start' button then the `Shut Down' option.

  2. When prompted, use the [Ctrl]-[Alt]-[Del] combination to bring up the logon screen. (You will be asked for a name and password, but ignore this and just press the [Enter] key.)

  3. You should now see the standard Windows desktop with a screen of icons.

  4. Find the icon labelled `Matlab' and double click on it. After another pause, the Matlab logo appears briefly, then the `MATLAB Command Window' remains on the screen. It ends with the words:-

 
To get started, type one of these commands:
          helpwin, helpdesk, or demo.
For information on all of the MathWorks products, type tour.
 
>>
 

Matlab is now ready!

1.4  Typing Commands

All commands to Matlab are typed in after the Matlab prompt, i.e.\. the symbol > > . They are then sent to Matlab to be implemented by pressing the [Enter] key.

Usually errors are not noticed until Matlab beeps and displays an error message. However it is not necessary to retype the whole command.

Now go on to the first lesson. Type in all the commands as they are shown, and make sure the Matlab response is what you expect.

Exercise 1

Type in the Matlab command logo . A nice 3D graph of the Matlab logo should appear. This is produced by advanced use of Matlab's graphics capabilities, discussed later.