Call Now: (800) 537-1660  
The Algebra Buster
The Algebra Buster


May 24th









May 24th

INTRODUCTION TO MATLAB

0. What is MATLAB?

MATLAB stands for matrix laboratory and is one of the most popular software for numerical
computation. MATLAB’s basic data element is an array (or matrix), which makes programming
to solve problems involving vector and matrix formulations (like those found in dynamic
equation systems of macro and econometrics) fairly straightforward.

MATLAB is de signed to solve problems numerically, that is, in finite-precision arithmetic.
Therefore it produces approximate rather than exact solutions , and should not be confused with a
symbolic computation system (SCS) such as Mathematica or Maple. It should be understood
that this does not make Matlab better or worse than an SCS; it is a tool designed for different
tasks and is therefore not directly comparable.

The following is a brief introduction to MATLAB aimed at getting you up and running. You
will almost certainly need to spend time at your computer with the MATLAB manual, help tools
of the program itself, and any other reference book you can find on the topic.

1. Finding Your Way Around MATLAB

Double-click on the MATLAB icon on your desktop. The MATLAB Desktop will open—this
is the Graphical User Interface for MATLAB. The desktop you see may include only one
window or may have two or three . One of the windows within the desktop (or the only one you
see) is called the Command window. This is where you will most often interact with MATLAB.
A prompt, >>, is displayed in the Command window followed by a blinking cursor, which lets
you know that MATLAB is ready to accept your commands.

Try typing the following:



The output should look like this:

ex1 =

This represents a 2x2 matrix of ones. Matlab inserts extra blank lines between practically
everything. To turn off this feature, type



To the left of the command window, we see Workspace and Current Directory window. While
the first shows the variables that are currently in MATLAB’s memory, second one simply shows
the contents of the folder that you are working in. The Workspace window shows you the
variables that you have created and, most notably, their dimensions. A variable in the
Workspace is available for use. On the bottom left you have Command History window – this is
where past commands are remembered. If you want to re-run a previous command you can
double click on it from this window (Right click on the command for more options.)

1.1 Help System

Easiest way to get help in MATLAB is to click on the question mark on the toolbar. This invokes
the help system of the software where you could go through the contents of its manual, search for
certain keywords and even watch some demos about how to use MATLAB.

If you know the name of a Matlab function you need help with, type



to see the help text contained in the function definition itself on Command window. This is a
better method for quick reference.

2. Syntax

Matlab works by executing the mathematical statements you enter in the command window. By
default, any output is immediately printed to the window.

You are also allowed to assign a name to an expression for your convenience. Keep in mind that
the name you assign is only a name, and it does not represent a mathematical variable (as it
would in Maple, for example). Every name must have a value at all times. If you try to read the
value of an unassigned name, you will get an error.

Nearly everything in Matlab is a matrix, whether it looks like it or not. This takes some getting
used to. We'll be introducing matrix-style operations along with their scalar counterparts so you
can understand the patterns that arise in the syntax.

2.1 Simple Math

MATLAB can do simple math just like a calculator; try typing:



Now hit “Enter”



MATLAB evaluates the command and returns the answer . You can also store the
numbers as variables and operate on them:



Note that MATLAB didn’t show that when you entered that variable. The
semicolon at the end of the command line tells MATLAB to evaluate the command but not
display the answer.

Another point is that usage of lowercase/uppercase letters matters in MATLAB:



Standard order of operations would apply when a string of calculations are typed up.

So use parenthesis if you need a certain order:



2.2 Built-in Functions

MATLAB has hundreds of pre-defined functions that you can use in your computations. Among
them are: trigonometric and inverse trigonometric functions (sin, cos, asin, acos,
atan, etc.), exponential function (exp), logarithm functions (log is log to base e, while
log10 and log2 are logs to bases 10 or 2.)

Matlab also has many other more sophisticated functions for solving linear equations, getting
eigenvalues of matrices, solving differential equations or calculating integrals numerically. Help
button is your friend!

3. Vectors and Matrices

Matlab is most used to work with matrices and vectors. Vectors are either row vectors or column
vectors and it is usually important to be clear as to what kind of vector you mean.

To create a row vector enter the name for the vector and the elements of the vector separated
by spaces (or commas) surrounded by square brackets .



To create a column vector, separate each element by a semicolon.



To enter a matrix, combine the row and column notation.

To extract parts of a matrix you can use one of the following commands:

- to display (or operate) on a particular element, row, or column of a matrix use its
address. The general syntax is matrixname(row#,column#).


Note that anything typed after a % sign is not evaluated. **Use this feature frequently when
writing programs in MATLAB!



The colon tells MATLAB to include all rows or columns.

- To extract a smaller sized matrix from an existing matrix use the address of the
desired elements:

- To extract the main diagonal use the command:



To delete rows and columns from a matrix use just a pair of square brackets:

Three special matrices that you’ll often use are the zero matrix, the identity matrix and
matrixes/vectors of ones.



 

Prev Next
 
Home    Why Algebra Buster?    Guarantee    Testimonials    Ordering    FAQ    About Us
What's new?    Resources    Animated demo    Algebra lessons    Bibliography of     textbooks
 

Copyright © 2009, algebra-online.com. All rights reserved.