12 In-Class Assignment: Matrix Representation¶
Image from: wikipedia
Agenda for today’s class (80 minutes)¶
%matplotlib inline
import matplotlib.pylab as plt
import numpy as np
import sympy as sym
sym.init_printing(use_unicode=True)
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-e3122a161773> in <module>
----> 1 get_ipython().run_line_magic('matplotlib', 'inline')
2 import matplotlib.pylab as plt
3 import numpy as np
4 import sympy as sym
5 sym.init_printing(use_unicode=True)
~/REPOS/MTH314_Textbook/MakeTextbook/envs/lib/python3.9/site-packages/IPython/core/interactiveshell.py in run_line_magic(self, magic_name, line, _stack_depth)
2342 kwargs['local_ns'] = self.get_local_scope(stack_depth)
2343 with self.builtin_trap:
-> 2344 result = fn(*args, **kwargs)
2345 return result
2346
~/REPOS/MTH314_Textbook/MakeTextbook/envs/lib/python3.9/site-packages/decorator.py in fun(*args, **kw)
230 if not kwsyntax:
231 args, kw = fix(args, kw, sig)
--> 232 return caller(func, *(extras + args), **kw)
233 fun.__name__ = func.__name__
234 fun.__doc__ = func.__doc__
~/REPOS/MTH314_Textbook/MakeTextbook/envs/lib/python3.9/site-packages/IPython/core/magic.py in <lambda>(f, *a, **k)
185 # but it's overkill for just that one bit of state.
186 def magic_deco(arg):
--> 187 call = lambda f, *a, **k: f(*a, **k)
188
189 if callable(arg):
~/REPOS/MTH314_Textbook/MakeTextbook/envs/lib/python3.9/site-packages/IPython/core/magics/pylab.py in matplotlib(self, line)
97 print("Available matplotlib backends: %s" % backends_list)
98 else:
---> 99 gui, backend = self.shell.enable_matplotlib(args.gui.lower() if isinstance(args.gui, str) else args.gui)
100 self._show_matplotlib_backend(args.gui, backend)
101
~/REPOS/MTH314_Textbook/MakeTextbook/envs/lib/python3.9/site-packages/IPython/core/interactiveshell.py in enable_matplotlib(self, gui)
3511 """
3512 from IPython.core import pylabtools as pt
-> 3513 gui, backend = pt.find_gui_and_backend(gui, self.pylab_gui_select)
3514
3515 if gui != 'inline':
~/REPOS/MTH314_Textbook/MakeTextbook/envs/lib/python3.9/site-packages/IPython/core/pylabtools.py in find_gui_and_backend(gui, gui_select)
278 """
279
--> 280 import matplotlib
281
282 if gui and gui != 'auto':
ModuleNotFoundError: No module named 'matplotlib'
2. Matrix Representation of Vector Spaces¶
Consider the following matrix \(A\).
✅ 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');
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:
✅ 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\):
✅ 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.
✅ DO THIS: What are the solutions to the above system of equations?
# Put your code here
✅ 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:
#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¶
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 together. 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#####
✅ 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).
#Put your answer 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?
#Put your answer 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.
Put 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.
#Put your answer here
Put your answer here
Written by Dr. Dirk Colbry, Michigan State University
This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.