IT103: Algebra

Module 4: Linear Functions

R Batzinger

2024-07-12

  • 4.1 Linear Functions
  • 4.2 Modeling with Linear Functions
  • 4.3 Fitting Linear Models to Data

Creating lines from data

Crickets chirps vs temperature

\[\tiny\begin{matrix}Chirps &44 &35& 20.4& 33& 31 &35& 18.5& 37& 26\\ Temperature& 80.5 &70.5 &57 &66& 68& 72 &52 &73.5 &53\\\end{matrix}\]

Cricket Thermometer


Call:
lm(formula = temp ~ chirps)

Residuals:
    Min      1Q  Median      3Q     Max 
-3.8906 -0.0446  0.3170  0.9490  1.8881 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept) -0.95523    2.50267  -0.382    0.714    
chirps       0.63510    0.07811   8.131 8.22e-05 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 1.806 on 7 degrees of freedom
Multiple R-squared:  0.9043,    Adjusted R-squared:  0.8906 
F-statistic: 66.11 on 1 and 7 DF,  p-value: 8.217e-05

R Square and R

Correlation coefficient

Finding a line from 2 points

::::{.columns} :::{.column width=“50%”}

::: :::{.column width=“50%”}

\[\eqalign{m &=& \frac{y_2-y_1}{x_2 -x_1}\\ &=&\frac{5-7}{3-1} \\&=&\frac{-2}{2}\\ &=& -1\\}\] \[\eqalign{y&=&mx+b\\1&=&-7+b\\8&=&b\\}\]

Matrices

\[A= \left[\begin{matrix} 1 & 4 & 7\\ 0 & -2 & 3\\ \end{matrix}\right]\]

\[B= \left[\begin{matrix} 2 & 5 & 6\\ -3 & 1 & 8\\ \end{matrix}\right]\]

Addition A + B

\[\eqalign{A + B &=& \left[\begin{matrix} 1 & 4 & 7\\ 0 & -2 & 3\\ \end{matrix}\right] + \left[\begin{matrix} 2 & 5 & 6\\ -3 & 1 & 8\\ \end{matrix}\right]\\ &=&\left[\begin{matrix} 1+2 & 4+5 & 7+6\\ 0-3 & -2+1 & 3+8\\ \end{matrix}\right]\\ &=&\left[\begin{matrix} 3 & 9 & 13\\ -3 & -1 & 11\\ \end{matrix}\right]\\} \]

Substraction A-B

\[A = \left[\begin{matrix} 5 & 0 & 2\\ 3 & 6 & -5\\ \end{matrix}\right]\]

\[B= \left[\begin{matrix} 2 & 8 & -1\\ 0 & 4 & 6\\ \end{matrix}\right]\]

\[\eqalign{ A - B &=&\left[\begin{matrix} 5 & 0 & 2\\ 3 & 6 & -5\\ \end{matrix}\right] - \left[\begin{matrix} 2 & 8 & -1\\ 0 & 4 & 6\\ \end{matrix}\right]\\ &=&\left[\begin{matrix} 5-2 & 0-8 & 2+1\\ 3-0 & 6-4 & -5-6\\ \end{matrix}\right]\\ &=&\left[\begin{matrix} 3 & -8 & 3\\ 3 & 2 & -11\\ \end{matrix}\right]\\}\]

Scalar multiplication aA

\[A = \left[\begin{matrix} 5 & 0 & 2\\ 3 & 6 & -5\\ \end{matrix}\right]\]

\[\eqalign{2A &=& 2\left[\begin{matrix} 5 & 0 & 2\\ 3 & 6 & -5\\ \end{matrix}\right]\\ &=& \left[\begin{matrix} 2\cdot 5 & 2\cdot 0 & 2 \cdot2\\ 2\cdot 3 & 2\cdot 6 & 2 \cdot -5\\ \end{matrix}\right]\\ &=& \left[\begin{matrix} 10 & 0 & 4\\ 6 & 12 & -10\\ \end{matrix}\right]\\}\]

Transposition of an array

\[A= \left[\begin{matrix} 1 & 4 & 7\\ 0 & -2 & 3\\ \end{matrix}\right]\]

\[A^\prime =\left[\begin{matrix} 1 & 0\\ 4 & -2 \\ 7 & 3\\ \end{matrix}\right]\]

\[B= \left[\begin{matrix} 2 & 5 & 6\\ -3 & 1 & 8\\ \end{matrix}\right]\]

\[B^\prime = \left[\begin{matrix} 2 & -3\\ 5 & 1\\ 6 & 8\\ \end{matrix}\right]\]

