MTH202 Worksheet 2¶

In [1]:
import numpy as np

Problem 1¶

Consider the following matrices $A$ and $B$ defined as in the following blocks.

In [2]:
A = np.array([[1, 1, 0, 4, 7],
              [0, 0, -1, 2, 3],
              [1, 1, 0, 0, -5],
              [1, 3, 5, 4, 2]])

B = np.array([[3, 2, 2, 1],
              [-1, 5, 0, 0],
              [0, 1, -3, 3],
              [0, 4, 3, 0],
              [1, 2, 0, 1]])

Problem 1.1¶

Find the dimension of $A$ and $B$.

In [3]:
A_rows, A_cols = A.shape
B_rows, B_cols = B.shape
print(f"dim(A) = {A_rows}x{A_cols}")
print(f"dim(B) = {B_rows}x{B_cols}")
dim(A) = 4x5
dim(B) = 5x4

Problem 1.2¶

Find the products $AB$ and $A^{\top}B^{\top}$.

In [4]:
AB = A @ B
ATBT = A.T @ B.T
print(f"AB = {AB}")
print(f"A'B' = {ATBT}")
AB = [[ 9 37 14  8]
 [ 3 13  9  0]
 [-3 -3  2 -4]
 [ 2 42 -1 18]]
A'B' = [[ 6 -1  0  3  2]
 [ 8 -1  6  3  4]
 [ 3 -5 14 -4  3]
 [20  6 14  8 12]
 [19  8 24 -3 15]]

Problem 1.3¶

Find the 3rd row of $AB$.

In [5]:
AB[2,:]
Out[5]:
array([-3, -3,  2, -4])

Problem 1.4¶

Find the last row of $A^{\top}B^{\top}$.

In [6]:
ATBT[-1,:]
Out[6]:
array([19,  8, 24, -3, 15])

Problem 2¶

Consider the following matrix $C$.

In [7]:
C = np.zeros((11, 11))
C
Out[7]:
array([[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
       [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
       [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
       [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
       [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
       [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
       [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
       [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
       [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
       [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
       [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]])

Problem 2.1¶

  • Change the first row of $C$ to your student id.
  • Change the first column of $C$ to the student id of the one sitting next to you.
In [8]:
# Suppose your id is 67012345678
# Your friend's id is 67098765432
C[0,:] = [6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 8]
C[:,0] = [6, 7, 0, 9, 8, 7, 6, 5, 4, 3, 2]
print(C)
[[6. 7. 0. 1. 2. 3. 4. 5. 6. 7. 8.]
 [7. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
 [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
 [9. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
 [8. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
 [7. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
 [6. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
 [5. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
 [4. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
 [3. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
 [2. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]]