Professional Documents
Culture Documents
ans =
6 10 15
4 10 20 35
5 15 35 70
>> ans'
ans =
6 10 15
4 10 20 35
5 15 35 70
Q.2. Create a random matrix with 3 rows and 4 columns. The matrix
values should be integer
b/w (0100), 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=
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
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
9 0];
0.1 0.4 3.6 4.2 1.7 0.9];
2 1];
V2(4) V2(5)]
V4 =
0.3000
1.2000
0.5000
2.1000
0.1000
9 0];
0.1 0.4 3.6 4.2 1.7 0.9];
2 1];
V2(9) V2(10)]
V5 =
0.4000
3.6000
4.2000
1.7000
0.9000
V1 = [1 2
V2 = [0.3
V3 = [4 4
V6=[V2(1)
3 4 5 6 7 8
1.2 0.5 2.1
4 4 3 3 2 2
V2(2) V2(3)
9 0];
0.1 0.4 3.6 4.2 1.7 0.9];
2 1];
V2(4) V2(5) V2(7) V2(8) V2(9) V2(10)]
V6 =
0.3000
1.2000
0.5000
4.2000
1.7000
0.9000
2.1000
0.1000
3.6000
9 0];
0.1 0.4 3.6 4.2 1.7 0.9];
2 1];
V2(4) V2(5) V2(6) 1.4 V2(8) V2(9) V2(10)]
V7 =
0.3000
1.2000
0.5000
2.1000
1.4000
4.2000
1.7000
0.9000
0.1000
0.4000
7 8 9 0];
2.1 0.1 0.4 3.6 4.2 1.7 0.9];
2 2 2 1];
V2(5) V2(7) V2(9)]
V8 =
0.3000
0.5000
0.1000
3.6000
1.7000
V5 =
8
V1*5
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=V1*5
V4 =
5 10 15 20 25 30 35 40 45
V1+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];
V7=V1+V2
Columns 1 through 8
1.3000 3.2000 3.5000 6.1000 5.1000 6.4000 10.6000 12.2000
Columns 9 through 10
10.7000 0.9000
V1-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];
V7=V1-V3
V7 =
-3 -2 -1
V1.*V2
7 -1
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];
V7=V1.*V2
V7 =
Columns 1 through 8
0.3000 2.4000 1.5000 8.4000 0.5000 2.4000 25.2000 33.6000
Columns 9 through 10
15.3000
V1*V2
ANSWER:
It give an error
V1*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];
V=V1.^2
V=
1
9 16 25 36 49 64 81
V1.^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];
V=V1.^V3
V=
V1^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];
V=V1^V3
There is an error
V1 == 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];
V=V1 == V3
V=
0
V1>6
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];
V=V1>6
V=
0
V1>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];
V=V1>V3
V=
0
V3-(V1>2)
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];
V=V3-(V1>2)
V=
4
V=
0
(V1>2) | (V1<6)
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];
V=(V1>2) | (V1<6)
V=
any(V1)
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];
V=any(V1)
V=
1
all(V1)
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];
V=all(V1)
V=
0
9 10
b = 2:11
b=
2
9 10 11
myfunction(a,b)
ans =
3
9 11 13 15 17 19 21