Matrix multiplication

\[A = \left[\begin{matrix}2 & 3 & 1\end{matrix}\right]\] \[B=\left[\begin{matrix}3\\ -2\\ 5\\\end{matrix}\right]\]

\[AB = \left[2\cdot 3 + 3\cdot-2 + 1\cdot 5\right] = \left[6 + -6 + 5\right] = [5]\]

Matrix multiplication AB

\[\eqalign{AB &=& \left[\begin{matrix} 2 & 1 \\ 7 & 0 \\ -3 & -2\\ \end{matrix}\right]\left[\begin{matrix} -1 & 0\\ 3 & 5\\\end{matrix}\right]\\ &=&\left[\begin{matrix} \left[\begin{matrix}2 & 1\\\end{matrix}\right] \left[\begin{matrix} -1\\3\\\end{matrix}\right]& \left[\begin{matrix}2 & 1\\\end{matrix}\right] \left[\begin{matrix} 0\\5\\\end{matrix}\right]\\ \left[\begin{matrix}7 & 0\\\end{matrix}\right] \left[\begin{matrix} -1\\3\\\end{matrix}\right]& \left[\begin{matrix}7 & 0\\\end{matrix}\right] \left[\begin{matrix} 0\\5\\\end{matrix}\right]\\ \left[\begin{matrix}-3 & -2\\\end{matrix}\right] \left[\begin{matrix} -1\\3\\\end{matrix}\right]& \left[\begin{matrix}-3 & -2\\\end{matrix}\right] \left[\begin{matrix} 0\\5\\\end{matrix}\right]\\ \end{matrix}\right]\\ &=&\left[\begin{matrix} (2\times-1)+(1\times3) & (2\times0)+(1\times5)\\ (7\times-1)+(0\times3) & (7\times0)+(0\times5)\\ (-3\times-1)+(-2\times3) & (-3\times0)+(-2\times5)\\ \end{matrix}\right]\\ &=&\left[\begin{matrix} (-2+3)&(0+5)\\ (-7+0)& (0+0)\\ (3-6)&(0-10)\\ \end{matrix}\right]\\ &=&\left[\begin{matrix} 1 & 5\\ -7 & 0\\ -3 & -10\\ \end{matrix}\right]\\ }\]

Another example

\[\eqalign{AB&=&\left[\begin{matrix}1&3\\2&0\\\end{matrix}\right] \left[\begin{matrix}5 & 0 & 1\\3 & -2 &6\\\end{matrix}\right]\\ &=&\left[\begin{matrix} \left[\begin{matrix}1 & 3\\\end{matrix}\right] \left[\begin{matrix} 5\\3\\\end{matrix}\right]& \left[\begin{matrix}1 & 3\\\end{matrix}\right] \left[\begin{matrix} 0\\-2\\\end{matrix}\right] \left[\begin{matrix}1 & 3\\\end{matrix}\right] \left[\begin{matrix} 1\\6\\\end{matrix}\right]\\ \left[\begin{matrix}2 & 0\\\end{matrix}\right] \left[\begin{matrix} 5\\3\\\end{matrix}\right]& \left[\begin{matrix}2 & 0\\\end{matrix}\right] \left[\begin{matrix} 0\\-2\\\end{matrix}\right] \left[\begin{matrix}2 & 0\\\end{matrix}\right] \left[\begin{matrix} 1\\6\\\end{matrix}\right]\\ \end{matrix}\right]\\ &=&\left[\begin{matrix} (1\times5) + (3\times3) & (1\times0)+(3\times-2)& (1\times1)+(3\times6)\\ (2\times5) + (0\times3) & (2\times0)+ (0\times-2)& (2\times 1) + (0 \times 6)\\ \end{matrix}\right]\\ &=& \left[\begin{matrix} (5+9) & (0-6) & (1+18)\\ (10+0)& (0+0) & (2+0)\\ \end{matrix}\right]\\ &=& \left[\begin{matrix} 14 & -6 & 19\\ 10 & 0 & 2\\ \end{matrix}\right]\\ }\]

A linear problem

  • 100 hens take 3 days to lay 100 eggs. How many days does it take 50 hens to lay 50 days?

  • 5 painters take 8 hrs to paint the exterior of 2 houses. How long would it take 4 men to the same job?

  • It takes 4 hours for 3 cars to drive from Chiang Mai to Chiang Rai. How long would it take 2 cars to do that?

Computer Graphic Transformations

An icon definition

param p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11
bias 1 1 1 1 1 1 1 1 1 1 1
x 1 2 2 3 3 2 2 4 4 1 1
y 0 0 2 2 3 3 4 4 5 5 0

