In order to successfully complete this assignment, you must follow all the instructions in this notebook and upload your edited ipynb file to D2L with your answers on or before 11:59pm on Friday February 5th.

BIG HINT: Read the entire homework before starting.

Homework 1: Data as Vectors

In this homework, we will exploring four different examples of in-class quizzes students had in previous semesters of this course. These problems are intended to give student's exposure to the style of questions asked on quizzes and help you practice. Please finish the entire Jupyter Notebook and turn in your edited file using the MSU D2L Website.

Your instructors recommend doing one question at a time. Set a timer for 20-30 minutes and see how much of the question you can answer. We hope this will get you used to getting a timed quiz complete during class.


1. Solving Systems of Linear Equations

Image of tools on the wall

Image obtained from Pixabay under the Creative commons License

In this problem we will go back to the problem on the 04-Gauss_Jordan_in-class-assignment, with the Giselle’s earnings as a carpenter and a blacksmith. In this problem for week 1 she worked a total of 30 hours and earned a total of \$690, where her wages as a carpenter were \\$20/hour and as a blacksmith were \$25/hour. This generated the following set of linear equations:

$$ c+b = 30$$$$20c+25b=690$$

Now here is the new information. For any job, there are two parts of the time spent; work set-up and work completion. Giselle spent $1/10$ of her work-setup time and $2/3$ of her work completion time on carpentry, so she spent $9/10$ of her work setup time and $1/3$ of her time on work completion. If s is the amount of work set-up time, and w is the amount of work completion time, we get the equations:

$$ \frac{1}{10}s + \frac{2}{3}w = c$$$$ \frac{9}{10}s + \frac{1}{3} w = b$$

To solve for s and w, there are 2 ways: first we can solve for c and b, and then solve for s and w; or second, we can solve for s and w directly.

In [1]:
%matplotlib inline 
import matplotlib.pylab as plt
import numpy as np
import sympy as sym
sym.init_printing()

QUESTION 1: (5pts) use python to solve for c and b in the original set of equations (you did this already in the 04-pre-class assignment)

In [2]:
#put your answer to the above question here.
In [3]:
from answercheck import checkanswer

checkanswer.vector([c,b],"db03b41005ab488f64e4028c15f96340");

QUESTION 2: (5 pts) Using your answers for c and b, generate the augmented matrix A for solving for s and w.

In [4]:
#Put your answer to the above question here.
In [5]:
from answercheck import checkanswer

checkanswer.matrix(A,"31ec508251cdc937ccba2f25a6aff458");

QUESTION 3: (5pts) Use Gauss Jordan and the reduced row echelon form to solve for s and w for your augmented matrix in question 2.

In [6]:
# Put your answer to the above question here
In [7]:
from answercheck import checkanswer

checkanswer.vector([s,w],"8d69467202b2e2cd7f3a18d614028316");

QUESTION 4: (5pts) Multiply the following 2 matrices and store them in a variable named A2:

$$ \left[ \begin{matrix} 1 & 1 \\ 20 & 25 \end{matrix} \right] \left[ \begin{matrix} \frac{1}{10} & \frac{2}{3} \\ \frac{9}{10} & \frac{1}{3} \end{matrix} \right] $$
In [8]:
# Put your answer to the above equation here. 
In [9]:
from answercheck import checkanswer

checkanswer.matrix(A2,"dcac2bb51a2f3bb09877934788038de5");

QUESTION 5: (5pts) Solve the resulting set of equations with

$$ \left[ \begin{matrix} 1 & 1 \\ 20 & 25 \end{matrix} \right] \left[ \begin{matrix} \frac{1}{10} & \frac{2}{3} \\ \frac{9}{10} & \frac{1}{3} \end{matrix} \right] \left[ \begin{matrix} s \\ w \end{matrix} \right] = \left[ \begin{matrix} 30 \\ 690 \end{matrix} \right] $$
In [10]:
# Put your answer to the above equation here
In [11]:
from answercheck import checkanswer

checkanswer.vector([s2,w2],"8d69467202b2e2cd7f3a18d614028316");

Notice that if we did everything correctly the answer for Question 5 is the same as the answer for Question 3.


2. Balancing Equations

IMage of a scale representing the balance of time and money.  This image is being used to show the balance of linear systems

