Exp 1
Exp 1
Simple to use
Fast computations are possible
Wide working range
Solution of matrix of any order
Desired operations are performed in matrices
Different Programming languages can be used
Simulation is possible
:Basic Commands
:Addition
A+B
:Subtraction
A-B
:Multiplication
A*B
:Division
A/B
:Power
A^B
:Power Of each Element individually
A.^B
:Range Specification
A:B
:Square-Root
A=sqrt(B)
Where A & B are any arbitrary integers
a
s
e
a
.y as one command s
et's plot the result of our L
ector addition with grid v
.ines l
lot (b) P
rid on g
ATLAB can make other M
raph types as well, with axis g
.labels
bar(b)
xlabel('Sample #')
ylabel('Pounds')
MATLAB can use symbols in
plots as well. Here is an
example using stars to mark the
points. MATLAB offers a
variety of other symbols and
.line types
plot(b,'*')
axis([0 10 0 10])
One area in which MATLAB
.excels is matrix computation
:Creating a matrix
Creating a matrix is as easy as making a vector, using semicolons (;) to
separate
.the rows of a matrix
A = [1 2 0; 2 5 -1; 4 10 -1]
=A
0 2 1
1- 5 2
1- 10 4
:Adding a new Row
B(4,:)=[7 8 9]
=ans
0 2 1
1- 5 2
1- 10 4
9 8 7
:Adding a new Column
C(:,4)=[7 8 9]
=ans
7 0 2 1
8 1- 5 2
9 1- 10 4
:Transpose
.We can easily find the transpose of the matrix A
'B = A
=B
4 2 1
10 5 2
1- 1- 0
:Matrix Multiplication
.Now let's multiply these two matrices together
Note again that MATLAB doesn't require you to deal with matrices as a
collection of numbers. MATLAB knows when you are dealing with
matrices
.and adjusts your calculations accordingly
C=A*B
=C
24 12 5
59 30 12
117 59 24
:Matrix Multiplication by corresponding elements
Instead of doing a matrix multiply, we can multiply the corresponding
elements
.of two matrices or vectors using the’.* ‘ operator
C = A .* B
=C
0 4 1
10- 25 4
1 10- 0
:Inverse
... Let's find the inverse of a matrix
X = inv(A)
=X
2- 2 5
1 1 - 2-
1 2- 0
and then illustrate the fact that a matrix times its inverse is the ...
identity
.matrix
I = inv(A) * A
=I
0 0 1
0 1 0
1 0 0
MATLAB has functions for nearly every type of common matrix
.calculation
:Eigen Values
... There are functions to obtain eigenvalues
eig(A)
= ans
3.7321
0.2679
1.0000
:Singular Value Decomposition
The singular value decomposition
svd(A)
= ans
12.3171
0.5149
0.1577
:Polynomial coefficients
The "poly" function generates a vector containing the coefficients of
the
.characteristic polynomial
The characteristic polynomial of a matrix A is
p = round(poly(A))
=p
1- 5 5- 1
.We can easily find the roots of a polynomial using the roots function
.These are actually the eigenvalues of the original matrix
roots(p)
= ans
3.7321
1.0000
0.2679
.MATLAB has many applications beyond just matrix computation
:Vector Convolution
... To convolve two vectors
q = conv(p,p)
=q
1 10- 35 52- 35 10- 1
.Or convolve again and plot the result ...
r = conv(p,q)
;plot(r)
=r
1- 15 90- 278 480- 480 278- 90 15- 1
Matri
x
Manip
ulatio
:n
We
.start by creating a magic square and assigning it to the variable A
A = magic(3)
=A
6 1 8
7 5 3
2 9 4