0% found this document useful (0 votes)
2 views

MAT Lab

The document outlines several MATLAB experiments focused on matrix and vector manipulation, including reshaping matrices, appending and deleting rows/columns, and concatenation. It also covers generating and plotting trigonometric functions, as well as using the linespace command to create vectors. Each experiment includes specific MATLAB commands and examples to demonstrate the concepts discussed.

Uploaded by

subapalani2001
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

MAT Lab

The document outlines several MATLAB experiments focused on matrix and vector manipulation, including reshaping matrices, appending and deleting rows/columns, and concatenation. It also covers generating and plotting trigonometric functions, as well as using the linespace command to create vectors. Each experiment includes specific MATLAB commands and examples to demonstrate the concepts discussed.

Uploaded by

subapalani2001
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

[EXPERIMENT NO: 4]

AIM OF THE EXPERIMENT:


Matrix formation and its manipulation.
EOUIPMENTS REOUIRED:
 Personal computer
 Operating system windows 8
 MATLAB Software-version IU007b
THEORY:
Reshaping the matrix as a differently sized matrix:
If a given matrix A is a (pXq) matrix it can be reshaped into a new (mXn) matrix, B as long
as total elements of the two matrices are same i.e. p*q=m*n . The reshaping command is
B=reshape (A, m, n)
Appending a row/column to a matrix:
Sometimes it is required that a column or a row to be added to a given matrix. A column can
be appended by using the following command;
A= [A; Y]
This will append the row vector y to the rows of existing matrix A.
Deleting a row/column of a matrix:
Rows and columns of a matrix can be deleted by setting the corresponding row or column
vector
Equal to a null vector i.e. a pair of empty square brackets [ ], without any element within the
brackets.
Concatenation of matrices:
Concatenation is a method of combining or joining small matrices together to make larger or
bigger matrices. The pair of square brackets [ ] is a concatenation operator.
MATLAB PROGRAMMING
Reshaping:
m=[1 2 3; 4 5 6; 6 7 8; 10 11 12]
m=
1 2 3
4 5 6
6 7 8
10 11 12
>>m=reshape(m,6,2)
m=
1 7
4 11
6 3
10 6
5 12
>>m=reshape(m,3,4)
m=
1 10 7 6
4 2 11 8
5 3 3 12
>>x=m(:)
x=
1
4
6
10
2
5
7
11
3
6
8
12
Appending new column
>>c=[1 3 5; 2 4 7; 3 5 8]
c=
1 3 5
2 4 7
3 5 8
>>d=[3 1 5; 7 2 4; 8 3 5]
d=
3 1 5
2 4 7
3 5 8
>>k=[c d]
k=
1 3 5 3 1 5
2 4 7 7 2 4
3 5 8 8 3 5
Appending new row
>>k=[c; d]
k=
1 3 5
2 4 7
3 5 8
3 1 5
7 2 4
8 3 5
Deleting row
>>a=[1 5 8 9; 7 9 5 1; 8 2 2 4]
a=
1 5 8 9
4 8 9 5
7 9 5 1
8 2 2 4
>>a(1,:)=[]
a=
4 8 9 5
7 9 5 1
8 2 2 4
>>a=(2:3,:)=[]
a=
4 8 9 5
Deleting column
>>g=[6 7 1; 8 9 2]
g=
6 7 1
8 9 2
>>g(:,2:3)=[]
g=
6
8
Concatenation
>>a=[1 2; 3 4]
a=
1 2
3 4
>>b=[a a+12; a+24 a+10]
b=
1 2 13 14
3 4 15 16
25 26 11 12
27 28 13 14
CONCLUSION:
DISCUSSION QUESTIONS:
2 −4 6 −3
Given A= 1 3 5 7
2 12 30 56
Write MATLAB statements to obtain
(i) All the elements of all rows but first column.
(ii) All the elements of first row but all columns.
(iii) Elements of second row and row.
[EXPERIMENT NO: 5]

AIM OF THE EXPERRVENT:


VECTOR MANIPULATION — Use of Linespace command to create vectors, add and subtract vectors.

EQUIPMENT REOUIRED:
 Personal computer
 Operating system windows 8
 MATLAB Software-version R2007b
THEORY:
Linespace - Generate linearly spaced vectors,
Syntax
Y = linespace(a, b)
Y = linespace(a, b, n)
Description
The linespace function generates linearly spaced vector. It is similar to the colon operator":",
but gives direct control over the number of points.
Y = linespace(a, b) generates a row vector y of 100 points linearly spaced between and
including a and b.
Y = linespace(a, b, n) generates a row vector y of n points linearly spaced between and
including a and b.
When executed, produces a vector having 5 equally spaced elements between the limits 0 and
10 given as follows a = [0 2 5 7.5 10.0]
MATLAB PROGRAMMING:
DISCUSSION OUESTION:
(i) Obtain the following products
a) AB b) ATA
3
Where A= 2 , B=[ 6 1 0 ]
1
3 0 −2
2 4
(ii) Find determinants and inverse of each matrices, A= , B= −1 1 2
8 −1
0 1 −2
[EXPERIMENT No: 6]

