22-03-2014, 12:50 PM
A Beginner’s Guide to MATLAB
MATLAB.pdf (Size: 533.4 KB / Downloads: 24)
INTRODUCTION
MATLAB, which stands for MATrix LABoratory, is a state-of-the-art mathematical software
package, which is used extensively in both academia and industry. It is an interactive program
for numerical computation and data visualization, which along with its programming capabilities
provides a very useful tool for almost all areas of science and engineering. Unlike other
mathematical packages, such as MAPLE or MATHEMATICA, MATLAB cannot perform
symbolic manipulations without the use of additional Toolboxes. It remains however, one of the
leading software packages for numerical computation.
As you might guess from its name, MATLAB deals mainly with matrices. A scalar is a 1-by-1
matrix and a row vector of length say 5, is a 1-by-5 matrix. We will elaborate more on these and
other features of MATLAB in the sections that follow. One of the many advantages of
MATLAB is the natural notation used. It looks a lot like the notation that you encounter in a
linear algebra course. This makes the use of the program especially easy and it is what makes
MATLAB a natural choice for numerical computations.
The purpose of this tutorial is to familiarize the beginner to MATLAB, by introducing the basic
features and commands of the program. It is in no way a complete reference and the reader is
encouraged to further enhance his or her knowledge of MATLAB by reading some of the
suggested references at the end of this guide.
MATLAB at Loyola College
MATLAB runs from ANY networked computer (e.g. your dorm room, the Math Lab in KH 318,
etc). To access it, go to the MetaFrame Presentation Server, located at
http://www.loyola.edu/moresoftware/ , and login using your Groupwise username and password
- if your Groupwise password will not work then try you student ID number as a password. Once
you login you will see a folder with applications, MATLAB being one of them. Double-click on
the MATLAB icon and off you go ... Note: It is possible that the first time you do this, you may
have to install some client software on your PC. Simply follow the instructions on the webpage
(after you login) and you should be fine
PROGRAMMING IN MATLAB
M-files: Scripts and functions
To take advantage of MATLAB’s full capabilities, we need to know how to construct long (and
sometimes complex) sequences of statements. This can be done by writing the commands in a
file and calling it from within MATLAB. Such files are called “m-files” because they must have
the filename extension “.m”. This extension is required in order for these files to be interpreted
by MATLAB.
There are two types of m-files: script files and function files. Script files contain a sequence of
usual MATLAB commands, that are executed (in order) once the script is called within
MATLAB. For example, if such a file has the name compute.m , then typing the command
compute at the MATLAB prompt will cause the statements in that file to be executed. Script
files can be very useful when entering data into a matrix.
Function files, on the other hand, play the role of user defined commands that often have input
and output. You can create your own commands for specific problems this way, which will have
the same status as other MATLAB commands. Let us give a simple example. The text below is
saved in a file called log3.m and it is used to calculate the base 3 logarithm of a positive
number. The text file can be created in a variety of ways, for example using the built-in
MATLAB editor through the command edit (that is available with MATLAB 5.0 and above),
or your favorite (external) text editor (e.g. Notepad or Wordpad in Microsoft Windows). You
must make sure that the filename has the extension “.m” !