# Visualizing Eigenvectors with GlowScript

I owe this post entirely to my mathematics colleague Ethan Smith and his recent work on visualizing eigenvectors in a plane. This work is based in turn on the paper by Schoenfeld. I’ve taken the visualization to 3D with the help of GlowScript and Trinket.

I was instantly interested in this project becuase I’m looking for ways to bring concepts from linear algebra (e.g. matrices, eigenvalues, tensors, etc.) into introductory claculus-based physics courses. I want to do this in a way that fosters the need for modern computation and visualization of geometric properties.

The concept here is very simple. You create a three dimensional distribution of unit vectors. I chose a spherically symmetric distribution. There’s really no necessity to use unit vectors as far as I can see; it just makes the numbers easier to manage. You then operate on each of these vectors with a linear transformation, represented by a matrix multiplication. The transformed vectors are visualized with arrows with their tails at the tips of the unit vectors. The transformation’s eigenvectors are immediately visible by inspection as the vectors represented by arrows collinear with the arrows representing the original unit vectors.

Unfortunately, I can’t embed trinkets in this blog, so I’ll have to make do by providing a link. When you click the link below, the trinket will open in a new browser window. You should see the GlowScript/VPython code on the left and the visualization on the right. The original unit vectors are white and the transformed vectors are blue (arbitrary color choices). You’re looking for the blue arrows that are collinear with white arrows. Those are the transformation’s eigenvectors. You can experiment with changing the number of unit vectors. More importantly, you’re encouraged to experiment with different transformation to see the effects of different eigenvalues. (I will come back later and include a screenshot here.)

Click this link to open the eigenpictures trinket.

The default matrix has eigenvalues of 1, 2, and 1 and the visualization makes spotting the eigenvectors quite simple.

I think this could have applications in introductory physics for visualizing inertia tensors. They can be represented as ellipsoids whose axes are the eigenvalues. I look forward to exploring this idea, and I thank Ethan Smith for showing me this.

# Matter & Interactions II, Weeks 13 and 14

I’m combining two weeks in this post.

The first week, we dealt with magnetic forces. One thing that I have never thought much about is the fact that the quantity $\mathbf{v}\times\mathbf{B}$ is effectively an electric field, but one that depends on velocity. When velocity is involved, reference frames are involved, and that of course means Einstein is talking to us again. M&I addresses the fact that what we detect as an electric field and/or a magnetic field depends on our reference frame. This is fundamental material that I feel should be included in every introductory electromagnetic theory course. There’s really no good reason to omit it given that special relativity is a foundation of all contemporary physics. It’s sad to think that beginning next fall, our students won’t be exposed to this material any more.

The second week gets us into chapter 21, which presents Gauss’s law and Ampére’s law. There are many fine points and details to present here. I’ll try to list as many as I can think of.

• I use the words pierciness, flowiness, spreadingoutness, and swirliness to introduce the concepts of flux, circulation, divergence, and curl respectively.
• We have the term flux for the quantity given by surface integrals, but we rarely if ever see the term circulation for line integrals. I recommend introducing the term, primarly because it forms the basis for the definition of curl.
• The distinction between an open surface and a closed surface is very important.
• I, like M&I, prefer to write vector area as $\hat{n}\,\mathrm{d}A$ rather than $\mathrm{d}\mathbf{A}$ because it allows for introducing a “sneaky one” into the calculation of flux that lets a dot product become a product of scalars when the field is parallel to the surface’s unit normal:

$\mathbf{E}\cdot\hat{n}\,\mathrm{d}A=\left\lVert\mathbf{E}\right\rVert\hat{E}\cdot\hat{n}\,\mathrm{d}A=\left\lVert\mathbf{E}\right\rVert\underbrace{\hat{E}\cdot\hat{n}}_1\,\mathrm{d}A=\left\lVert\mathbf{E}\right\rVert\mathrm{d}A$

• Similarly, I like an element of vector length, at least for electromagnetic theory, as $\hat{t}\,\mathrm{d}\ell$ rather than $\mathrm{d}\mathbf{\ell}$ (the $\ell$ is supposed to be bold but it doesn’t look bold to me). I don’t think I have ever seen this notation in an introductory course before, but I like it because students have seen unit tangents in calculus and this notation closely parallels that for vector area as described above. Plus, it also allows for a “sneaky one” into the calculation of circulation when the field is parallel to the path’s unit tangent::