Graphic representation

Transition matrix

\[Identity = \left[\begin{matrix}1 & 0 & 0 \\ 0 & 1 & 0\\ 0& 0& 1\\ \end{matrix}\right]\]

Transition

\[Scale = \left[\begin{matrix}1 & 0 & 0 \\ 0 & a_x & 0\\ 0& 0& a_y\\ \end{matrix}\right]= \left[\begin{matrix}1 & 0 & 0 \\ 0 & 0.5 & 0\\ 0& 0& 0.25\\ \end{matrix}\right]\]

Scale Transition

\[Scale = \left[\begin{matrix}1 & b_x & b_y \\ 0 & 1 & 0\\ 0 & 0& 1\\ \end{matrix}\right]= \left[\begin{matrix}1 & 2 & 2 \\ 0 & 0.5 & 0\\ 0& 0 & 0.5\\ \end{matrix}\right]\]

Sheer Transition

\[Scale = \left[\begin{matrix}1 & 0 & 0 \\ 0 & 1 & 0\\ 0 & c_y& 1\\ \end{matrix}\right]= \left[\begin{matrix}1 & 0 & 0 \\ 0 & 1& 0\\ 0& 0.2& 1\\ \end{matrix}\right]\]

Rotation Transition

\[Rotation = \left[\begin{matrix}1 & 0 & 0 \\ 0 & \cos \theta & -\sin \theta\\ 0 & \sin \theta & \cos \theta\\ \end{matrix}\right]= \left[\begin{matrix}1 & -0.5& 0.5 \\ 0 & cos(0.25) & -sin(0.25)\\ 0& sin(0.25) & cos(0.25)\\ \end{matrix}\right]\]

Cost of candy manufacture

\[Cs=\begin{matrix} quantity & baht & rupiah & ringit & S\$\\ 10 & 5 & 2300 & 22 & 0.42 \\ 20 & 9 & 4450 & 40 & 0.84 \\ 100 & 40 & 21000 & 210 & 4.00 \\ 1000 & 350 & 200000 & 2000 & 35.00 \\ \end{matrix}\]

We would like to compare the price structures of all the manufacturers.

Problems:

  • Different exchange rates
  • Different qualities

Exchange rates

\[\begin{matrix} US\$& baht & rupiah & ringit & S\$\\ 1 & 32.87 & 151450 & 4.20 & 3.25\\ \end{matrix}\]

Exchange to USD \[\left[\begin{matrix} baht & 0.03042\\ rupiah & 0.00006603\\ ringit & 0.238\\ S\$ & 0.3077\\ \end{matrix}\right]\]

Exchange Transformation matrix \[Et= \left[\begin{matrix} 0.03042 & 0 & 0 & 0 \\ 0 & 0.00006603 & 0 & 0\\ 0 & 0 & 0.238 & 0\\ 0& 0 & 0 & 0.3077\\ \end{matrix}\right]\]

Convert all Cost to USD

\[\tiny\eqalign{C_{US} &=& Cs \times Et\\ &=&\left[\begin{matrix} 5 & 2300 & 22 & 0.42 \\ 9 & 4450 & 40 & 0.84 \\ 40 & 21000 & 210 & 4.00 \\ 350 & 200000 & 2000 & 35.00 \\ \end{matrix}\right]\times \left[\begin{matrix} 0.03042 & 0 & 0 & 0 \\ 0 & 0.00006603 & 0 & 0\\ 0 & 0 & 0.238 & 0\\ 0& 0 & 0 & 0.3077\\ \end{matrix}\right]\\&=&\left[\begin{matrix} 0.15210& 0.1518690 & 5.236 & 0.129234\\ 0.27378& 0.29383 & 9.520 & 0.258468\\ 1.21680 & 1.38663 & 49.980 &1.230800\\ 10.64700 & 13.2060 & 476.000 & 10.769500\\ \end{matrix}\right]}\]

Convert to unit costs

Quantity Transition Matrix \[\eqalign{Qt &=& \left[\begin{matrix} \frac{1}{10} & 0 & 0 & 0\\ 0 & \frac{1}{20} & 0 & 0\\ 0 & 0 & \frac{1}{100} & 0\\ 0& 0 & 0 & \frac{1}{1000}\end{matrix}\right]\\} \]

Normalizing to unit costs

