Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

SNS Lab 1

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

Signals & Systems Lab Department of Electrical & Computer Engineering

Lab 01-Introduction to MATLAB


Task 01:

MATLAB Code:
% Task 1: Create a vector a and b
a = 0:0.1:10;
b = cos(0:0.2:20);

% Compute the following:

% a. C where Ci = ai/bi.
C = a ./ b

% b. d where di = ai^4
d = a .^ 4

% c. The element-wise product of a and b.


element_wise_product = a .* b

% d. The dot product of a and b.


dot_product = dot(a, b)

Output

Registration No: FA22-BSEE-035


Signals & Systems Lab Department of Electrical & Computer Engineering

f= 46.0507

Task 02:

MATLAB Code:
% Task 2: Create a 3 × 3 matrix with all its elements randomly distributed
in [0, 1].
A = rand(3);

Registration No: FA22-BSEE-035


Signals & Systems Lab Department of Electrical & Computer Engineering

% a. Compute the inverse of the matrix.


A_inv = inv(A);

% b. Compute the transpose of the matrix.


A_transpose = A';

% c. Compute the determinant of the matrix.


A_det = det(A);

% d. Compute the size of the matrix.


A_size = size(A);

% Display the results


disp('The original matrix A is:'), disp(A)
disp('The inverse of matrix A is:'), disp(A_inv)
disp('The transpose of matrix A is:'), disp(A_transpose)
disp('The determinant of matrix A is:'), disp(A_det)
disp('The size of matrix A is:'), disp(A_size)

Output:

Registration No: FA22-BSEE-035


Signals & Systems Lab Department of Electrical & Computer Engineering

FIGURE 1 RESULTS OF COMPUTING THE MATRIX

Registration No: FA22-BSEE-035


Signals & Systems Lab Department of Electrical & Computer Engineering

Task 03:

MATLAB Code:
% Define the matrix x
x = [1/4, 1/4, 5/4; -1, 2, 1; -5/4, -1/4, 15/4]

% Use the eig function to compute the eigenvalues and eigenvectors


[V, D] = eig(x)

% Display the eigenvalues and eigenvectors


disp('The eigenvalues of the matrix are:'), disp(diag(D))
disp('The corresponding eigenvectors are:'), disp(V)

Output:

Registration No: FA22-BSEE-035


Signals & Systems Lab Department of Electrical & Computer Engineering

FIGURE 2 EIGENVALUES AND EIGENVECTORS OF THE MATRIX X.

Lab Analysis:
In this lab we study about the how to use Matlab in our engineering field . In
this lab we get introduce to matlab deeply study and use different commands . we come to
know how to create vectors and apply different operations on them and study different
commands and check there results similarly we come to know how to create different
matrices and how to apply different operations on them I.e how to get dot product etc.

Registration No: FA22-BSEE-035

You might also like