$\mathbf{B}\cdot\hat{t}\,\mathrm{d}\ell=\left\lVert\mathbf{B}\right\rVert\hat{B}\cdot\hat{t}\,\mathrm{d}\ell=\left\lVert\mathbf{B}\right\rVert\underbrace{\hat{B}\cdot\hat{t}}_1\,\mathrm{d}\ell=\left\lVert\mathbf{B}\right\rVert\mathrm{d}\ell$

• After this chapter, we can finally write Maxwell’s equations for the first time. I show them as both integral equations and as differential equations. One of my usual final exam questions is to write each of the four equations as both an integral equation and a differential equation and to provide a one sentence interpretation of each form of each equation.

That’s about it for these two chapters. I thought there was something else I wanted to talk about, but it seems to have escaped me and I’ll update this post if and when I remember it.

Feedback welcome as always.

# Vector Formalism in Introductory Physics I: Taking the Magnitude of Both Sides

TL;DR: I don’t like the way vectors are presented in calculus-based and algebra-based introductory physics. I think a more formal approach is warranted. This post addresses the problem of taking the magnitude of both sides of simple vector equations. If you want the details, read on.

This is the first post in a new series in which I will present a more formal approach to vectors in introductory physics. It will not have the same flavor as my recently begun series on angular quantities; that series serves a rather different purpose. However, there may be some slight overlap between the two series if it is appropriate.

I am also using this series to commit to paper (screen, really) some thoughts and ideas I have had for some time with the hope of turning them into papers for submission to The Physics Teacher. I’d appreciate any feedback on how useful this may be to the community.

To begin with, I want to address issues in the algebraic manipulation of vectors with an emphasis on coordinate-free methods. I feel that in current introductory physics courses, vectors are not exploited to their full potential. Instead of learning coordinate-free methods, students almost always learn to manipulate coordinate representations of vectors in orthonormal, Cartesian coordinate systems and I think that is unfortunate because it doesn’t always convey the physics in a powerful way. Physics is independent of one’s choice of coordinate system, and I think students should learn to manipulate vectors in a similar way.

Let’s begin by looking at a presumably simple vector equation:

$a\mathbf{A} = -5\mathbf{A}$

The object is to solve for $a$ given $\mathbf{A}$. Don’t be fooled; it’s more difficult than it looks. In my experience, students invariably try to divide both sides by $\mathbf{A}$ but of course this won’t work because vector division isn’t defined in Gibbsian vector analysis. Don’t let students get away with this if they try it! The reasons for not defining vector division will be the topic of a future post.

(UPDATE: Mathematics colleague Drew Lewis asked about solving this equation by combining like terms and factoring, leading to $(a+5)=0$ and then to $a = -5$. This is a perfectly valid way of solving the equation and it completely avoids the “division by a vector” issue. I want to call attention to that issue though, because when I show students this problem, they always (at least in my experience) try to solve it by dividing. Also, in future posts I will demonstrate how to solve other kinds of vector equations that must be solved by manipulating both dot products and cross products, each of which carries different geometric information, and I want to get students used to seeing and manipulating dot products. Thanks for asking Drew!)

One could simply say to “take the absolute value of both sides” like this:

$\left| a\mathbf{A} \right| = \left| -5\mathbf{A}\right|$

but this is problematic for two reasons. First, it destroys the sign on the righthand side. Second, a vector doesn’t have an absolute value because it’s not a number. Vectors have magnitude, not absolute value, which is an entirely different concept from that of absolute value and warrants separate consideration and a separate symbol.

We need to do something to each side to turn it into a scalar because we can divide by a scalar. Let’s try taking the dot product of both sides with the same vector, $\mathbf{A}$, and proceed as follows:

\begin{aligned} a\mathbf{A}\bullet\mathbf{A} &= -5\mathbf{A}\bullet\mathbf{A} && \text{dot both sides with the same vector} \\ a\lVert\mathbf{A}\rVert^2 &= -5\lVert\mathbf{A}\rVert^2 && \text{dot products become scalars} \\ \therefore a &= -5 && \text{solve} \end{aligned}

