Exercise 3: linear algebra and BLAS¶

Due date: see canvas.

Upload pdf output of notebook into canvas

1. BLAS API¶

Find functions in scipy.linalg.blas for performing the following 3 functions and demonstrate their use with the values given below. Do not use any other packages.

(a) dot product $z = \mathbf x \cdot \mathbf y$

(b) matrix-vector product $\mathbf b = \mathbf A \mathbf x$

(c) matrix-matrix product $\mathbf C = \mathbf A \mathbf B$

Hints:

  • the functions may do more than you need; there may be optional inputs you can ignore, and scalar inputs you can set to 1.
  • the lists as seen below for vectors are interpreted as column vectors, but in the matrices the inner lists are rows
In [ ]:
import scipy.linalg.blas as blas
In [6]:
x = [1,2,3]
y = [4,5,6]

A = [[1,0,1],[0,-1,1],[-1,1,0]]
b = [-1,1,2]
B = [[0,2,1],[1,-1,1],[1,1,-1]]

2. Matrix multiplication parts¶

(a) Demonstrate that you can get the same result as above for $\mathbf A \mathbf x$, by using only the dot product function

(b) Demonstrate that you can get the same result as above for $\mathbf A \mathbf B$, by using the matrix-vector multiplication function one column at a time

Hint: you will probably need to manually extract the columns rather than using a simple slice to access.