Introduction To Matlab: Luke Dickens
Introduction To Matlab: Luke Dickens
Introduction To Matlab: Luke Dickens
Part 1
Luke Dickens
The Basics
Built-in Functions
Plotting
Overview
Matlab is an intuitive, easy-to-learn, high performance language for
numerical computation and data visualisation. It can handle:
3 The language
High-level language based on arrays, functions, input/output, and flow
statements (for, if, while)
4 Graphics
Data plotting in 2d and 3d, as well as image analysis and animation tools
5 External interfaces
Interaction between C and Fortran programs with Matlab, either for linking
convenient routines from Matlab in C/Fortran, or for Matlab to call fast C/Fortran
programs
Different ways to use Matlab
1 Interactive mode
just type commands and define variables, empty workspace with command
clear
2 Simple scripts
M-file (name.m) with list of commands
Operate on existing data in work space, or create new data
Variables remain in workspace (until cleared)
Re-useable
3 M-file functions
M-file as with scripts
May return values
Re-usable
Easy to call from other functions (make sure file is in Matlab search path)
Introduction
The Basics
Built-in Functions
Plotting
Variables
So for example,
» B’+C
ans =
5 8 11
13 16 19
but
» B+C
??? Error using ==> plus
Matrix dimensions must agree.
We also have elementwise multiply (.*) and divide (./). With
elementwise division, be careful that there are no zero
elements in the second matrix. Why?
The elementwise power operator (.^), applies a power to each
element of a matrix.
Matrix Multiplication
Mx = 0 ⇒ x = 0
Summary of Arithmetic Operators
+ addition
- subtraction
* multiplication
^ power
\ left division
/ right division
.* elementwise multiplication
.^ elementwise power
.\ elementwise left division
./ elementwise right division
’ transpose
Comparison Operators
As with addition and subtraction. Relational operators can be
applied to a scalar and a scalar; a matrix and a scalar; or to two
matrices of the same dimension. The following are available:
< less than
> greater than
<= less than or equal
>= greater than or equal
== equal
~= not equal
Boolean values (or matrices) may be connected by the
following logical operators.
& and
| or
~ not
You will explore these in the lab.
Introduction
The Basics
Built-in Functions
Plotting
Built-in Functions
The Basics
Built-in Functions
Plotting
The plot Function
y yellow . point
m magenta o circle
c cyan x x-mark
r red + plus
g green - solid
b blue * star
w white : dotted
k black -. dashdot
-- dashed
Multiple Plots
• Overview of Matlab
• Vector and matrix construction
• Working with vectors and matrices
• Commonly used built in functions. Including:
• Special functions
• Operations on scalars, vector and matrices
• A focus on plotting
References