Description

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’.
ANSWER:
pascal(5)
ans =
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
ans'
ans =
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
Q.2. Create a random matrix with 3 rows and 4 columns. The matrix
values should be integer
b/w (0—100), than change its any 2 rows values by ‘1.5’.
c

All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.

Related Documents

Share

Transcript

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’.
ANSWER:
>> pascal(5) ans = 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 >> ans' ans = 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
Q.2. Create a random matrix with 3 rows and 4 columns. The matrix values should be integer b/w (0
—100), than change its any 2 rows values by ‘1.5’.
clc
clear all;
close all;
x=rand(3,4)*100
x(1,:)=1.5
x(2,:)=1.5
x = 95.7167 14.1886 79.2207 3.5712 48.5376 42.1761 95.9492 84.9129 80.0280 91.5736 65.5741 93.3993 x = 1.5000 1.5000 1.5000 1.5000 48.5376 42.1761 95.9492 84.9129 80.0280 91.5736 65.5741 93.3993 x = 1.5000 1.5000 1.5000 1.5000 1.5000 1.5000 1.5000 1.5000 80.0280 91.5736 65.5741 93.3993
Q.3. Operate with the vectors
V1 = [1 2 3 4 5 6 7 8 9 0] V2 = [0.3 1.2 0.5 2.1 0.1 0.4 3.6 4.2 1.7 0.9] V3 = [4 4 4 4 3 3 2 2 2 1]
Calculate, respectively, the sum of all the elements in vectors V1, V2, and V3 ANSWER:
clc
clear all;
close all;
V1 = [1 2 3 4 5 6 7 8 9 0];
V2 = [0.3 1.2 0.5 2.1 0.1 0.4 3.6 4.2 1.7 0.9];
V3 = [4 4 4 4 3 3 2 2 2 1];
y=sum(V1)
z=sum(V2)
S=sum(V3) ANSWER: y = 45 z = 15.0000 S = 29
b) How to get the value of the fifth element of each vector? ANSWER:
clc
clear all;
close all;
V1 = [1 2 3 4 5 6 7 8 9 0];
V2 = [0.3 1.2 0.5 2.1 0.1 0.4 3.6 4.2 1.7 0.9];
V3 = [4 4 4 4 3 3 2 2 2 1];
A=V1(5)
B=V2(5)
C=V3(5) A = 5 B = 0.1000 C = 3
What happens if we execute the command V1(0) and V1(11)? ANSWER:
clc
clear all;
close all;
V1 = [1 2 3 4 5 6 7 8 9 0];
V2 = [0.3 1.2 0.5 2.1 0.1 0.4 3.6 4.2 1.7 0.9];
V3 = [4 4 4 4 3 3 2 2 2 1];
A=V1(0)
C=V1(11) That give an error due not present an 11 digit in vector
Remember if a vector has N elements, their subscripts are from 1
to N
c) Generate a new vector V4 from V2, which is composed of the first five elements of V2. ANSWER:
clc
clear all;
close all;
V1 = [1 2 3 4 5 6 7 8 9 0];
V2 = [0.3 1.2 0.5 2.1 0.1 0.4 3.6 4.2 1.7 0.9];
V3 = [4 4 4 4 3 3 2 2 2 1];
V4=[V2(1) V2(2) V2(3) V2(4) V2(5)]
V4 = 0.3000 1.2000 0.5000 2.1000 0.1000
d) Generate a new vector V5 from V2, which is composed of the last five elements of V2 ANSWER:
clc
clear all;
close all;
V1 = [1 2 3 4 5 6 7 8 9 0];
V2 = [0.3 1.2 0.5 2.1 0.1 0.4 3.6 4.2 1.7 0.9];
V3 = [4 4 4 4 3 3 2 2 2 1];
V5=[V2(6) V2(7) V2(8) V2(9) V2(10)]
V5 = 0.4000 3.6000 4.2000 1.7000 0.9000
e) Derive a new vector V6 from V2, with its 6th element omitted. ANSWER:
clc
clear all;
close all;

We Need Your Support

Thank you for visiting our website and your interest in our free products and services. We are nonprofit website to share and download documents. To the running of this website, we need your help to support us.

Thanks to everyone for your continued support.

No, Thanks