Question# 01:-
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’.
Matlab Code:
clc
clear all
close all
display('Symmetric Matrix with 5 rows and 5 columns');
m=pascal(5)
display('Transpose of symmetric Matrix');
x=m'
display('Comparison of the two Matrices');
m==x
Results:
Symmetric Matrix with 5 rows and 5 columns
m =
1 1 1 1 1
1 2 3 4 5
1 3 6 10 15
1 4 10 20 35
1 5 15 35 70
Transpose of symmetric Matrix
x =
1 1 1 1 1
1 2 3 4 5
1 3 6 10 15
1 4 10 20 35
1 5 15 35 70
Comparison of the two Matrices
ans =
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
Question# 02:-
Create a random matrix with 3 rows and 5 columns. The matrix values should be integer b/w (0—100), than change its all 2 rows values by ‘7’.
Matlab Code:
clc
clear all
close all
display('Random Matrix with 3 rows and 5 columns');
r=rand(3,5)
display('Integer b/w 0-100');
i=100*r
display('Fixing Elements of the Matrix');
f=fix(i)
display('Changing its 2 rows elements by 7');
f(1:2:3,:)=7
Results:
Random Matrix with 3 rows and 5 columns
r =
0.4120 0.4399 0.2126 0.1338 0.6299
0.7446 0.9334 0.8392 0.2071 0.3705
0.2679 0.6833 0.6288 0.6072 0.5751
Integer b/w 0-100
i =
41.1953 43.9924 21.2560 13.3773 62.9888
74.4566 93.3380 83.9238 20.7133 37.0477
26.7947 68.3332 62.8785 60.7199 57.5148
Fixing Elements of the Matrix
f =
41 43 21 13 62
74 93 83 20 37
26 68 62 60 57
Changing its 2 rows elements by 7
f =
7 7 7 7 7
74 93 83 20 37
7 7 7 7 7
Question# 03:-
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 (0—10)
(3) Second row of matrix should contain odd number b/w (11—20).
Matlab Code:
clc
clear all
close all
display('First vectors with even numbers 0-10');
x=[2 4 6 8 10]
display('2nd vectors with odd numbers 11-20');
y=[11 13 15 17 19]
display('Cascading the two vectors');
c=[x;y]
Results:
First vectors with even numbers 0-10
x =
2 4 6 8 10
2nd vectors with odd numbers 11-20
y =
11 13 15 17 19
Cascading the two vectors
c =
2 4 6 8 10
11 13 15 17 19
Question# 04:-
Calculate
(a) c=d+e(b) c=d-e(c) c=d*e(d) c=d/e
Note: multiplication and division should be done element by element.
Matlab Code:
clc
clear all
close all
d=[1+2j 3;7 5j];
e=[2+3j 5+5j;0 1-8j];
display('(a)');
c1=d+e
display('(b)');
c2=d-e
display('(c)');
c3=d.*e
display('(d)');
c4=d./e
Results:-
c1 =
3.0000 + 5.0000i 8.0000 + 5.0000i
7.0000 1.0000 - 3.0000i
(b)
c2 =
-1.0000 - 1.0000i -2.0000 - 5.0000i
7.0000 -1.0000 +13.0000i
(c)
c3 =
-4.0000 + 7.0000i 15.0000 +15.0000i
0 40.0000 + 5.0000i
(d)
c4 =
0.6154 + 0.0769i 0.3000 - 0.3000i
Inf -0.6154 + 0.0769i
Question# 05:-
Plot the function
y=3*exp (3*pi*t);
Choose t from (0---1) with increment of 0.001
Matlab Code:
clc
clear all
close all
t=[0:0.001:1]; %%%Defining t%%%
y=3*exp (3*pi*t); %%%Exponential function%%%
plot(t,y);
title('Exponential Function');
Results:
Categories: