0% found this document useful (0 votes)
56 views7 pages

Exp 1

This document discusses the basics of MATLAB including its functions, benefits, basic commands and matrix operations. It demonstrates how to perform operations like addition, subtraction, multiplication and division on matrices and vectors. It also shows how to plot graphs, find eigenvalues and perform other matrix calculations in MATLAB.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views7 pages

Exp 1

This document discusses the basics of MATLAB including its functions, benefits, basic commands and matrix operations. It demonstrates how to perform operations like addition, subtraction, multiplication and division on matrices and vectors. It also shows how to plot graphs, find eigenvalues and perform other matrix calculations in MATLAB.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

EXPERIMENT NO: 01

Introduction to MATLAB and its basic commands


:MATLAB
This is a very important tool used for making long complicated calculations
and plotting graphs of different functions depending upon our requirement.
Using MATLAB an m-file is created in which the basic operations are
performed which leads to simple short and simple computations of some
.very complicated problems in no or very short time
:Some very important functions performed by MATLAB are given as follows
 Matrix computations
 Vector Analysis
 Differential Equations computations
 Integration is possible
 Computer language programming
 Simulation
 Graph Plotation
 2-D & 3-D Plotting
:Benefits
:Some Benefits of MATLAB are given as follows

 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

:Basic Matrix Operations


.This is a demonstration of some aspects of the MATLAB language
:Creating a Vector
.Lets create a simple vector with 9 elements called a
a = [1 2 3 4 6 4 3 4 5]
=a
5 4 3 4 6 4 3 2 1
Now let's add 2 to each element of our vector, a, and store the result in
a new
.vector
Notice how MATLAB requires no special handling of vector or matrix
.math
:Adding an element to a Vector
b=a+2
=b
765686543
:Plots and Graphs
Creating graphs in
MATLAB
i
s

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

Eng / Abdulsalam alhaboob

You might also like