Professional Documents
Culture Documents
Matlab - s3 Ec 2019
Matlab - s3 Ec 2019
S3 ECE
MATrix LABoratory
● Software package for high-performance numerical computation and
visualization
● MATLAB has since been expanded and now has built-in functions for
solving several types of scientific computations.
MATLAB environment
● The Workspace
● Dimensioning: automatic
x = 2;
abc_123 = 0.005;
2ab = 5;
Error ???
SPECIAL VARIABLES
● pi Value of π
● eps Smallest incremental number
● inf Infinity
● NaN Not a number e.g. 0/0
● i and j i = j = square root of -1
● realmin The smallest usable positive real number
● realmax The largest usable positive real number
OPERATORS
not ~
Less Than <
and &
Less Than or Equal <=
or |
Greater Than >
Add +
Greater Than or Equal >=
Subtract -
Equal To ==
Multiply *
Not Equal To ~=
Divide /
Lesson 1
Calculator
»2+2
»x=2+2
» format long
EXERCISE
● Arithmetic operations :
○ 25 / (25 - 1 ) ○ 1 .0323
○ (1 - (1/25)) - 1 ○ 1 .0323
○ [ 3 ( √5 - 1) / (√5 + 1 ) 2 ] - 1 ○ -0.6459
○ Area = 𝛑r2 with r = 𝛑(⅓) - 1. ○ 0.6781
● Complex numbers :
○ (1 + 3i )/ (1 - 3i )
○ e(𝞹i / 4 ) ○ -0.8000 + 0.6000i
○ exp (pi/2*i)exp (pi/2i) ○ 0.7071 + 0.7071i
○ 0.0000 + l .OOOOi
○ 0.0000 - l .OOOOi
Elementary Math functions
r1 and r2 specify the beginning and ending rows and c1 and c2 specify
the beginning and ending columns to be extracted
EXAMPLE
>> X = [1, 2, 3 ; 4, 5, 6 ; 7, 8, 9] >> X13 = X(3,1:3)
X= 1 2 3 X13 = 7 8 9
4 5 6
7 8 9
1
4
Matrix Extension
>> a = [1, 2i, 0.56]
>> a = [1,2;3,4]
a = 1 0+2i 0.56
a= 1 2
3 4
>> a(2,4) = 0.1
a = 1 0+2i 0.56 0
>> a_cat =[a, 2*a ; 3*a, 2*a]
0 0 0 0.1
a_cat =
1 2 2 4
>> b = [1,2;3,4] 3 4 6 d8
b= 1 2 3 6 2 4
3 4 9 12 6 8
>> b_rep = repmat(b,1,2)
b_rep = 1 2 1 2
3 4 3 4
Matrix Addition
y= 6 7
8 9 xsz shows error due to
dimension mismatch of x and z
Matrix Multiplication
>> c = b*a
c= 4 6
>> c = a*b
Error ??
Matrix Element wise operations
Plot sin(x) and cos(x) over [0,2π], on the same plot with different colours
Plot the following function
y = t, 0 <= t <=1
= 1/t , 1 <= t <=6
Subplots
Syntax: subplot (rows, columns, index)