One of the earliest applications of matrix algebra was to solve systems of linear equations. We encounter these in all sorts of situations throughout our lives. In the first two questions below we ask you to formulate and solve a system of linear equations related to figuring out the number of hours worked at two different jobs. In the third and fourth problems we ask you to use Gauss-Jordan elimination to balance chemical equations. The last question is about matrix multiplication.

In [12]:
%matplotlib inline 
import matplotlib.pylab as plt
import numpy as np
import sympy as sym
sym.init_printing()

Situation for problems 1 and 2.

Amy works for a movie theater. She can be assigned to two different jobs during her shift and each job pays a different amount of money. If Amy works at the concessions stand then she will make \$14.50 an hour, and \\$12.15 an hour for selling tickets. Last week, Amy worked a total of 39.5 hours and earned \$525.75. (Disregard all taxes.) If we set $c$ to be the number of hours worked on concessions and $t$ to be the number of hours worked selling tickets then we get two equations

$$ c + t = 39.5,$$$$ 14.50c + 12.15t = 525.75.$$

QUESTION 1: (5pts) Represent the above system of equations as a matrix equation of the form $Ax = b$ and then use numpy to solve the system.

In [13]:
##Edit this cell to answer the question.
In [14]:
from answercheck import checkanswer

checkanswer.vector(x,"92b54c2b36360ec6cc21ca67bc8eeb41");

QUESTION 2: (5 pts) Use complete sentences to describe what the three values $A_{2,2}$, $x_{1,1}$, and $b_{2,1}$ represent in the context of Amy's situation.

YOUR ANSWER HERE


Situation for problems 3 and 4.

A chemical equation is the symbolic representation of a chemical reaction in the form of symbols and formulae, wherein the reactant entities are given on the left-hand side and the product entities on the right-hand side. The coefficients of the symbols represent the number of molecules of each chemical required to preserve matter in the chemical reaction.

For example, the process of burning methane is represented by the chemical equation

$$ 1 CH_4 + 2 O_2 \rightarrow 1CO_2 + 2 H_2O$$

We see there are a total of 1 unit of C (carbon), four units of H (hydrogen), and 4 units of O (oxygen) on the left, and the same on the right. These numbers are computed by multiplying the coefficient by the subscript.

We can represent this reaction using vectors. If the coefficients are unknown then we have

$$x_1 CH_4 + x_2 O_2 \rightarrow x_3 CO_2 + x_4 H_2O$$

Here we see that each chemical in the reaction gives us an unknown variable, and we can obtain an equation in these variables for each element in the reaction.

$$ C: x_1 = x_3 $$$$ H: 4x_1 = 2x_4$$$$ O: 2x_2 = 2x_3 + x_4$$

which leads us to the augmented matrix $$ \left[ \begin{matrix} 1 & 0 & -1 & 0 \\ 4 & 0 & 0 &-2 \\ 0 & 2 & -2 & -1 \end{matrix} \, \middle\vert \, \begin{matrix} 0 \\ 0 \\ 0 \end{matrix} \right] \stackrel{RREF}{\longrightarrow} \left[ \begin{matrix} 1 & 0 & & -0.5 \\ 0 & 1 & 0 &-1 \\ 0 & 0 & 1 & -0.5 \end{matrix} \, \middle\vert \, \begin{matrix} 0 \\ 0 \\ 0 \end{matrix} \right]$$

This leads us to equations $$x_1 - \frac 1 2 x_4 = 0$$

$$ x_2 - x_4 = 0$$$$ x_3 - \frac 1 2 x_4 = 0$$

To get integer values for our solution we can take $x_4 =2$ and see that $x_1 = 1, x_2 = 2,$ and $x_3 = 1$.


The (unbalanced) chemical reaction $$Ca(OH)_2 + H_3PO_4 \rightarrow Ca_3(PO_4)_2 + H_2O$$ mixes calcium hydroxide with phosphoric acid to create tricalcium phosphate and water. This chemical equation is unbalanced and so assigning variables to the coefficients

$$x_1 Ca(OH)_2 + x_2H_3PO_4 \rightarrow x_3Ca_3(PO_4)_2 + x_4H_2O$$

produces the augmented matrix

