Fa17 Bce 037 - La00

You might also like

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

Obtained Max

COMSATS University Islamabad, Abbottabad Campus


10
Department of Electrical and Computer Engineering

Lab Assignment No. 00: Matrix Manipulations

Class/Subject: BCE-7A/Digital Image Processing Due Date: September 28, 2020 (11:59 pm)

Name: Muneeb Ur Rehman Registration#_FA16-EPE-066

Note: Your report must consist of code below each question and a well commented program listing.
 Email your complete report in MS Word format at: zahid0987@cuiatd.edu.pk.
 Name of your report must be your registration number. For instance, FA17__BCE__xx__LA00
(replace xx with your registration number)

1. Define a matrix A of order 1×5 and display its 3rd member.


Solution:
Code:
A= [1 24 31 4 5];
A(3)
Output:
ans = 31

2. Take the transpose of a matrix A of order 1×5 and display its 3rd member. (use A=A.’ to take transpose)
Solution:
Code:
B= [61 71 81 91 101];
B=B.'
B(3)
Output:
B=
61
71
81
91
101
ans = 81
3. Define a 5×5 matrix and display its 3rd row and 3rd column members only. (use : to access all rows or
columns)
Solution:
Code:
C=[1 2 3 4 5; 6 7 8 9 10; 111 121 131 141 151; 16 17 18 19 20; 21 22 23 24 25];
C(3,:)
C(:,3)

Output:
ans = 111 121 131 141 151
ans =
3
8
131
18
23

4. Take a 3×3 matrix and compute its determinant and inverse. Also use the tic toc command to show the
time required to compute the inverse. Use det and inv commands to get a solution.

Solution:
Code:
tic
D=[1 2 3; 4 4 6; 4 2 7];
x=det(D)
y=inv(D)
toc
Output:
x = -16
y=
-1.0000 0.5000 0
0.2500 0.3125 -0.3750
0.5000 -0.3750 0.2500
Elapsed time is 0.001269 seconds.
5. Take a 4×3 matrix and show its order. (use size command to know) then replace all the values of your
matrix with zeros (use zeros command in Matlab).
Solution:
Code:
E=[11 12 13; 14 15 16; 17 18 19; 20 21 22];
[r c]= size(E)
x= zeros(r,c)
Output:
r=4
c=3
x=
0 0 0
0 0 0
0 0 0
0 0 0

6. An image in the Matlab is interpreted as a matrix. Read the image moon.jpg, show its order, display it on
your screen, and rotate the moon.jpg image by 45 0 clockwise. (Use imread, imshow, imrotate commands to
complete your task). Use title command to label the input and rotated image. Please use help imrotate
command in MatLab. Also show how much time your system takes to rotate the moon image.
Solution:
Code:
tic
img1 = imread('moon.jpg');
[r c] = size(img1)
subplot(121)
imshow(img1);
title('Original Image of moon')
subplot(122)
img2 = imrotate(img1,-45,'bilinear','crop');
imshow(img2);
title('Moon image rotated at 45 degrees ')
toc;
Output:

Original Image of moon Moon image rotated at 45 degrees

r = 538
c = 464
Elapsed time is 0.446768 seconds.

7. Create a matrix A, any size and shape you want, and fill it with arbitrary values. Compute AAT and ATA.
The results should be square, symmetric matrices. (Hint: use the rand command in MatLab to create a
random matrix of specified order).

Solution:
Code:
F=rand(2,3);
F*F'
F'*F
Output:
ans =
1.7345 0.9644
0.9644 1.0943
ans =
1.1518 0.8349 0.8482
0.8349 0.6606 0.4675
0.8482 0.4675 1.0165

You might also like