Académique Documents
Professionnel Documents
Culture Documents
MAM1043H
What is MATLAB?
MATrix LABoratory
MATLAB is a numerical computing
environment (Google)
Useful for numerical scientific and
engineering calculations
MANY useful toolboxes available for a
wide variety of applications.
Command Window
For entering commands
So what do I do???
MATLAB behaves like a really cool calculator!
(That can be programmed to perform complex
calculations)
Simply enter commands in the command window.
Try:
>>5*3
>>sin(pi/2)
Statements
A statement is some instruction for the
computer to perform some task.
Example:
>>a=2
Statements
Can then modify a variable:
>>a=a*3
Key Idea:
Variables will keep their value until some instruction
is given to change it.
Addition: >>a=2+3
Subtraction: >>a=2-3
Multiplication: >>a=2*3
Division: >>a=2/3
Powers: >>a=2^3
Variables
Rules for variable names:
Consist of letters (a..z), numbers (0..9) and
underscore ( _ )
Must start with a letter (a..z)
Variables are case sensitive, so velocity and
Velocity are different variables!
Types of Variables
Scalars:
>>a=2
Vectors:
>>v=[1 2 3]
Matrices:
>>A=[1 2 3; 4 5 6; 7 8 9]
Key Idea:
All variables in MATLAB are matrices!!
Operations on Vectors
For the vector:
>>v=[1 2 3]
Operations on Vectors
The power operation gives an error! Why??
Does this make sense?
>>[1 2 3]^2
which means
>>[1 2 3]*[1 2 3]
How do we multiply vectors together? Is there a
unique way of doing this?...
The answer is NO!!
Array Operators
Performs operation on each component in
two vectors (must be the same size!):
>>[1 2 3].*[1 2 3]
>>[2 8 27]./[1 2 3]
>>[1 2 3].^2
Constructing Arrays
Use the colon : operator:
>>x=1:10
Built in functions
MATLAB has many built in functions, for
example:
Trigonometric (sin(),cos(), etc)
Exponentials, logs (log(),exp())
Roots (sqrt())
Plotting (plot(),surf(), etc)
Vector product (dot(), cross() )
plus more
And you can create your own!! (Later.)
Plotting Graphs
Must create vectors to plot:
>>x=0:pi/10:2*pi;
>>y=sin(x);
Colours, etc:
>>plot(x,y,r);
>> plot(x,y,rx);
Still to come
Creating our own functions.
How can we solve linear system of
equations?
Making decisions and repeating steps.