$$ M = \left[ \begin{matrix} 1 & 0 & -3 & 0 \\ 2 & 4 & -8 &-1 \\ 2 & 3 & 0 & -2 \\ 0 & 1 & -2 & 0 \end{matrix} \, \middle\vert \, \begin{matrix} 0 \\ 0 \\ 0 \\0 \end{matrix} \right]$$

QUESTION 3: (5pts) Find the reduced row echelon form of the matrix $M$ above. Save the reduced matrix as rref for answer check.

In [15]:
#Edit this cell to answer this question.
M = np.matrix("1,0,-3,0,0;2,4,-8,-1,0;2,3,0,-2,0;0,1,-2,0,0")
In [16]:
from answercheck import checkanswer

checkanswer.matrix(rref,"4c1a09e6f2097c1319ee4704fe05dce2");

QUESTION 4: (5pts) Give a non-zero integer solution to the balanced chemical equation associated to the matrix $M$. Save your answer as solution which is a list of $x_1,x_2,x_3,x_4$

In [17]:
#Edit this cell to save your answer.
solution=[]
In [18]:
# YOUR CODE HERE
raise NotImplementedError()

The following question is unrelated to the system of equations above. It is a question about matrix multiplication.

QUESTION 5: (5pts) Suppose $A,$ $B,$ and $C$ are matrices that satisfy $$A + BB^T = C,$$ where $B^T$ is the transpose of $B$.

Which of the following statements are always true? (Note. There may be more than one.)

  1. $A$ is square.
  2. $A$ and $B$ have the same dimensions.
  3. $A$, $B$, and $C$ have the same number of rows.
  4. $B$ is a tall matrix. That is, $B$ has more rows than columns.
  5. $B$ is a wide matrix. That is, $B$ has more columns than rows.

YOUR ANSWER HERE


3. Chickens and Rabbits

Image of chickens and rabbits in a cage as a visual representation of the problem

Above is a famous primary school math olympiad problem: there are only chickens and rabbits in a cage. After counting, we found there are totally 35 heads and 94 feet. How many do we have for each kind?

Let us have some fun by using linear algebra to solve an advanced version of it. There are spiders, dragonflies, and cicadas totally 18 insects in a cage. We have a total of 116 legs and 22 pairs of wings. How many insects do we have of each kind? (spider has 8 legs and 0 wings; dragonfly has 6 legs and 2 pairs of wings; cicada has 6 legs and 1 pair of wings)

Question 1: (6pts) Suppose there are $x$ spiders, $y$ dragonflies, and $z$ cicadas. Set up three linear equations involving $x$, $y$, and $z$.

YOUR ANSWER HERE

Question 2: (7pts) Write out the augmented matrix $A$ for the linear equations you set up above, and reduce it to the REF (Row Echelon Form) (not RREF) by hand. (Please just provide the REF below, no need to show the intermediate steps)

In [19]:
#Put your answer here
A = 
A_REF = 
In [20]:
from answercheck import checkanswer
checkanswer.eq_matrix(A,'bb6c9782ce482b2aea5d41312e9697c4');
In [21]:
checkanswer.eq_matrix(A_REF,'bb6c9782ce482b2aea5d41312e9697c4');
In [22]:
checkanswer.vector([A_REF[1,0],A_REF[2,0],A_REF[2,1]],'b5021f73f68b6e2f957706af7a39ac75')

Question 3: (6pts) Use sympy to reduce the augemented matrix $A$ to the Reduced Row Echelon Form (RREF). (Hint: check Part 4 of the 05 in-class assignment)

In [23]:
#Put your answer here
RREF = 
In [24]:
from answercheck import checkanswer
checkanswer.matrix(RREF,'bb6c9782ce482b2aea5d41312e9697c4');

Question 4: (3pts) Use the RREF you found in Question 3 to derive the solution to the original linear system.

In [25]:
# Put your answer here
x = 
y =
z =
In [26]:
from answercheck import checkanswer
checkanswer.vector([x,y,z],'c550ab8dd2e8d171e88dd545ad653bff');

Question 5: (3pts) For the RREF you found in Question 3, which part of it corresponds to an identity matrix?

YOUR ANSWER HERE


4. Starship Truckers

Rocketship logo to help motivate problem

As a member of the intergalactic union of starship truckers you are trying to a little honest industrial espionage and spy on your fellow truckers to see how they are making their money. The following are commodities that any trucker may be shipping:

Commodity Density (mass / volume) Profit (Price / mass)
Water 1000 $kg/m^3$ 4200 $\$ / kg$
Gold 19,300 $kg/m^3$ 17000 $\$ / kg$
Fuel* 719 $kg/m^3$ -3100 $\$ / kg$
vacuum 0 $kg/m^3$ 0 $\$ / kg$

* NOTE the fuel profit is negative because it is an expense incurred by the trucker for each run.

Starship trucks are in categories based on the volume of their hold volume ($S_v$). Starship trucks are always shipped full when they leave the mining colony and therefore the sum of the volumes of each of the individual commodities must equal the volume of the hold:

$$W + G + F + V = S_v$$

Where $W, G$, and $F$ are the volumes of each of the commodities. The jumpdrive burn rate ($b_r$) is exactly $2.4x10^{-5} m^3 / kg$ no matter the distance. No starship trucker worth their salt will have any left over fuel so this means we have the following linear relationship. The weight of the entire shipment times the burn rate equals the amount of fuel needed:

$$\text{Weight}\times b_r = F$$

The weight of the entire shipment is just the volume of each individual commodity times it's density ($d_w, d_g, d_f$) plus the weight of the starship truck itself ($S_w$):

$$\text{Weight} = Wd_w + Gd_g + Fd_f + S_w$$

Combining the previous two equations we get:

$$(Wd_w + Gd_g + Fd_f + S_w)b_r = F$$

Notice that the unknown variable $F$ is on both sides of the equation. To get this equation into a standard linear form we do the following simple algebra (Steps shown for clarity):

$$Wd_wb_r + Gd_gb_r + Fd_fb_r + S_wb_r = F$$$$Wd_wb_r + Gd_gb_r + Fd_fb_r -F = -S_wb_r$$$$Wd_wb_r + Gd_gb_r + F(d_fb_r - 1) = -S_wb_r$$

Profit is determined by the mass of a commodity times the price per kilogram as follows:

$$ Wd_wp_w + Gd_gp_g + Fd_fp_f = \text{profit}$$

Where \$p_w, p_g, p_f$ are the profit/mass of the product as listed in the above table. All the above numbers are repeated here for simplicity:

In [27]:
import numpy as np
import sympy as sym
sym.init_printing()

#Numbers from the above table
dw = 1000   # kg/m3
dg = 19300  # kg/m3
df = 719    # kg/m3
pw = 4200   # $/kg
pg = 17000  # $/kg
pf = -2100  # $/kg

# Burn Rate
br = 2.4*10**-5 # m3/kg

Question 1.a: Assume you just finished a shipment with $W = 200 m^3, G = 200 m^3 \text{and } F=100{m^3}$. What is your ships hold volume (yes, this one is easy)?

In [28]:
#Put your answer to the above question here.
In [29]:
from answercheck import checkanswer
checkanswer.float(Sv,'02541b7cbb840b5f6bd8eff3c9f56f61');

Question 1.b: In the same run as Question 1.a, what is the maximum weight of your ship ($S_w$)?

In [30]:
#Put your answer to the above question here
In [31]:
from answercheck import checkanswer
checkanswer.float(Sw,'b6a776fd8d09eafe8954d5aa7cd7740d',decimal_accuracy=2);

Question 1.c: How much money did you earn on the previous run?

In [32]:
#Put your answer to the above question here
In [33]:
from answercheck import checkanswer
checkanswer.float(profit,'20f32ce6e591e84e398721178c7b8f06',decimal_accuracy=2);

Question 1.d: Now assume that your compeditor (Nan) has a smalish ship of $S_w = 10,000 kg$ and hold size of $S_v = 100m^3$. On Nan's last run they made a profit of 20 billion spacebucks. Assume that the volumns $W$, $G$ and $F$ are unknown. Write this system of equations $Ax=b$ as an augmented numpy matrix $A$.

In [34]:
profit = 20*10**9
Sb = 10000
Sv = 100
In [35]:
#Put your answer to the above question here
In [36]:
from answercheck import checkanswer
checkanswer.eq_matrix(A,'ef4af5a1ad087f8838df635139c3236b');

Question 1.e: In your own words, explain why you can not solve this system of equations above using the Jacobi iterative solver.

YOUR ANSWER HERE


Congratulations, we're done!

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.

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