A few applications we’ll see this semester
Math 221 Linear Algebra, Fall 2021

T. Ratliff, Wheaton College
ratliff_thomas@wheatoncollege.edu

Solving systems of equations

1. Solve the system  
	2x + 3y =  7
	4x  - 2y = -10

Answer is. . .

x = -1,   y = 3

What does this mean geometrically?

Plot[{ 7/3 - 2/3 x, 5 + 2x},{x,-5,4}]

2. Solve the system  
	3x  + 6y = 2
	-x   - 2y  = 1

Plot[{(2-3x)/6, (1+x)/-2},{x,-4,4}]

3. Solve the system  
	2x  +  2y  = 4
	3x  +  3y = 6

Plot[{(4-2x)/2, (6-3x)/3},{x,-4,4}]

4. Solve the system  
	  x              -    3z   = -5
	2x  +    y                =  4
	  x   +  2y  + 12z  = 9

p1=ContourPlot3D[{x-3z==-5, 2x+y==4, x+2y+12z==9},{x,-21,-17}, {y,40,44},{z,-6,-3}];
p2=Graphics3D[{Red,PointSize[0.05],Point[{-19,42,-14/3}]}];
Show[p1,p2]

5. Solve the system  
	  x   -     y   +    3z   = 2
	             y    +    2z   =  -1
	  x               +    5z  = 2

ContourPlot3D[{x-y+3z==2, y+2z==-1, x+5z==2},{x,-2,2}, {y,-2,0.5},{z,-1,1.5}]

6. Solve the system  
	  x  +    y    +     z    =  2
	  x  +  2y    +     z   =  3
	2x  +  3y  +    2z  = 5

ContourPlot3D[{x+y+z==2,x+2y+z==3,2x+3y+2z==5},{x,-3,3},{y,-1,2},{z,-2,2},AxesLabel->Automatic]

Computer graphics - Simple Example

Start with a square

sq={ {1,0},{2,0}, {2,1},{1,1},{1,0}};
ListPlot[sq, Joined->True, PlotRange->{ {-4,4},{-4,4}},AspectRatio->1, PlotStyle->{Thickness[0.01]}]

Look at points that form corners of the square

sq //MatrixForm

Rotate square by 2π/3 radians counter clockwise

rMatrix = {{Cos[2Pi/3], -Sin[2Pi/3]},{Sin[2Pi/3], Cos[2Pi/3]}};
rsq = Transpose[rMatrix.Transpose[sq]];
ListPlot[{sq,rsq}, Joined->True, PlotRange->{ {-4,4},{-4,4}},AspectRatio->1, PlotStyle->{Thickness[0.01]}]

We do this by multiplying the list of points by a particular matrix to get a  new list of points

rMatrix//MatrixForm

rsq //MatrixForm

Skew the square in the positive x-direction

sMatrix = {{1,1},{0,1}};
ssq = Transpose[sMatrix.Transpose[sq]];
ListPlot[{sq,ssq}, Joined->True, PlotRange->{ {-4,4},{-4,4}},AspectRatio->1, PlotStyle->{Thickness[0.01]}]

We do this by multiplying the list of points by a different matrix to get another  new list of points

sMatrix//MatrixForm

ssq //MatrixForm

What if we want to skew and then rotate?

srMatrix = rMatrix.sMatrix;
srsq = Transpose[srMatrix.Transpose[sq]];
ListPlot[{sq,srsq}, Joined->True, PlotRange->{ {-4,4},{-4,4}},AspectRatio->1, PlotStyle->{Thickness[0.01]}]

We multiply our two matrices to get the single matrix to perform this transformation

srMatrix//MatrixForm

srsq // MatrixForm

Least-squares regression line

Given a scatterplot of points

pts=Table[ {i, i+ RandomVariate[NormalDistribution[100,50]]},{i,2,200}];
ListPlot[pts]

How do you find the line that best fits this data?

m=Table[ {pts[[i,1]],1},{i,1,Length[pts]}];
b=pts[[All,2]];
lsq=LeastSquares[m,b];
p1=ListPlot[pts];
p2=Plot[ lsq[[1]]x+lsq[[2]], {x,0,200},PlotStyle->{Red}];
Show[p1,p2]

Same techniques have applications in lots of different areas

Singular Value Decomposition

Photo from Boston Public Market on Hanover Street

image =

The photo is 686 x 948 = 650,328 pixels.  
Can we reduce the storage size if we’re willing to reduce the resolution?

imageMatrix= ImageData[image,"Byte"];
{iMu, iMs, iMv} = SingularValueDecomposition[N[imageMatrix],50] ;
svgMatrix = iMu.iMs.Transpose[iMv];
Image[svgMatrix/256]

This image is still 686 x 948, but we are able to generate it using 1,684 x 50 = 84,200 values

Uses the Singular Value Decomposition

Can really think of what we’re doing is smoothing by being willing to lose some resolution/sharp lines. 
Same ideas are useful if have a set of data where you think there is noise and you want to “smooth” the rough spots. (This is really hand-wavy, I realize).