\[\tiny\eqalign{C_{unit} &=& Qt \times Cs\\ &=&\left[\begin{matrix} \frac{1}{10} & 0 & 0 & 0\\ 0 & \frac{1}{20} & 0 & 0\\ 0 & 0 & \frac{1}{100} & 0\\ 0& 0 & 0 & \frac{1}{1000}\\\end{matrix}\right] \left[\begin{matrix} 5 & 2300 & 22 & 0.42 \\ 9 & 4450 & 40 & 0.84 \\ 40 & 21000 & 210 & 4.00 \\ 350 & 200000 & 2000 & 35.00 \\ \end{matrix}\right]\\ &=&\left[\begin{matrix} 0.50 &230.0 & 2.2 & 0.042\\ 0.45 &222.5 & 2.0 & 0.042\\ 0.40 &210.0 & 2.1 & 0.040\\ 0.35 &200.0 & 2.0 & 0.035\\ \end{matrix}\right]\\}\]

Putting it all together

\[\tiny\eqalign{C_{unit,usd} &=& C_{unit} \times Et\\ &=&\left[\begin{matrix} 0.50 &230.0 & 2.2 & 0.042\\ 0.45 &222.5 & 2.0 & 0.042\\ 0.40 &210.0 & 2.1 & 0.040\\ 0.35 &200.0 & 2.0 & 0.035\\ \end{matrix}\right] \left[\begin{matrix} 0.03042 & 0 & 0 & 0 \\ 0 & 0.00006603 & 0 & 0\\ 0 & 0 & 0.238 & 0\\ 0& 0 & 0 & 0.3077\\ \end{matrix}\right]\\ &=&\left[\begin{matrix} 5 & 2300 & 22 & 0.42 \\ 9 & 4450 & 40 & 0.84 \\ 40 & 21000 & 210 & 4.00 \\ 350 & 200000 & 2000 & 35.00 \\ \end{matrix}\right]\\ &=&\left[\begin{matrix} 0.015210 & 0.01518690 & 0.5236 & 0.0129234\\ 0.013689 & 0.01469168 & 0.4760 & 0.0129234\\ 0.012168 & 0.01386630 & 0.4998 & 0.0123080\\ 0.010647 & 0.01320600 & 0.4760 & 0.0107695\\ \end{matrix}\right]\\}\]

Putting labels on the results

Unit price in USD from all competitors

Qty TH ID MY SG
10 0.015210 0.01518690 0.5236 0.0129234
20 0.013689 0.01469168 0.4760 0.0129234
100 0.012168 0.01386630 0.4998 0.0123080
1000 0.010647 0.01320600 0.4760 0.0107695

Transition Challenge

Graphic Definition

\[points = \left[\tiny\begin{matrix} param & P1 &P2 &P3 &P4& P5& P6 &P7& P8& P9\\ Bias&1&1&1&1&1&1&1&1&1\cr X & 1&4&4&2&2&2.5&2.5&1& 1\cr Y &0&0&1&1&3&3&4&4&0\cr \end{matrix}\right]\]

Graphic Representation

Challenge: What is the transition matrix for these shape drawn from the previous points?

::: ::::

Answer Key

\[\eqalign{ A &=& \left[\begin{matrix} 1&0&10\\ 0&1&0\\ 0&0&-\frac{1}{2}\\ \end{matrix}\right]\\ B &=& \left[\begin{matrix} 1&0&0\\ 0&1&0\\ 0&0&1\\ \end{matrix}\right]\\ C &=& \left[\begin{matrix} 1&3&4.5\\ 0&\frac{1}{2}\cos(\frac{3}{4})&\frac{1}{2}\sin(\frac{3}{4})\\ 0&-\frac{1}{2}\sin(\frac{3}{4})&\frac{1}{2}\cos(\frac{3}{4})\\ \end{matrix}\right]\\ D &=& \left[\begin{matrix} 1&2.5&3\\ 0&\cos(\frac{3}{4})&-\sin(\frac{3}{4})\\ 0 &\sin(\frac{3}{4})&\cos(\frac{3}{4})\\ \end{matrix}\right]\\ E &=& \left[\begin{matrix} 1&10&10\\ 0&-1&0\\ 0&0&-1\\ \end{matrix}\right]\\ F &=& \left[\begin{matrix} 1&9.5&0\\ 0&-\frac{1}{2}&0\\ 0&0&1\\ \end{matrix}\right]\\ }\]

Sample matrix

\[\left[\begin{matrix} 1 & 2 & 3\\ \end{matrix}\right]\left[\begin{matrix} 1\\ 2\\ 3\\ \end{matrix}\right]= \left[1^2+2^2+3^2\right] = \left[14\right]\]

