Link to this document's Jupyter Notebook

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 asynchronously, 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 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: Projections

Graph showing how one vector can be projected onto another vector by forming a right triangle

Image from: https://en.wikipedia.org/wiki/Vector_projection

Agenda for today's class (80 minutes)

  1. (20 minutes) Pre-Class Review
  2. (30 minutes) Understanding Projections with Code
  3. (30 minutes) Gram-Schmidt Orthoganalization Process

1. Pre-class Review


2. Understanding Projections With Code

In this in-class assignment, we are going to avoid some of the more advanced libraries ((i.e. no numpy or scipy or sympy) to try to get a better understanding about what is going on in the math. The following code implements some common linear algebra functions:

Projection function

DO THIS: Write a function that projects vector $v$ onto vector $u$. Do not use the numpy library. Instead use the functions provided above:

$$\mbox{proj}_u v = \frac{v \cdot u}{u \cdot u} u$$

Make sure this function will work for any size of $v$ and $u$.

Let's test your function. Below are two example vectors. Make sure you get the correct answers. You may want to test this code with more than one set of vectors.

Visualizing projections

DO THIS:See if you can design and implement a small function that takes two vectors ($a$ and $b$) as inputs and generates a figure similar to the one above.

I.e. a black line from the origin to "$b$", a black line from origin to "$a$"; a green line showing the "$a$" component in the "$b$" direction and a red line showing the "$a$" component orthogonal to the green line. Also see section titled "Projection of One Vector onto Another Vector" in Section 4.6 on page 258 of the book.

When complete, show your solution to the instructor.


3. Gram-Schmidt Orthoganalization Process

DO THIS: Implement the Gram-Schmidt orthoganalization process from the Hefron textbook (page 282). This function takes a $m \times n$ Matrix $A$ with linearly independent columns as input and return a $m \times n$ Matrix $G$ with orthogonal column vectors. The basic algorithm works as follows:

Use the following function definition as a template:

Here, we are going to test your function using the vectors:

QUESTION: What is the Big-O complexity of the Gram-Schmidt process?

Put 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 asynchronously, turn in your assignment using D2L.

Course Resources:

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