Math 485 (Sect 2) -- Mathematical Modeling

[ Tutorial page | Course home page ]

Section 1: MATLAB basics

Matrix notation:
>> [1 2; 3 4; 5 6]
gives
ans =

     1     2
     3     4
     5     6
a 3x2 matrix.

A vector is just an Nx1 (column) or 1xN matrix:

>> [1 2 3]

ans =

     1     2     3

>> [1;2;3]

ans =

     1
     2
     3
Operations on matrices include

Variables

You can store matrices and numbers in variables, like so:
>> a=[1 2; 3 4]

a =

     1     2
     3     4

>> b=[1 3 ; 5 7]

b =

     1     3
     5     7

>> a+b

ans =

     2     5
     8    11

Functions

MATLAB's built-in functions can apply to numbers or matrices (or vectors):

>> cos(pi)

ans =

    -1

>> cos([-pi 0 pi])

ans =

    -1     1    -1
Aside from basic functions like sin, cos, exp, MATLAB also has a number of important operations on matrices.

Last updated on February 4, 2008 by Kevin K. Lin