Download (right-click, save target as ...) this page as a jupyterlab notebook from: Lab8-TH


Laboratory 8: Matrices a Red Pill Approach

LAST NAME, FIRST NAME

R00000000

ENGR 1330 Laboratory 8 - Homework


Reading Files

Exercise 0

Define the matrix A and the vector u in Python. Then perform all of the tasks below.

\begin{gather} \mathbf{A} = \begin{pmatrix} 1 & 3 & 5 & 7 \\ 2 & 4 & 6 & 8 \\ -3 & -2 & -1 & 0 \\ \end{pmatrix} ~ \mathbf{u} = \begin{pmatrix} 10 \\ 20 \\ 30 \\ \end{pmatrix} \end{gather}
  1. Print the matrix A
  2. Print the vector u
  3. Print the shape of A
  4. Print the shape of u
  5. Print the first column of A
  6. Print the first two rows of A
  7. Print the first two entries of u
  8. Print the last two entries of u
  9. Print the bottom left 2×2 partition (submatrix) of A
  10. Print the middle two elements of the middle row of A

Use the code blocks below to craft your answer.

Exercise 1

Use your script to multiply two matrices, just like in the Lab (in-Lab portion). Apply the script to find $\mathbf{A}\mathbf{B}$ where.

\begin{gather} \mathbf{A} = \begin{pmatrix} 1 & 2 \\ 3 & 4 \\ 5 & 6 \\ \end{pmatrix} ~~~~ \mathbf{B} = \begin{pmatrix} 7 & 8 & 9 \\ 10 & 11 & 12 \\ \end{pmatrix} \end{gather}

The two matrices are located in files:

http://54.243.252.9/engr-1330-webroot/8-Labs/Lab08/Amat.txt

and:

http://54.243.252.9/engr-1330-webroot/8-Labs/Lab08/Bmat.txt

You should download these files before proceeding


References

  1. A linear algebra primer https://numericalmethodssullivan.github.io/ch-linearalgebra.html

  2. Python file manipulations https://www.tutorialspoint.com/python/python_files_io.htm

  3. A Complete Beginners Guide to Matrix Multiplication for Data Science with Python Numpy https://towardsdatascience.com/a-complete-beginners-guide-to-matrix-multiplication-for-data-science-with-python-numpy-9274ecfc1dc6