0% found this document useful (0 votes)
107 views8 pages

Introduction To Matrices in Matlab LAB # 02

This document describes a lab assignment on matrices in MATLAB. The objectives are to learn various matrix functions in MATLAB including indexing, submatrices, element operations, and generating random signals. The document provides examples of tasks completed in the lab, including generating matrices from other matrices using addition, subtraction, and other operations. It also demonstrates how to create submatrices by selecting certain rows and columns from a given matrix. Built-in functions for rounding, summing, finding products, and determining matrix size and length are explored.

Uploaded by

Hurair Mohammad
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)
107 views8 pages

Introduction To Matrices in Matlab LAB # 02

This document describes a lab assignment on matrices in MATLAB. The objectives are to learn various matrix functions in MATLAB including indexing, submatrices, element operations, and generating random signals. The document provides examples of tasks completed in the lab, including generating matrices from other matrices using addition, subtraction, and other operations. It also demonstrates how to create submatrices by selecting certain rows and columns from a given matrix. Built-in functions for rounding, summing, finding products, and determining matrix size and length are explored.

Uploaded by

Hurair Mohammad
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/ 8

INTRODUCTION TO

MATRICES IN MATLAB
LAB # 02

Spring 2020
CSE301L Signals & Systems Lab

Submitted by: Hurair Mohammad


Registration No. : 18PWCSE1657
Class Section: B

“On my honor, as student of University of Engineering and Technology, I have neither given nor received
unauthorized assistance on this academic work.”

Student Signature: ______________

Submitted to:
Engr. Durr-e-Nayab
Date 3/03/2020

Department of Computer Systems Engineering


University of Engineering and Technology, Peshawar
OBJECTIVES OF THE LAB:
 Built in Matrix Functions
 Indexing Matrices
 Sub Matrices
 Matrix element level operations
 Round Floating Point numbers to Integers
 Lenth of matrix.
 Size of matrix.

-------------------------TASK 01--------------------------
Problem Analysis:
We have to make a new matrix B from A by the following condition.
Algorithm:
 We have given a matrix say A and to make another say B.
 Copy the column of A not changing any element.
 Subtract column 1 of A from column 2 of A ,it will be the second column of B.
 Subtract column 2 of A from column 3 of A ,it will be the third column of B.
Code:
%Matrix A
disp('Matrix A is: ')
A=[13 6 9;1 4 8;2 8 17 ]
%Matrix B
disp('Matrix B is: ')
B=[A(:,1),A(:,2)-A(:,1),A(:,3)-A(:,2)]

OUTPUT:

Figure 1 output

Discussion and Conclusion:


From the above we conclude that we make a new matrix B by subtracting the columns of A. C2-C1=B2, C3-
C2=B3,C1=B1.
-------------------------TASK 02--------------------------
Problem Analysis:
To generate random discrete time signals.
Algorithm:
 First we take variable and generate random discrete time signals from 1 to 2500.
 The take another variable and generate the same discrete time signals from 1 to 2500.
 Then take third variable and add the previous signals.
CODE:
%Signal Number 1
disp('1st Signal: ')
signal_1=rand(1,2500)
%Signal Number 2
disp('2nd Signal: ')
signal_2=rand(1,2500)
%Resultant
disp('Sum of signal_1 and signal_2: ')
resultant_signal=signal_1+signal_2
OUTPUT:

Figure 2

2.3 SUB-MATRICES:
Code:
>> x = [0.0:0.1:2.0]';

>> y = sin(x);

>> [x y]

Output:
Discussion and Conclusion:
By doing this we learnt that we can add two-rand signal and we can add it to each other’s.
-------------------------TASK 03--------------------------
A note on colon notation
Problem Analysis:
Generate the sequences.
Algorithm:
 First we have to generate the sequence.
 To write side it goes up to 69.75 and to left side it goes to -65.25.
 The difference between each corresponding element will be 7.5.
CODE:
%Generate the Sequence difference b/e each two element is 0.25
X=-65.25:7.5:69.75
OUTPUT:

Figure 3

Discussion and Conclusion:


We conclude that we cane generate the sequence from any point to any point and we can fix the distance
between two point.
-------------------------TASK 04--------------------------
SUB MATRICES:
Problem Analysis:
We have to make matrices from the given matrices by addition, subtraction etc.
Algorithm:
 We take two matrices A and B.
 Simply add, subtract, multiply, divide, exponential take sin and square root of A with B.
A=[-12,34,61,-9;65,78,90,12; 14,78,45,12; 60,25,3,8]
B=[34,67,8,9; 12,-91,12,9; 89,-8,0,2; 16,9,23,67]
CODE:
disp('Array Addition: ')
C=A+B
disp('Array Subtraction: ')
D=A-B
disp('Array Multiplication using .* operator;: ')
E=A.*B
disp('Array Division using ./ operator: ')
F=A./B
disp('Array Exponentiation using .^ operator: ')
G=A.^B
disp('Sin of Matrix A: ')
H=sin(A)
disp('Square Root of B: ')
I=sqrt(B)
disp('Product of H and I: ')
J=H*I
OUTPUT:
Discussion and Conclusion:
We can add, subtract, multiply, divide and the most important is take sin of each element of ant matrix and
also square root.
-------------------------TASK 05------------------------
Problem Analysis:
We make sub matrices from the given matrices.
Algorithm:
 We make matrix B from A by removing the 1st column from A and take the remaining element
and the resultant matrix will be 4x3.
 Matrix C from A by removing the 1st row from A and take the remaining element and the
resultant matrix will be 3x4.
 Matrix D from A by removing 1st column and last three rows of matrix A the resultant matrix will
be 2x3.
CODE:
disp('Matrix A: ')
A=[3 7 -4 12;-5 9 10 2;6 13 8 11;6 13 8 11;15 5 4 1]
disp('Elements in the second through fourth columns of A: ')
B=A(:,2:4)
disp('Elements in the second through fourth rows of A: ')
C=A(2:4,:)
disp('Elements in the first two rows and the last three columns of A: ')
D=A(1:2,2:4)

OUTPUT:

Figure 7
Discussion and Conclusion:
We can drive sub matrices from ant matrix. We can select the any rows and column from the matrix and
thus is the conclusion of the given task.
-------------------------TASK 06--------------------------
Problem Analysis:
To check built in function round, ciel, floor and fix.
Algorithm:
 Take a matrix f of values floating point.
 Then apply all the above function.
CODE: OUTPUT:

Discussion and Conclusion:


We can round off any floating values. And thus we have done with the task.
-------------------------TASK 07--------------------------
Using sum and prod built in function.
Algorithm:
 Take a matrix A.
 Apply the formula sum(A) it will add columns wise element.
 Apply the formula prod(A) it will multiply columns wise element.
 Find the size by typing size(a).
 Find the length by typing length(a).
CODE:
%Matrix A
disp('Matrix A: ')
A=[-3 5;4 8]
%Add element column wise
disp('After using sum(A): ')
B=sum(A)
disp('After using prod(A): ')
%Product element column wise
C=prod(A)
%Length
disp('Length of Matrix A: ')
length(A)
%Size
disp('Size of Matrix A: ')
size(A)

OUTPUT:

Discussion and Conclusion:


We can find the size and length of any matrix.
We can find the sum and multiplication of the two matrix.

You might also like