05 Pre-Class Assignment: Gauss-Jordan Elimination#

Goals for today’s pre-class assignment#

  1. Solving Many Systems (at the same time)

  2. Calculating Vector Length, Normalization, Distance and Dot

  3. Linear Combinations of Vectors

#  Load Useful Python Libraries 
%matplotlib inline
import matplotlib.pylab as plt
import numpy as np
import sympy as sym
sym.init_printing(use_unicode=True)

1. Solving Many Systems (at the same time)#

from IPython.display import YouTubeVideo
YouTubeVideo("k5fdGS5b4OU",width=640,height=360, cc_load_policy=True)

Now, lets consider the systems of equations from a previous assignment, regarding Giselle working as a carpenter and a blacksmith, except now she has worked three weeks instead of one. Her hourly earnings do not change (i.e. she makes \(\$20\) per hour as a carpenter and \(\$25\) per hour as a blacksmith).

  • In the first week, she worked for a total of 35 hours and earned \(\$750\).

  • In the second week, she worked for a total of 35 hours and earned \(\$750\).

  • In the third week, she worked for a total of 30 hours and earned \(\$650\).

How much did she work as a carpenter and blacksmith for each of those weeks? In other words, we have three similar systems of equations, one for each week:

Week 1:

\[\begin{split}\begin{align*} c + b &= 30\\ 20c + 25b &= 690 \end{align*}\end{split}\]

Week 2:

\[\begin{split}\begin{align*} c + b &= 35\\ 20c + 25b &= 750 \end{align*}\end{split}\]

Week 3:

\[\begin{split}\begin{align*} c + b &= 30\\ 20c + 25b &= 650 \end{align*}\end{split}\]

DO THIS: Write a \(2 \times 5\) augmented matrix representing the 6 equations above. The leftmost two columns should have the coefficients for the common left side of the three systems of equations. The rightmost three columns should have the constants for each of the right sides of the three systems of equations. Name your Matrix \(G\) to verify your answer using the checkanswer function below.

# Put your answer to the above question here. 
from answercheck import checkanswer
checkanswer.matrix(G,'a1e01de142199370be70131849fbf108')

The following function will apply the rref function to the matrix \(G\) and store it in a variable called, wait for it, rref:

rref,_ = sym.Matrix(G).rref()
rref

QUESTION: Given the above, How many hours did Giselle work as a capenter for the three weeks and how many hours did she work as a blacksmith. Fill in your answers below to check if you are correct:

#Replace the zeros with your answers
carpenter_week1 = 0
carpenter_week2 = 0
carpenter_week3 = 0
blacksmith_week1 = 0
blacksmith_week2 = 0
blacksmith_week3 = 0
from answercheck import checkanswer

hours = [[carpenter_week1, carpenter_week2, carpenter_week3],
         [blacksmith_week1, blacksmith_week2, blacksmith_week3]]
hours = np.matrix(hours).astype('float')

checkanswer.matrix(hours,'b2d4a73cac3c95204f5ed743b507093a');

2. Dot Product, Norm, Distance, Orthogonal Vectors#

Let \(u,v \in \mathbb R^n\) be given by \(u=(u_1, \dots u_n)\) and \(v=(v_1, \dots v_n)\), then their dot product is a scalar, mathematically denoted by \(u\cdot v\) and is given by

\(u\cdot v = \text{dot}(u,v) = u_1v_1 + u_2v_2 +\dots + u_nv_n \in \mathbb{R}\).

Definition 1.#

We say \(u\) is orthogonal to \(v\), if \(u\cdot v =0\).

Here pause and think if \(0\) above is a vector or a scalar. Provide your answer below.

Definition 2.#

Given a vector \(u\), the norm (length) of \(u\) is given by \(||u|| = \sqrt{u\cdot u}\).

Here pause and think why we are guaranteed that \(||u||\) is a real number. Explain your reasoning below.

Definition 3.#

Given vectors \(u, v \in \mathbb R^n\), the distance between \(u\) and v is given by \(||u -v|| = \sqrt{(u-v)\cdot (u-v)}\).

Can the distance between two vectors be negative? Explain your reasoning below.

DO THIS: Review Sections 1.4 and 1.5 of the Boyd and Vandenberghe text and answer the questions below.

QUESTION: Use Python to compute the dot product between \(u = [ 1, 7, 9, 11]\) and \(v = [ 7, 1, 2, 2]\) (Store the information in a variable called uv).

#Put your answer to the above question here
from answercheck import checkanswer

checkanswer.float(uv,'48044bf058c2d7d21b311b173a0ca7e5');

QUESTION: What is the norm of vector \(u\) defined above (store this value in a variabled called n)?

#Put your answer to the above question here
from answercheck import checkanswer

checkanswer.float(n,'96078eb552924d7bdb9e67f9ecab88c1');

QUESTION: What is the distance between points \(u\) and \(v\) defined above. (put your answer in a variable named d)

#Put your answer to the above question here
from answercheck import checkanswer

checkanswer.float(d,'71f49beeb28061bc60eb3d9966497416');

3. Linear Combinations of Vectors#

Recall that \(\mathbb R^n\) is a vector space, in particular, it is:

  • Closed under addition

  • Closed under scalar multiplication

QUESTION: In your own words describe what we mean by saying \(\mathbb R^n\) is closed under addition and closed under scalar multiplication.

put your answer here…

Recall that given two scalars (\( a, b \in \mathbb R\)) and and two vectors (\(u, v \in \mathbb R^n\)),then \(au+bv\) is called a linear combination of \(u\) and \(v\). Explain why \(au+bv\) is also a vector in \(\mathbb R^n\).

put your answer here…

QUESTION: Use Python to compute the following linear combinations for \(u = (1,2), v = (4,-1)\), and \(w = (-3,5)\).

(a) \(a = u+w\)

#Put your answer here
from answercheck import checkanswer

checkanswer.vector(a,'af464d466ae982f2cd4461af494e86d6');

(b) \(a = 2u+v\)

#Put your answer here
from answercheck import checkanswer

checkanswer.vector(a,'393468eff8c6ba5d27b7d0aa1b18f929');

(c) \(a = u+3w\)

# Put your answer here
from answercheck import checkanswer

checkanswer.vector(a,'d5e5ca43a86501bcde09b1cbc0ba49b5');

Written by Dr. Dirk Colbry, Michigan State University Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.

###STARTFOOTER###


Congratulations, we’re done!#