In order to successfully complete this assignment you need to participate both individually and in groups during class. If you attend class in-person then have one of the instructors check your notebook and sign you out before leaving class. If you are attending asyncronously, turn in your assignment using D2L no later than 11:59pm on the day of class. See links at the end of this document for access to the class timeline for your section.

In-Class Assignment: Matrix Representation

Image from: wikipedia)

%matplotlib inline
import matplotlib.pylab as plt
import numpy as np
import sympy as sym
sym.init_printing(use_unicode=True)

1. Review Pre-class assignment


2. Matrix Representation of Vector Spaces

Consider the following matrix $A$.

$$ \left[ \begin{matrix} 1 & 0 & 3 \\ 0 & 1 & 5 \\ 1 & 1 & 8 \end{matrix} \right] $$

**QUESTION:** What is the reduced row echelon form of $A$?

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

checkanswer.matrix(rref,'1731818a1555cc33a778a4eb76af945c');
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-3-6dd78ddfb26f> in <module>
      1 from answercheck import checkanswer
      2 
----> 3 checkanswer.matrix(rref,'1731818a1555cc33a778a4eb76af945c');

NameError: name 'rref' is not defined

ROW SPACE The first and second (non zero) rows of the above matrix "spans" the same space as the orignal three row vectors in $A$. We often call this the "row space" and it can be written as a linear combination of the non-zero rows of the reduced row echelon form:

$$row(A) = r(1,0,3)^\top+s(0,1,5)^\top$$

**DO THIS:** Calculate the solutions to the system of homogeneous equations $Ax=0$. This is often called the NULL SPACE or sometimes KERNEL of $A$.

#Put your asnwer here

**DO THIS:** We introduced two subspaces. Pick one vector from the row space of $A$ and another vector from the null space of $A$. Find the dot product of these two vector.

#Put your answer here

**Question:** Did you get the same value for the dot product? Explain your answer.

Put your answer to the above question here

**DO THIS:** What is the reduced row echelon form of $A^T$?

#Put your answer here

COLUMN SPACE: The first and second (non zero) rows of the above matrix "spans" the same space as the original three column vectors in $A$. We often call this the "column space" (or "image space") of $A$ and it can be written as a linear combination of the non-zero rows of the reduced row echelon form of $A^T$:

$$col(A) = a(1,0,1)^\top+b(0,1,1)^\top$$

**DO THIS:** Calculate the solutions to the system of homogeneous equations $A^Tx=0$. This is often called the NULL SPACE of $A^T$.

Do This - Erase the contents of this cell and replace it with your answer to the above question! (double-click on this text to edit this cell, and hit shift+enter to save the text)


Example #1

Consider the following system of linear equations.

$$ x_1 - x_2 + x_3 = 3 $$$$ -2x_1 + 2x_2 - 2x_3 = -6 $$

**DO THIS:** What are the solutions to the above system of equations?

# Put your code her

**DO THIS:** Come up with a specific arbitrary solution (any solution will do) to the above set of equations.

Put your answer to the above question here.

**DO THIS:** Now consider only the left hand side of the above matrix and solve for the kernel (null Space) of A:

$$ A = \left[ \begin{matrix} 1 & -1 & 1 \\ -2 & 2 & -2 \end{matrix} \right] $$
#Put your answer here

**DO THIS:** Express an arbitrary solution as the sum of an element of the kernel of the transformation defined by the matrix of coefficients and a particular solution.

Put your answer to the above question here.

**DO THIS:** Discuss in your group and the class your solution from above. How does the solution to $Ax=b$ relate to the solution to $Ax=0$. If you were to plot all solutions, what shape does it take? How does this shape relate to the kernel?

Put your answer to the above question here.


3. Practice Nutrition

A big Annie's Mac and Cheese fans want to improve the levels of protein and fiber for lunch by adding broccoli and canned chicken. The nutrition information for the foods in this problem are

Nutrient Mac and Cheese Broccoli Chicken Shells and White Cheddar
Calories 270 51 70 260
Protein (g) 10 5.4 15 9
Fiber (g) 2 5.2 0 5

She wants to achieve the goals with exactly 400 calories, 30 g of protein, and 10 g of fiber by choosing the combination of these three or four serving. (Assume that we can have non-integer proportions for each serving.)

**Question a**: We consider all four choices of food togethe. Formulate the problem into a system of equations $$Ax = b.$$ Create your matrix $A$ and the column vector $b$ in np.matrix.

import numpy as np
#####Start your code here #####
A = np.matrix()
b = np.matrix()
#####End of your code here#####
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-9-6341be01792f> in <module>
      1 import numpy as np
      2 #####Start your code here #####
----> 3 A = np.matrix()
      4 b = np.matrix()
      5 #####End of your code here#####

TypeError: __new__() missing 1 required positional argument: 'data'

**Question b**: In this and next question, we only consider three out of the four choices. What proportions of these servings of the three food (Mac and Cheese, Broccoli, and Chicken) should be used to meet the goal? (Hint: formulate it as a system of equations and solve it).

#####Start your code here #####
#####End of your code here#####

**Question c**: She found that there was too much broccoli in the proportions from part (b), so she decided to switch from classical Mac and Cheese to Annie’s Whole Wheat Shells and White Cheddar. What proportions of servings of the new three food should she use to meet the goals?

#####Start your code here #####
#####End of your code here#####

**Question d**: Based on the solutions to parts (b) and (c), what are the possible proportions of serving for the four food that meet the goal.

Start your answer here

End of your answer here

**Question e**: Solve the system of equations from part (a). You need to first decide the three outcomes: One solution, None solution, Infinite many solutions. Then for One solution, write down the solution; for Infinite many solutions, write down all the solutions with free variables.

#####Start your code here #####
#####End of your code here#####

Start your answer here

End of your answer here


Congratulations, we're done!

If you attend class in-person then have one of the instructors check your notebook and sign you out before leaving class. If you are attending remote, turn in your assignment using D2L.

Course Resources:

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