Lab Report 2
Lab Report 2
Lab Report 2
ENGINEERING
THEORY
MATLAB (Matrix laboratory)
MATLAB (matrix laboratory) is a fourth-generation high-level programming language
and interactive environment for numerical computation, visualization and programming.
It allows matrix manipulations; plotting of functions and data; implementation of
algorithms; creation of user interfaces; interfacing with programs written in other
languages, including C, C++, Java, and FORTRAN; analyse data; develop algorithms;
and create models and applications.
It can perform the following functions
3
IN LAB TASKS
In this lab we study about different command of MATLAB use to perform operation on the
matrices and the polynomials.
The commands with their functions are listed below
1. WHO
this command shows the variable you have used for example, if you have used 50 variables and
now you want to know about all of those
2. WHOS
This command tells you about format of variable.
3. CLEAR
This command clear all the variable
4. CLEAR X
this command clear that variable x
a =2; b =3;
a +b;
a-b;
a*b);
a/b;
4
a=3;
a/5= 0.600
format long (15 decimal places)
a/5= 0.600000000000
8. CONTROLLING SPACE
format loose,
format compact
5
12. MATRIX INDEXING
To access single element
a= [3 2 1
765
9 4 8]
a(3)
ans=9;
6
15. TO ACCESS SINGLE COLUMN
a(:,3)
Ans=1
5
8
a(:,2:3)
Ans= 2 1
65
48
from second row to third
a(2:3,:)
Ans= 2 6 5
948
7
17. DELETING A ROW
A(2,:)=[]
8
22. Transpose of matrix
b=a. '
0 0
0 0
9
26. ones(m,n) Returns an m-by-n matrix of ones
ones(2,3)
ans =
1 1 1
1 1 1
10
28. Concatenation of matrices
Matrices can be constructed in a block form. With C defined by
b=[6 7;1 2]
b=
6 7
1 2
>> c = [b zeros(2); ones(2) eye(2)]
c=
6 7 0 0
1 2 0 0
1 1 1 0
1 1 0 1
11
CREATING A POLYNOMIAL USING COEFFICIENTS:
The ‘poly’ function in MATLAB can be used to create a polynomial using a vector of coefficients.
The vector of coefficients should be in descending order of power of the polynomial.
For example, the vector [2, 4, 3] would represent the polynomial 2*x^2 + 4*x + 3.
Root of polynomial
r= roots(P)
Polynomial from root
P=poly(r)
Addition of polynomial
Subtraction of polynomial
6 5 3
>> p2=[9,8,7]
p2 =
9 8 7
>> p1.*p2
ans =
12
54 40 21
>> p1./p2
ans =
Root of polynomial
r= roots(P)
Polynomial from root
P=poly(r)
13
REFERENCES
1.https://www.tutorialspoint.com/matlab/matlab_overview.htm
14