\[\left[\begin{matrix} 1\\ 2\\ 3\\ \end{matrix}\right]\left[\begin{matrix} 1 & 2 & 3\\ \end{matrix}\right]= \left[\begin{matrix}1^2 &2^2&3^2\\\end{matrix}\right] = \left[\begin{matrix}1&4&9\\\end{matrix}\right]\]

Multiple variable representation

\[\eqalign{x &+& y &+& z &=& 6\\ 2x &+& y &+& 4z &=& 16\\ 3x &+& 5y &+& 2z &=& 19\\ }\]

\[\left[\begin{matrix} 1 & 1 & 1 \\ 2 & 1 & 4 \\ 3 & 5 & 2 \\ \end{matrix}\right]\left[\begin{matrix}x\\y\\z\\\end{matrix}\right]= \left[\begin{matrix} 6\\ 16\\ 19\\ \end{matrix}\right]\]

\[\left[\begin{matrix} 1 & 1 & 1 &6\\ 2 & 1 & 4 &16\\ 3 & 5 & 2 &19\\ \end{matrix}\right]\]

Gaussian Elimination

\[\left[\begin{matrix} 1 & 1 & 1 &6\\ 2 & 1 & 4 &16\\ 3 & 5 & 2 &19\\ \end{matrix}\right]\]

\[\tiny\left[\begin{matrix} 1 & 1 & 1 &6\\ 2 & 1 & 4 &16\\ 3 & 5 & 2 &19\\ \end{matrix}\right]-\left[\begin{matrix} 0&0&0&0\\ 2&2&2&12\\ 3&3&3&18\\ \end{matrix}\right]\rightarrow \left[\begin{matrix} 1&1&1&6\\ 0&-1&2&4\\ 0&2&-1&1\\ \end{matrix}\right]\]

\[\tiny\left[\begin{matrix} 1&1&1&6\\ 0&1&-2&-4\\ 0&2&-1&1\\ \end{matrix}\right]- \left[\begin{matrix} 0&0&0&0\\ 0&0&0&0\\ 0&2&-4&-8\\ \end{matrix}\right]\rightarrow \left[\begin{matrix} 1&1&1&6\\ 0&1&-2&-4\\ 0&0&3&9\\ \end{matrix}\right] \] \[\left[\begin{matrix} 1&1&1&6\\ 0&1&-2&-4\\ 0&0&1&3\\ \end{matrix}\right] \]

Backsubstitution

\[\left[\begin{matrix} 1&1&1&6\\ 0&1&-2&-4\\ 0&0&1&3\\ \end{matrix}\right] \]

\[\tiny\left[\begin{matrix} 1&1&1&6\\ 0&1&-2&-4\\ 0&0&1&3\\ \end{matrix}\right]- \left[\begin{matrix} 0&0&1&3\\ 0&0&-2&-6\\ 0&0&1&3\\ \end{matrix}\right]\rightarrow \left[\begin{matrix} 1&1&0&3\\ 0&1&0&2\\ 0&0&1&3\\ \end{matrix}\right] \]

\[\tiny \left[\begin{matrix} 1&1&0&3\\ 0&1&0&2\\ 0&0&1&3\\ \end{matrix}\right]- \left[\begin{matrix} 0&1&0&2\\ 0&0&0&0\\ 0&0&0&0\\ \end{matrix}\right]\rightarrow \left[\begin{matrix} 1&0&0&1\\ 0&1&0&2\\ 0&0&1&3\\ \end{matrix}\right]\]

\[ \left[\begin{matrix} 1&0&0\\ 0&1&0\\ 0&0&1\\ \end{matrix}\right]\left[\begin{matrix} x\\ y\\ z\\ \end{matrix}\right]= \left[\begin{matrix} 1\\ 2\\ 3\\ \end{matrix}\right] \] ## Another one

\[\eqalign{ x &+& 2y &+& 3z &=& 12\\ 3x &+& 2y &+& 1z &=& 12\\ 2x &+& 1y &+& 2z &=& 10\\ }\]

Gaussian Elimination

\[\tiny\left[\begin{matrix} 1&2&3 &12\\ 3& 2& 1 & 12\\ 2& 1& 2& 10\\ \end{matrix}\right]- \left[\begin{matrix} 1&2&3 &12\\ 3& 6& 9 & 36\\ 2& 4& 6& 24\\ \end{matrix}\right]\rightarrow \left[\begin{matrix} 1&2&3 &12\\ 0& -4& -8 & -24\\ 0& -3& -4& -14\\ \end{matrix}\right] \]