AIM OF THE EXPERIMENT:


Generation of the sin wave and use square root functions with vector arguments in MAT LAB.
EOUIPMENTS REOUIRED:
 Personal Computer
 Operating system windows 8
 MATLAB Software — version R2007b
THEORY:
1. Sin- Sin of argument in radians
Syntax
Y = sin(x)
Description
Example
y = sin(x) returns the sine of the elements of X. The sin function operates element-wise on
arrays. The function accepts both real and complex inputs. For real values of X in the interval
[-int. int], sin returns real values in the interval [-1,1]. For complex values of X, sin returns
complex values. All angles are in radians.

2. Sqrt – Square root


Syntax
B=sqrt(X)
Description
Example
B = sqrt(X) returns the square root of each element of the array X.

MATLAB PROGRAMMING
Plot the Sine function over the domain -x ≤ x ≤ x
x= -pi:0.001:pi:
plot(x, sin(x)), grid on
>>x=2:2
x=
-2 -1 0 1 2
>>y=sqrt(x)
y=
0+1.4142i 0+1.0000i 0 1.0000 1.4142

CONCLUSION
DISCUSSION QUESTION:
1. complete the following arithmetic questions

(i)

(ii) 𝑥 = 𝑡𝑠𝑖𝑛𝑡 , where t= vector element from 1 to 10
( )
(iii) 𝑧=
[EXPERIMENT NO: 7]

AIM OF THE EXPERIMENT:


Plotting and labelling of two - dimensional functions like sin(t), cos(t), tan(t), sec(t) etc for
a given duration.
EQUIPMENT REQUIRED:
 Operating System Window 10
 MATLAB software version R2007
 Personal Computer
THEORY:
1. Two - dimensional Plots
To draw a two - dimensional plot in MATLAB, the plot command is used. The syntax is given
as follows:
plot(x, y)
where,
x is a vector containing the x - coordinates of the plot and
y is a vector containing the y - coordinates of the plot.
2. Printing Labels
To make the plot more understandable, the two axes are labelled and a title is provided above
the top of the plot by using the following commands.
xlabel(‘string’) %Statement 1
ylabel(‘string’) %Statement 2
title(‘string’) %Statement
where,
Statement 1 uses the command xlabel to print label on the x - axis. The label to be
printed is enclosed in single quotes. Similarly, Statement 2 uses the command ylabel to print
the label along y - axis. The command title in Statement 3 is used to provide a title above the
top of the graph.
3. Grid
To give better illustration of the coordinates on the plot, a grid is used. The command
grid is used to show the grid lines on the plot. The grid on the plot can be added or removed
by using the on and off with the grid command. When grid command without any argument
is used alternatively, it toggles the grid drawn. By default, MATLAB starts with grid off.
MATLAB EXPERIMENT:
>>t=0:pi/2:3*pi;
>>y=sin(t);
>>plot(t, y);
>>area(t, y);
>>grid on;
>>xlabel(‘t’);
>> ylabel(‘sin(t)’);
>>title(‘plot of sin(t)’)

>>t=0:pi/2:3*pi;
>>y=cos(t);
>>plot(t, y);
>>area(t, y);
>>grid on;
>>xlabel(‘t’);
>> ylabel(‘con(t)’);
>> title(‘plot of cos(t)’);
>>t=0:pi/2:3*pi;
>>y=tan(t);
>>plot(t, y);
>>area(t, y);
>>grid on;
>>xlabel(‘t’);
>> ylabel(‘tan(t)’);
>> title(‘plot of tan(t)’);
>>t=0:pi/2:3*pi;
>>y=sec(t);
>>plot(t, y);
>>area(t, y);
>>grid on;
>>xlabel(‘t’);
>> ylabel(‘sec(t)’);
>> title(‘plot of sec(t)’);

CONCLUSION:
From the above experiment, we have successfully generated plots of trigonometric functions
like sint, cost, tant, sect etc for a given duration.

DISCUSSION OUESTION:
1. Write a program to plot the curve for a function described by the equation y=x3+2x2-5,
where x varies from -10 to 10.
x = -10 : 0.1 : 10
y = x3+2x2-5
plot (x, y);
axis ([-10x min 10 x max 0 y min 500 y max]);

You might also like