You are on page 1of 4

Lab Assingment:1

Q.1. Create a symmetric matrix m with five rows and five columns. Calculate its
transpose and verify that the matrix is symmetric by observing that m=m.
Solution:
m=
5
1
2
3
7

%creating symmetric matrix


1
2
3
7
3

2
3
7
3
2

3
7
3
2
1

7
3
2
1
5

>> m'

%taking transpose of matrix

ans =
5
1
2
3
7

1
2
3
7
3

2
3
7
3
2

3
7
3
2
1

7
3
2
1
5

>> a=m-m'

%m=m
%m-m=0

a=
0
0
0
0
0

0
0
0
0
0

0
0
0
0
0

0
0
0
0
0

0
0
0
0
0

Q.2. Create a random matrix with 3 rows and 5 columns. The matrix values should
be integer b/w (0100), than change its all 2 rows values by 7.
Solution:
a=randint(3,5,[0,100])
a=
65
82
66

34
29
34

53
73
31

84
57
37

%creating random matrix


70
55
44

%fixing or replacing 1St two rows elements

a(1:2,1:5)=7
a=
7
7
61

7
7
76

7
7
82

7
7
79

7
7
17

Q.3. Use your knowledge to define a vector by incrementing


and also cascade more than one vector to form a matrix try to
make a matrix with the following properties.
(1) Matrix should contain 2 rows.
(2) First row of matrix should contain even number b/w (010)
(3) Second row of matrix should contain odd number b/w (11
20)
Solution:
b=
2

10

>> c=[11:2:20]
c=
11

13

15

17

19

8
17

10
19

>> mat=[b ; c]
mat =
2
11

4
13

6
15

calculate

(a) c=d+e
(b) (b) c=d-e
(c) (c) c=d*e
(d) (d) c=d/e
(e) Note: multiplication and division should be done element
by element.
Solution:
clc
clear all
close all
d= [1+2j 3 ; 7
d=

% clears desktop
% Removes all variables and functions
% Closes all the open windows
5j ]
1.0000 + 2.0000i
7.0000

e= [2+3j 5+5j ; 0 1-8j]


e=
2.0000 + 3.0000i
0

3.0000
0 + 5.0000i
5.0000 + 5.0000i
1.0000 - 8.0000i

c=d+e
c=

3.0000 + 5.0000i
7.0000

8.0000 + 5.0000i
1.0000 - 3.0000i

(b) c = d-e
d= [1+2j 3 ; 7
d=

5j ]
1.0000 + 2.0000i
3.0000
7.0000
0 + 5.0000i

e= [2+3j 5+5j ; 0 1-8j]


e=

2.0000 + 3.0000i
0

c=

-1.0000 - 1.0000i
7.0000

5.0000 + 5.0000i
1.0000 - 8.0000i

c=d+e

(c) c=d*e
d= [1+2j 3 ; 7

5j ]

-2.0000 - 5.0000i
-1.0000 +13.0000i

d=

1.0000 + 2.0000i
7.0000

3.0000
0 + 5.0000i

e= [2+3j 5+5j ; 0 1-8j]


e=

2.0000 + 3.0000i
0

5.0000 + 5.0000i
1.0000 - 8.0000i

c=

-4.0000 + 7.0000i
0

15.0000 +15.0000i
40.0000 + 5.0000i

c=d*e

(d) c=d/e
d= [1+2j 3 ; 7
d=

% Creating 1st 2*2 matrix

5j ]

1.0000 + 2.0000i
7.0000

e= [2+3j 5+5j ; 0 1-8j]


e=
c=d/e
c=

3.0000
0 + 5.0000i

% Creating 2nd 2*2 matrix

2.0000 + 3.0000i
0

5.0000 + 5.0000i
1.0000 - 8.0000i

% Creating new matrix by dividing


0.6154 + 0.0769i
0.3000 - 0.3000i
Inf
-0.6154 + 0.0769i

Q.5. Plot the function


y=3*exp (3*pi*t);
Choose t from (0---150) with increment of 0.001
Solution:
clc
clear all
close all
t=0:0.001:150
y=3*exp(3*pi*t)
plot (t,y)
xlabel (time')
grid on

% clears desktop
% Removes all variables and functions
% Closes all the open windows
% Time for given function will be
% Generating the function
% plotting the signal
% Labeling the X-axis
ylabel ('Amplitude')
% Labeling the Y-axis
% start grid On

You might also like