\[\tiny \left[\begin{matrix} 1&2&3 &12\\ 0& 1& 2 & 6\\ 0& 3& 4& 14\\ \end{matrix}\right]- \left[\begin{matrix} 0&0&0 &0\\ 0& 0& 0 & 0\\ 0& 3& 6& 18\\ \end{matrix}\right]\rightarrow \left[\begin{matrix} 1&2&3 &12\\ 0& 1& 2 & 6\\ 0& 0& -2& -4\\ \end{matrix}\right]\] \[\left[\begin{matrix} 1&2&3 &12\\ 0& 1& 2 & 6\\ 0& 0& 1& 2\\ \end{matrix}\right] \]

Back substitution

\[\left[\begin{matrix} 1&2&3 &12\\ 0& 1& 2 & 6\\ 0& 0& 1& 2\\ \end{matrix}\right] \] \[\tiny\left[\begin{matrix} 1&2&3 &12\\ 0& 1& 2 & 6\\ 0& 0& 1& 2\\ \end{matrix}\right]- \left[\begin{matrix} 0&0&3 &6\\ 0& 0& 2 & 4\\ 0& 0& 0& 0\\ \end{matrix}\right] \rightarrow \left[\begin{matrix} 1&2&0 &4\\ 0& 1& 0 & 2\\ 0& 0& 1& 2\\ \end{matrix}\right] \]

\[\tiny\left[\begin{matrix} 1&2&0 &4\\ 0& 1& 0 & 2\\ 0& 0& 1& 2\\ \end{matrix}\right]- \left[\begin{matrix} 0&2&0 &4\\ 0& 0& 0 & 0\\ 0& 0& 0& 0\\ \end{matrix}\right] \rightarrow \left[\begin{matrix} 1&0&0 &2\\ 0& 1& 0 & 2\\ 0& 0& 1& 2\\ \end{matrix}\right] \] \[\left[\begin{matrix} x\\ y\\ z\\ \end{matrix}\right] = \left[\begin{matrix} 2\\ 2\\ 2\\ \end{matrix}\right]\]

Checking the answer

1&2&3 &12\ 3& 2& 1 & 12\ 2& 1& 2& 10\ \[\left[\begin{matrix} 1 & 2 & 3 \\ 3 & 2 & 1 \\ 2 & 1 & 2 \\ \end{matrix}\right]\left[\begin{matrix}2\\2\\2\\\end{matrix}\right]= \left[\begin{matrix} 6\\ 16\\ 19\\ \end{matrix}\right]\]

     [,1]
[1,]   12
[2,]   12
[3,]   10


Initial matrix:
     [,1] [,2] [,3] [,4]
[1,]   2    1   -1    8 
[2,]  -3   -1    2  -11 
[3,]  -2    1    2   -3 

row: 1 

 exchange rows 1 and 2 
     [,1] [,2] [,3] [,4]
[1,]  -3   -1    2  -11 
[2,]   2    1   -1    8 
[3,]  -2    1    2   -3 

 multiply row 1 by -1/3 
     [,1] [,2] [,3] [,4]
[1,]    1  1/3 -2/3 11/3
[2,]    2    1   -1    8
[3,]   -2    1    2   -3

 multiply row 1 by 2 and subtract from row 2 
     [,1] [,2] [,3] [,4]
[1,]    1  1/3 -2/3 11/3
[2,]    0  1/3  1/3  2/3
[3,]   -2    1    2   -3

 multiply row 1 by 2 and add to row 3 
     [,1] [,2] [,3] [,4]
[1,]    1  1/3 -2/3 11/3
[2,]    0  1/3  1/3  2/3
[3,]    0  5/3  2/3 13/3

row: 2 

 exchange rows 2 and 3 
     [,1] [,2] [,3] [,4]
[1,]    1  1/3 -2/3 11/3
[2,]    0  5/3  2/3 13/3
[3,]    0  1/3  1/3  2/3

 multiply row 2 by 3/5 
     [,1] [,2] [,3] [,4]
[1,]    1  1/3 -2/3 11/3
[2,]    0    1  2/5 13/5
[3,]    0  1/3  1/3  2/3

 multiply row 2 by 1/3 and subtract from row 1 
     [,1] [,2] [,3] [,4]
[1,]    1    0 -4/5 14/5
[2,]    0    1  2/5 13/5
[3,]    0  1/3  1/3  2/3

 multiply row 2 by 1/3 and subtract from row 3 
     [,1] [,2] [,3] [,4]
[1,]    1    0 -4/5 14/5
[2,]    0    1  2/5 13/5
[3,]    0    0  1/5 -1/5

row: 3 

 multiply row 3 by 5 
     [,1] [,2] [,3] [,4]
