Beruflich Dokumente
Kultur Dokumente
Exercise No. 1
Introduction to MATLAB and its basic commands
OBJECTIVES
EQUIPMENT
Quantity
1 PC with MATLAB Software per student
BASIC
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 Plots
2-D & 3-D Plots
Some basic MATLAB commands are given as follows: Where A & B are any arbitrary integers
Addition:
A+B Adding an element to a Vector:
b=a+n
Subtraction:
A-B Show Grid
grid on / off
Multiplication:
A*B Plotting
Plot (variable)
Division: Plot (variable, symbol)
A/B
Axis
Power: axis([X Y])
A^B
Adding a new row in a matrix
Power Of each Element individually: B(row,:) = [ ]
A. ^B
Transpose
Range Specification:
B= A
A: B
Polynomial coefficients
The "poly" function generates a vector containing the coefficients of the characteristic polynomial
p = round(poly(A))
roots( )
Vector Convolution
q = conv(p,p)
nMagic square
M = magic(n)
M = magic(n) returns an n-by-n matrix constructed from the integers 1 through n^2 with equal row and column sums. The
order n must be a scalar greater than or equal to 3.
This is called a magic square because the sum of the elements in each column is the same.
sum(M)
PROCEDURE
Creating a Vector:
1. Lets create a simple vector with 9 elements called a or name your vector in any variable. Write your output below.
______________________________________________________________________________________________________
______________________________________________________________________________________________________
______________________________________________________________________________________________________
__________________________________________________________________
2. 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. Write the result and your observation.
______________________________________________________________________________________________________
______________________________________________________________________________________________________
______________________________________________________________________________________________________
______________________________________________________________________________________________________
______________________________________________________________________________________________________
3. Plot the result of our vector addition with grid lines. Draw the output graph.
4. Make a plot of the result of the vector using bar graph. Draw the output graph.
5. Mark the points of the graph on procedure no. 3 using asterisk symbol and define the axis X 0 10; and Y 0 10 respectively.
Creating a matrix:
1. Create a 3 x 3 matrix; name your matrix in any variable. Write your code and output below.
1 2 0
2 5 -1
4 10 -1
__________________________________________________________________________________________________
__________________________________________________________________________________________________
__________________________________________________________________________________________________
__________________________________________________________________________________________________
__________________________________________________________________________________________________
__________________________________________________________________________________________________
2. Add a new row in your matrix and store it in a new variable. Write your code and output below.
__________________________________________________________________________________________________
__________________________________________________________________________________________________
__________________________________________________________________________________________________
__________________________________________________________________________________________________
Matrix Multiplication:
5. Multiply the two matrixes. The original matrix and transpose matrix
______________________________________________________________________________________________________
______________________________________________________________________________________________________
______________________________________________________________________________________________________
______________________________________________________________________________________________________
8. Then illustrate the fact that a matrix times its inverse is the identity matrix.
__________________________________________________________________________________________________
__________________________________________________________________________________________________
__________________________________________________________________________________________________
__________________________________________________________________________________________________
Eigen Values
10. Obtain the singular value decomposition of the matrix in procedure no. 1
__________________________________________________________________________________________________
__________________________________________________________________________________________________
__________________________________________________________________________________________________
__________________________________________________________________________________________________
Polynomial coefficients
11. Generate the polynomial of matrix in procedure no. 1 and determine its roots.
__________________________________________________________________________________________________
__________________________________________________________________________________________________
__________________________________________________________________________________________________
__________________________________________________________________________________________________
Vector Convolution
13. Convolve the vector from the procedure no. 11 to the result of problem no. 12 and plot the result.
__________________________________________________________________________________________________
__________________________________________________________________________________________________
__________________________________________________________________________________________________
__________________________________________________________________________________________________
14. Obtain the Magic square of the matrix in procedure no. 1. And the sum.
__________________________________________________________________________________________________
__________________________________________________________________________________________________
__________________________________________________________________________________________________
__________________________________________________________________________________________________
GENERALIZATION
1. Explain the importance of knowing the basic MATLAB instructions and command; How MATLAB requires no
special handling of vector or matrix math.
__________________________________________________________________________________________________
______________________________________________________________________________________________________________
______________________________________________________________________________________________________________
______________________________________________________________________________________________________________
______________________________________________________________________________________________________________
______________________________________________________________________________________________________________