This is a better way to proceed. It’s formal, and indeed even pedantic, but I dare say it’s the best way to go if one wants to include dot products. Of course in this simple example, one can see the solution by inspection, but my goals here are to get students to stop thinking about the concept of dividing by a vector and to manipulate vectors algebraically without referring to a coordinate system.

Let’s now look at another example with a different vector on each side of the equation.

$a\mathbf{A} = -5\mathbf{B}$

Once again the object is to solve for $a$ given $\mathbf{A}$ and $\mathbf{B}$. Note that solving for either $\mathbf{A}$ or $\mathbf{B}$ is obviously trivial so I won’t address it; it’s simply a matter of scalar division. Solving for $a$ is more challenging because we must again suppress the urge to divide by a vector. I will show two possible solutions. Make sure you understand what’s being done in each step.

\begin{aligned} a\mathbf{A} &= -5\mathbf{B} && \text{given equation} \\ a\mathbf{A}\bullet\mathbf{A} &= -5\mathbf{B}\bullet\mathbf{A} && \text{dot both sides with the same vector} \\ a\mathbf{A}\bullet\mathbf{A} &= -5\mathbf{B}\bullet\left(\dfrac{-5}{\hphantom{-}a}\mathbf{B}\right) && \text{substitute from original equality} \\ a\lVert\mathbf{A}\rVert^2 &= \dfrac{25}{a}\lVert\mathbf{B}\rVert^2 && \text{dot products become scalars} \\ a^2 &= 25\dfrac{\lVert\mathbf{B}\rVert^2}{\lVert\mathbf{A}\rVert^2} && \text{rearrange} \\ \therefore a &= \pm 5\dfrac{\lVert\mathbf{B}\rVert}{\lVert\mathbf{A}\rVert} && \text{solve} \end{aligned}

We get two solutions, and they are geometrically opposite each other; that’s the physical implication of the signs. (I suppose we could argue over whether or not to just take the principal square root, but I don’t think we should do that here because it would throw away potentially useful geometric information.) We can find a cleaner solution that accounts for this. Consider the following solution which exploits the concepts of “factoring” a vector into a magnitude and a direction and the properties of the dot product.

\begin{aligned} a\mathbf{A} &= -5\mathbf{B} && \text{given equation} \\ a\mathbf{A}\bullet\mathbf{A} &= -5\mathbf{B}\bullet\mathbf{A} && \text{dot both sides with \textbf{A}} \\ a\lVert\mathbf{A}\rVert^2 &= -5\lVert\mathbf{B}\rVert\widehat{\mathbf{B}}\bullet\lVert\mathbf{A}\rVert\widehat{\mathbf{A}} && \text{factor each vector into magnitude and direction} \\ a\lVert\mathbf{A}\rVert^2 &= -5\lVert\mathbf{B}\rVert\lVert\mathbf{A}\rVert\,\widehat{\mathbf{B}}\bullet\widehat{\mathbf{A}} && \text{push magnitude through the dot product} \\ \therefore a &= -5\dfrac{\lVert\mathbf{B}\rVert}{\lVert\mathbf{A}\rVert}\,\widehat{\mathbf{B}}\bullet\widehat{\mathbf{A}} && \text{solve} \end{aligned}

See the geometry? It’s in the factor $\widehat{\mathbf B}\bullet\widehat{\mathbf A}$. If $\mathbf{A}$ and $\mathbf{B}$ are parallel, this factor is $+1$ and if they are antiparallel it is $-1$. Convince yourself that those are the only two options in this case. (HINT: Show that each vector’s direction is a scalar multiple of the other vector’s direction.) This solution won’t work if the two vectors aren’t collinear. If we’re solving for $a$ then both vectors are assumed given and we know their relative geometry.

Let’s look at another example from first semester mechanics, Newton’s law of gravitation,

$\mathbf{F} = G\dfrac{M_1 M_2}{\lVert\mathbf{r}_{12}\rVert^2}\left( -\widehat{\mathbf r}_{12}\right)$

where $\mathbf{r}_{12} = \mathbf{r}_1 - \mathbf{r}_2$ and should be read as “the position of 1 relative to 2.” Let’s “take the magnitude of both sides” by first writing $\mathbf{F}$ in terms of its magnitude and direction, dotting each side with a vector, and dividing both sides by the resulting common factor.