[1,]    1    0 -4/5 14/5
[2,]    0    1  2/5 13/5
[3,]    0    0    1   -1

 multiply row 3 by 4/5 and add to row 1 
     [,1] [,2] [,3] [,4]
[1,]    1    0    0    2
[2,]    0    1  2/5 13/5
[3,]    0    0    1   -1

 multiply row 3 by 2/5 and subtract from row 2 
     [,1] [,2] [,3] [,4]
[1,]  1    0    0    2  
[2,]  0    1    0    3  
[3,]  0    0    1   -1  

Point and line

p1 = (1,4) p2 = (11,9) p3 = (5,16)

How far is p3 from the line that goes through p1 and p2?

  • Find the slope for the line

\[m = \frac{\Delta y}{\Delta x}=\frac{9-4}{11-1}=\frac{5}{10}= 0.5\]

  • Find the intercept

\[\eqalign{y &=& mx + b\\ 4 &=& 0.5\cdot 1 + b\\ 4 &=& 0.5 + b\\ 3.5 &=& b\\ y &=& 0.5 x + 3.5\\}\] * Determine the slope of the perpenticular

\[ \frac{m_{perp}}{m_{line}} = \frac{m_{perp}}{0.5}= -1\]

\[m_{perp} = -0.5\]

  • Determine the perpenticular line that goes through p3

\[\eqalign{16 &=& -.5\cdot 5 +b\\ 16 &=& -2.5 + b\\ 18.5 &=& b\\ y &=& -0.5 x + 18.5\\}\]

  • Find the intersection point for both lines

\[\eqalign{y &=& -0.5x + 18.5\\ y &=& 0.5x + 3.5\\ -0.5x + 18.5 &=& 0.5x +3.5\\ 15&=&x\\ y &=& 0.5\cdot 15 + 3.5 = 7.5 +3.5 = 11\\}\]

Intercept = (15,11)

  • Find the distance between p3 and the intersection point

\[\eqalign{d &=& \sqrt{(\Delta x)^2 + (\Delta y)^2}\\ &=& \sqrt{(15-5)^2 + (11-16)^2}\\ &=& \sqrt{10^2 + 5^2}\\ &=&\sqrt{125} = 11.18\\}\]

Chemistry

Stoichiometry of reactants and products of a reaction

\[w\ C_6H_{12}O_6 + x\ O_2 \rightarrow y\ CO_2 + z\ H_2O\]

*Count the number of atoms in each molecule

  • Oxygen:\(6w + 2x -2y -z =0\)

  • Carbon:\(6w - y = 0\)

  • Hydrogen:\(12w - 2z = 0\)

*Assume a number for one of the molecules

  • Sugar: \(w = 1\)

  • Solve the matrix


Initial matrix:
     [,1] [,2] [,3] [,4] [,5]
[1,]  6    2   -2   -1    0  
[2,]  6    0   -1    0    0  
[3,] 12    0    0   -2    0  
[4,]  1    0    0    0    1  

row: 1 

 exchange rows 1 and 3 
     [,1] [,2] [,3] [,4] [,5]
[1,] 12    0    0   -2    0  
[2,]  6    0   -1    0    0  
[3,]  6    2   -2   -1    0  
[4,]  1    0    0    0    1  

 multiply row 1 by 1/12 
     [,1] [,2] [,3] [,4] [,5]
[1,]    1    0    0 -1/6    0
[2,]    6    0   -1    0    0
[3,]    6    2   -2   -1    0
[4,]    1    0    0    0    1

 multiply row 1 by 6 and subtract from row 2 
     [,1] [,2] [,3] [,4] [,5]
[1,]    1    0    0 -1/6    0
[2,]    0    0   -1    1    0
[3,]    6    2   -2   -1    0
[4,]    1    0    0    0    1

 multiply row 1 by 6 and subtract from row 3 
     [,1] [,2] [,3] [,4] [,5]
[1,]    1    0    0 -1/6    0
[2,]    0    0   -1    1    0
[3,]    0    2   -2    0    0
[4,]    1    0    0    0    1

 subtract row 1 from row 4 
     [,1] [,2] [,3] [,4] [,5]
[1,]    1    0    0 -1/6    0
[2,]    0    0   -1    1    0
[3,]    0    2   -2    0    0
[4,]    0    0    0  1/6    1

row: 2 

 exchange rows 2 and 3 
     [,1] [,2] [,3] [,4] [,5]
[1,]    1    0    0 -1/6    0
[2,]    0    2   -2    0    0
[3,]    0    0   -1    1    0
[4,]    0    0    0  1/6    1

 multiply row 2 by 1/2 
     [,1] [,2] [,3] [,4] [,5]
