Name: Sao Savat
Id: e20180899
Homework: 01
Problem:
Given three of row vectors 𝑎 = (5, 3, 7, 10, 15, 17) 𝑏 = (4, 2, 5, 7,19, 0) and 𝑐 = (1, 5, 3, 8).
1. Change these row vectors to column vectors 𝑎 ′, 𝑏 ′ and c ′ respectively by using MATLAB commands.
2. Calculate the product of ‘a’ and ‘b’ then verify your answer using MATLAB commands.
3. Calculate the Cumulative of vector c and verify with MATLAB commands.
4. Sorting the vector ‘a’ and ‘b’ using MATLAB commands. After that, calculate its dot product and verify
using two technics in MATLAB.
Solution:
1. Change these row vectors to column vectors 𝑎 ′, 𝑏 ′ and c ′ respectively by using MATLAB commands.
We have three of row vectors 𝑎 = (5, 3, 7, 10, 15, 17) 𝑏 = (4, 2, 5, 7,19, 0) and 𝑐 = (1, 5, 3, 8).
Thus:
Commands Results Comments
a’=[5; 3; 7; 10; 15; 17] a’=
7 % To define a column vector a
10
15
17
𝑏’= [4; 2; 5; 7; 19; 0] b’=
5 % To define a column vector b.
19
0
c’= [1; 5; 3; 8] c’=
5 % To define a column vector c
2. Calculate the product of ‘a’ and ‘b’ then verify your answer using MATLAB commands.
5 4 9
3 2 5
7 5 12
a+b = + =
10 7 17
15 19 34
(17) ( 0 ) (17)
Commands Results Comments
a=[5 3 7 10 15 17] 5 3 7 10 15 17 % To define a row vector a
b= [4 2 5 7 19 0] 4 2 5 7 19 0 % To define a row vector b.
a+b 9 5 12 17 34 17 % Sum of Vector a and b
3. Calculate the Cumulative of vector c and verify with MATLAB commands.
Commands Results Comments
c=[1 5 3 8] 1 6 9 17 % Cumulative sum of c
4. Sorting the vector ‘a’ and ‘b’ using MATLAB commands. After that, calculate its dot product and verify using
two technics in MATLAB.
Commands Results Comments
% sorting in ascending order
sort(a) 3 5 7 10 15 17
of vector a
% sorting in ascending order
sort(b) 0 2 4 5 7 19
of vector b
Calculate Dot product of vector a and b
Formula: ab= ∑𝑛𝑖=1 𝑎𝑖 𝑏𝑖 = (5×4)+(3×2)+(7×5)+(10×7)+(15×19)+(17×0)= 416
Commands Results Comments
% dot commands for vector a
dot(a, b) 417
and b