\begin{aligned} \lVert\mathbf{F}\rVert\left(-\widehat{\mathbf{r}}_{12}\right) &= G\dfrac{M_1 M_2}{\lVert\mathbf{r}_{12}\rVert^2}\left( -\widehat{\mathbf{r}}_{12}\right) && \text{given equation} \\ \lVert\mathbf{F}\rVert\left(-\widehat{\mathbf{r}}_{12}\bullet\widehat{\mathbf{r}}_{12}\right) &= G\dfrac{M_1 M_2}{\lVert\mathbf{r}_{12}\rVert^2}\left(-\widehat{\mathbf{r}}_{12}\bullet\widehat{\mathbf{r}}_{12}\right) && \text{dot both sides with the same vector} \\ \lVert\mathbf{F}\rVert\left(-\lVert\widehat{\mathbf{r}}_{12}\rVert^2\right) &= G\dfrac{M_1 M_2}{\lVert\mathbf{r}_{12}\rVert^2}\left(-\lVert\widehat{\mathbf{r}}_{12}\rVert^2 \right) && \text{dot products become scalars} \\ \therefore \lVert\mathbf{F}\rVert &= G\dfrac{M_1 M_2}{\lVert\mathbf{r}_{12}\rVert^2} && \text{divide both sides by the same scalar} \end{aligned}

Okay, this isn’t an Earth-shattering result becuase we knew in advance it has to be the answer, but my point is how we formally went about getting this answer. More specifically, the point is how we went about it without dividing by a vector.

Let’s now consider a final example from introductory electromagnetic theory, and this was the example that got me thinking about this entire process of “taking the magnitude of both sides” about a year ago. It’s the expression for the electric force experienced by a charged particle in the presence of an electric field (obviously not its own electric field).

$\mathbf{F} = q\mathbf{E}$

That one vector is a scalar multiple of another means the two must be collinear, so they must either be parallel or antiparallel. An issue here is that $q$ is a signed quantity. Again, we have a choice about which vector with which to dot both sides; we could use $\mathbf{F}$ or we could use $\mathbf{E}$. If we use the former, we will eventually need to take the square root of the square of a signed quantity, which may lead us astray. Therefore, I suggest using the latter.

\begin{aligned} \mathbf{F} &= q\mathbf{E} && \text{given equation} \\ \mathbf{F}\bullet\mathbf{E} &= q\mathbf{E}\bullet\mathbf{E} && \text{dot both sides with the same vector} \\ \lVert\mathbf{F}\rVert\widehat{\mathbf{F}}\bullet\lVert\mathbf{E}\rVert\widehat{\mathbf{E}} &= q\lVert\mathbf{E}\rVert^2 && \text{factor LHS, simplify RHS} \\ \lVert\mathbf{F}\rVert\lVert\mathbf{E}\rVert\,\widehat{\mathbf{F}}\bullet\widehat{\mathbf{E}} &= q\lVert\mathbf{E}\rVert^2 && \text{push the magnitude through the dot product} \\ \therefore \lVert\mathbf{F}\rVert &= \dfrac{q}{\widehat{\mathbf{F}}\bullet\widehat{\mathbf{E}}}\lVert\mathbf{E}\rVert && \text{solve} \end{aligned}

This may look overly complicated, but it’s quite logical, and it reflects goemetry. If $q$ is negative, then the dot product will also be negative and the entire quantity will be positive. If $q$ is positive, then the dot product will also be positive and again the entire quantity will be positive. Geometry rescues us again, as it should in physics. We can also rearrange this expression to solve for either $q$ or $\lVert\mathbf{E}\rVert$ with the sign of $q$ properly accounted for by the dot product. By the way, $\widehat{\mathbf{F}}$ and $\widehat{\mathbf{E}}$ can’t be orthogonal becuase then their dot product would vanish and the above expression would blow up. Geometry and symmetry, particularly the latter, preclude this from happening.

In summary, “taking the magnitude of both sides” of a simple vector equation presents some challenges that are mitigated by exploiting geometry, something that is neglected in introductory calculus-based and algebra-based physics courses. I suggest we try to overcome this by showing students how to formally manipulate such equations. One advantage of doing this is students will see how vector algebra works in more detail than usual. Another advantage is that students will learn to exploit geometry in the absence of coordinate systems, which is one of the original purposes of using vectors after all.

Do you think this would make a good paper for The Physics Teacher? Feedback welcome!