[1,]    1    0    0 -1/6    0
[2,]    0    1   -1    0    0
[3,]    0    0   -1    1    0
[4,]    0    0    0  1/6    1

row: 3 

 multiply row 3 by -1 
     [,1] [,2] [,3] [,4] [,5]
[1,]    1    0    0 -1/6    0
[2,]    0    1   -1    0    0
[3,]    0    0    1   -1    0
[4,]    0    0    0  1/6    1

 multiply row 3 by 1 and add to row 2 
     [,1] [,2] [,3] [,4] [,5]
[1,]    1    0    0 -1/6    0
[2,]    0    1    0   -1    0
[3,]    0    0    1   -1    0
[4,]    0    0    0  1/6    1

row: 4 

 multiply row 4 by 6 
     [,1] [,2] [,3] [,4] [,5]
[1,]    1    0    0 -1/6    0
[2,]    0    1    0   -1    0
[3,]    0    0    1   -1    0
[4,]    0    0    0    1    6

 multiply row 4 by 1/6 and add to row 1 
     [,1] [,2] [,3] [,4] [,5]
[1,]  1    0    0    0    1  
[2,]  0    1    0   -1    0  
[3,]  0    0    1   -1    0  
[4,]  0    0    0    1    6  

 multiply row 4 by 1 and add to row 2 
     [,1] [,2] [,3] [,4] [,5]
[1,]  1    0    0    0    1  
[2,]  0    1    0    0    6  
[3,]  0    0    1   -1    0  
[4,]  0    0    0    1    6  

 multiply row 4 by 1 and add to row 3 
     [,1] [,2] [,3] [,4] [,5]
[1,] 1    0    0    0    1   
[2,] 0    1    0    0    6   
[3,] 0    0    1    0    6   
[4,] 0    0    0    1    6   

Another Solution

\[\eqalign{1x -2y + 4z &=& 12\\ 2x -y + 5z &=& 18\\ -x + 3y -3z &=& -8\\}\]

\[\left[\begin1&-2&4&12\\ 2&-1&5&18\\ -1&3&-3&-8\\\end{matrix}\right]\]


Initial matrix:
     [,1] [,2] [,3] [,4]
[1,]  1    1    1    6  
[2,]  1    2    3   14  
[3,]  3    2   -1    4  

row: 1 

 exchange rows 1 and 3 
     [,1] [,2] [,3] [,4]
[1,]  3    2   -1    4  
[2,]  1    2    3   14  
[3,]  1    1    1    6  

 multiply row 1 by 1/3 
     [,1] [,2] [,3] [,4]
[1,]    1  2/3 -1/3  4/3
[2,]    1    2    3   14
[3,]    1    1    1    6

 subtract row 1 from row 2 
     [,1] [,2] [,3] [,4]
[1,]    1  2/3 -1/3  4/3
[2,]    0  4/3 10/3 38/3
[3,]    1    1    1    6

 subtract row 1 from row 3 
     [,1] [,2] [,3] [,4]
[1,]    1  2/3 -1/3  4/3
[2,]    0  4/3 10/3 38/3
[3,]    0  1/3  4/3 14/3

row: 2 

 multiply row 2 by 3/4 
     [,1] [,2] [,3] [,4]
[1,]    1  2/3 -1/3  4/3
[2,]    0    1  5/2 19/2
[3,]    0  1/3  4/3 14/3

 multiply row 2 by 2/3 and subtract from row 1 
     [,1] [,2] [,3] [,4]
[1,]    1    0   -2   -5
[2,]    0    1  5/2 19/2
[3,]    0  1/3  4/3 14/3

 multiply row 2 by 1/3 and subtract from row 3 
     [,1] [,2] [,3] [,4]
[1,]    1    0   -2   -5
[2,]    0    1  5/2 19/2
[3,]    0    0  1/2  3/2

row: 3 

 multiply row 3 by 2 
     [,1] [,2] [,3] [,4]
[1,]    1    0   -2   -5
[2,]    0    1  5/2 19/2
[3,]    0    0    1    3

 multiply row 3 by 2 and add to row 1 
     [,1] [,2] [,3] [,4]
[1,]    1    0    0    1
[2,]    0    1  5/2 19/2
[3,]    0    0    1    3

 multiply row 3 by 5/2 and subtract from row 2 
     [,1] [,2] [,3] [,4]
[1,] 1    0    0    1   
[2,] 0    1    0    2   
[3,] 0    0    1    3