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


Exercise Set 8: Matrices a Red Pill Approach

LAST NAME, FIRST NAME

R00000000

ENGR 1330 ES 8 - Homework

In [11]:
# Preamble script block to identify host, user, and kernel
import sys
! hostname
! whoami
print(sys.executable)
print(sys.version)
print(sys.version_info)
atomickitty
sensei
/opt/jupyterhub/bin/python3
3.8.10 (default, Jun  2 2021, 10:49:15) 
[GCC 9.4.0]
sys.version_info(major=3, minor=8, micro=10, releaselevel='final', serial=0)

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.

In [12]:
#%reset -f # only if necessary
In [13]:
# read/create matrix A
# read/create vector u
# print A
# print u
# determine and Print the shape of A 
# determine andPrint the shape of u
# Print the first column of A
# Print the first two rows of A
# Print the first two entries of u
# Print the last two entries of u
# Print the bottom left 2×2 partition (submatrix) of A
# Print the middle two elements of the middle row of A

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

In [14]:
# read file Amat.txt
# read file Bmat.txt
# create a destination matrix ABmatrix
# print Amat
# print Bmat
# perform the multiplication put the result into ABmatrix 
# print ABmatrix