Given the following Matrix: B=[2 5 8 9 1 4 7 7 0 3 3 6 2 6 1 7] perform the foll
ID: 3682149 • Letter: G
Question
Given the following Matrix:
B=[2 5 8 9
1 4 7 7
0 3 3 6
2 6 1 7]
perform the following operations:
a) Perform element-by-element multiplication with the 2nd row and the 3rd column of matrix B
b) Replace the fourth column of matrix B with the resulting numbers in part a). (It is not acceptable to simply rewrite matrix A with the new numbers)
c) Delete the third row of matrix B.
The initial matrix and the resulting matrix after part c) MUST be stored in the variable B.
Copy and paste your code below.
Explanation / Answer
I am giving an example how to do it clearly.
Matrix multiplication
In matrix multiplication two vectors with equal magnitude can be multiplied.
Example : >> A=[1 2 3];
>> B=[2;4;3];
>> C=A*B % * is the command for multiplication.
C = 19
1.1.4 .* Array multiplication operator
Array multiplication
Array multiplication is the term by term multiplication.
Example :>> A=[1 2 3];
>> B=[3 4 2];
>> C=A.*B% .* is the command for array multiplication.
C = 3 8 6
A(:,n) refer to the elements in all rows of column n of the matrix A.
A(n,:) refer to the elements in all the columns of row n of the matrix A.
A(:,m:n)refers to the elements in all the rows between columns m and n of the matrix A.
A(m:n,:) refers to the elements in all the elements between rows m and n of the matrix A.
A(m:n,p:q) refers to the elements in rows m through n and columns p through q.
Ex:1 . create a matrix A with 5 rows and 6 columns and create another column vector B from the elements in all the rows of column 3 in matrix A.
>> A=[1 3 5 7 9 11;2 4 6 8 10 12;3 6 9 12 15 18;4 8 12 16 20 24;5 10 15 20 25 30]
A = 1 3 5 7 9 11
2 4 6 8 10 12
3 6 9 12 15 18
4 8 12 16 20 24
5 10 15 20 25 30
>> A(3,2)% it shows that 3rd row 2nd column.
ans = 6
>> B=A(:,3) % it shows that all rows in third column.
B = 5
6
9
12
15
>> C=A(2,:) % it shows that all columns in second row.
C = 2 4 6 8 10 12
>> A(:,2:3) % it shows that all rows in 2nd to 3rd columns
ans =
3 5
4 6
6 9
8 12
10 15
>> A(2:3,:)% it shows that all columns with 2nd to third row.
ans =
2 4 6 8 10 12
3 6 9 12 15 18
The square brackets operator constructs two-dimensional matrices only, (including 0-by-0, 1-by-1, and 1-by-n matrices).
Example :
>> [1 2 3 4]
ans = 1 2 3 4
>> [1;2;3]
ans =
1
2
3
>> [1 2 3; 4 3 2; 2 5 6]
ans =
1 2 3
4 3 2
2 5 6
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.