Cal Perez

Senior Software Engineer. I also like to cook, paint, and play D&D and Warhammer RPG.

Brushing Up On Some Math

August 27, 2018

It's been a while since I've used the math I learned in high school and college. I wanted to review topics that I felt were relevant to understanding something like Maxwell's Equations, which I'll cover in my next post.

Fair warning that I'm not a mathematician so my explanations won't be precise. Instead I want to communicate the general ideas behind each concept and why they're useful.

Vector Fields

Vector fields can help us visualize functions that take a two dimensional input and spit out a two dimensional output. Take this function

f(x,y)=[3y3+y23yx3x2+3x]f(x,y) = \begin{bmatrix} 3y^3 + y^2 - 3y \\ x^3 - x^2 + 3x \end{bmatrix}

which looks like

Vector Field Example

Each arrow represents a vector, which is a collection of values like a magnitude with a direction. Typically, color is used to denote magnitude instead of length to avoid a messy graph. In this example, the pink denotes a higher magnitude.

We can also get 3D vector fields, but I wanted to keep it simple with two dimensions.

So if we take the point (1,1)(1,1)

f(1,1)=[3(1)3+(1)23(1)(1)3(1)2+3(1)]=[3+1311+3]=[13]\begin{align} f(1, 1) &= \lbrack _{3(1)^3 + (1)^2 - 3(1)}^{(1)^3 - (1)^2 + 3(1)} \rbrack \nonumber \\ &= \lbrack _{3 + 1 - 3}^{1 - 1 + 3} \rbrack \nonumber \\ &= \lbrack _{1}^{3} \rbrack \nonumber \end{align}

we'd get the vector [13][_{1}^{3}] which is the same as saying start at some point and go 1 unit to the right and 3 units up. The hypotenuse of that triangle is the resulting vector.

Vector fields are common in electrodynamics and fluid dynamics to represent the flow of electrons or the flow of a liquid. For example, if we took a snapshot of a moving pool of water and measured the vector velocity of different points in the pool, we'd get a vector field.

This video explains it really well.

Transforming Vectors

Let's say we have two vectors:

a=[312]\vec{a} = \begin{bmatrix} 3 \\ -1 \\ 2 \end{bmatrix}

b=[131]\vec{b} = \begin{bmatrix} -1 \\ 3 \\ 1 \end{bmatrix}

Vectors a=[3,-1,2], b=[-1,4,1]

I want to illustrate transformations that you can make on vectors in the next few sections to better understand vector's uses.

Vector Addition

Adding vectors together is simple; we just need to add the corresponding components of each vector.

a+b=[ax+bxay+byaz+bz]=[3+11+32+1]=[223]\vec{a} + \vec{b} = \begin{bmatrix} a_{x} + b_{x}\\ a_{y} + b_{y}\\ a_{z} + b_{z} \end{bmatrix} = \begin{bmatrix} 3 + -1\\ -1 + 3 \\ 2 + 1 \end{bmatrix} = \begin{bmatrix} 2\\ 2 \\ 3 \end{bmatrix}

This will always result in another vector.

Why would we add vectors though?

If we think about it from a physics perspective, what else is considered a vector? Forces! So if we had two opposing forces or multiple forces interacting with each other, we can get the resulting force which will be a vector.

Scalar Multiplication

Multiplying a vector by a scalar (a real number) scales each component in a vector.

3a=3[312]=[936]3\vec{a} = 3\begin{bmatrix} 3 \\ -1 \\ 2 \end{bmatrix} = \begin{bmatrix} 9 \\ -3 \\ 6 \end{bmatrix}

This will also always result in another vector.

Dot Product

The dot product is a little weird:

ab=axbx+ayby+azbz=(3×1)+(1×3)+(2×1)=4\vec{a} \cdotp \vec{b} = a_{x}b_{x} + a_{y}b_{y} + a_{z}b_{z} = (3 \times -1) + (-1 \times 3) + (2 \times 1) = -4

We just need to multiply the corresponding components for each vector and sum the products.

And when an angle is given between the vectors, we can use:

ab=abcosθ\vec{a} \cdotp \vec{b} = \lVert\vec{a}\rVert \lVert\vec{b}\rVert \cos\theta

We multiply the magnitude of a\vec{a}, the magnitude of b\vec{b}, and the cosine of the angle between them. Using the Pythagorean Theorem, the magnitude of a vector can be calculated with ax2+ay2+az2\sqrt{a_x^2 + a_y^2 + a_z^2} .

However, since the result will always be a scalar why is the dot product even useful?

The dot product lets us take direction into account when we're calculating how a particle is affected by a force, for example, since we break down the force vector into its components. It would give us the force parallel to the direction we want from the force being applied to a particle from all directions.

Cross Product

The cross product isn't as weird as the dot product:

a×b=[aybzazbyazbxaxbzaxbyaybx]=[(11)(23)(21)(31)(33)(11)]=[758]\vec{a} \times \vec{b} = \begin{bmatrix} a_{y}b_{z} - a_{z}b_{y} \\ a_{z}b_{x} - a_{x}b_{z} \\ a_{x}b_{y} - a_{y}b_{x} \end{bmatrix} = \begin{bmatrix} (-1 *1) - (2* 3)\\ (2 *-1) - (3* 1) \\ (3 *3) - (-1* -1) \end{bmatrix} = \begin{bmatrix} -7\\ -5 \\ 8 \end{bmatrix}

And when an angle is defined we can use:

a×b=absinθn^\vec{a} \times \vec{b} = \lVert \vec{a} \rVert \lVert \vec{b} \rVert \sin \theta \, \hat{n}

where n^\hat{n} is the unit vector for a\vec{a} and b\vec{b}.

The cross product can only be found in three dimensions. The result is always a vector perpendicular to both original vectors.

Derivatives

Derivatives are the key to understanding how a function changes over time. If we had a linear graph it would be a simple task to find its slope using "rise over run" or Δy/Δx\Delta y / \Delta x. That result would be completely accurate for the rate of change at any point on the curve as xx approaches infinity.

But when we need the rate of change at any point on a more complex graph we need to find the derivative for the curve. So what exactly is a derivative?

It's basically an infinitesimally small rise over an infinitesimally small run.

Delta y delta x getting smaller

Mathematically this is represented as

f(x)=limf(x+h)f(x)/hf\prime(x) = \lim\limits_\infty f(x + h) - f(x) / h

But instead of using this longer interpretation we summarize it as dy/dxdy/dx where dd represents an infinitesimally small change.

I'm not going to over how to find the derivatives of exponential or trigonometric functions because I don't want this post to be a novel, but the most important thing to remember is that the derivative represents how the value of a function changes with a change in x.

Integrals

Integrals are the answer to finding the area underneath a curve between a set of boundaries.

Sample Graph with Area

So if we wanted the area under the curve between aa and bb then we would need to do abf(x)dx\int_{a}^{b} f(x) \, dx where dxdx is an infinitesimally small change in xx, f(x)f(x) is the value of the function at some xx, and the \int is the summation of all of those infinitesimally small slices of area.

Graph with smaller and smaller slices

Why do we use integrals, though?

Curves can represent rates of change like how a car's velocity changes over time. If we wanted to find the distance that the car traveled then we integrate over that velocity curve for that specified time interval. The solution to that definite integral would be the distance.

It's also important to note that because of the Fundamental Theorem of Calculus we're able to have an integral (or an anti-derivative) for every derivative.

Definite Integrals

Integrals with an upper and lower bound, like the example above. When solving definite integrals we end up with a number, a definite solution. For example:

252xdx=[x2]25=5222=21\int_2^5 2x \, dx = \lbrack x^2 \rbrack_2^5 = 5^2 - 2^2 = 21

Indefinite Integrals

Integrals without bounds. When solving indefinite integrals we end up with another function with respect to the variable we are integrating for. For example:

x4+2xdx=x5/5+x2+K\int x^4 + 2x \, dx = x^5 / 5 + x^2 + K

Line Integrals

Both of the examples above describe integrals along a straight line (the x axis typically), but what do we do when we're trying to find the area of the "wall" created by the intersection of this graph and this path?

Example graph for line integral

Notice how the blue curve on the xy plane is following a winding path instead of a straight line. This is how line integrals get their name, even though it would make more sense to call them path integrals or curve integrals.

Given that this graph is represented by f(x,y)=x2+y2f(x, y) = x^2 + y^2 and the curve that is the foundation for the "wall" is a quarter circle with its center on the origin, we can deduce a few things:

  • xx can be represented by x=costx = \cos t
  • yy can be represented by y=sinty = \sin t
  • tt is an arbitrary variable for the degrees or radians in xx and yy
  • From our unit circle days, we know that 0tπ/20 \leq t \leq \pi /2

Now, how do we solve for the area under this curve along this path?

Basically, we're taking small changes in xx and small changes in yy to represent a section of the curve. Like this:

Example graph for line integral

We know we can represent ΔS\Delta S as dSdS for an infinitesimally small change. Using Pythagorean Theorem, we know that

dS=(dx/dt)2+(dy/dt)2dtdS = \sqrt{(dx/dt)^2 + (dy/dt)^2} dt

And plugging it in we get

t=0f(x,y)dS=t=0cos2t+sin2t(dx/dt)2+(dy/dt)2dt\int_{t=0} f(x, y) \, dS = \int_{t=0} \cos^2 t + \sin^2 t \, \sqrt{(dx/dt)^2 + (dy/dt)^2} dt

(The upper limit should be π/2\pi / 2 but Katex was giving me trouble)

Then if we find dx/dtdx/dt and dy/dtdy/dt of xx and yy we can fill in more information.

I'm not going to solve this integral since me doing a bunch of math would be a lot and I'm too new at Katex to make it render the way I want. I want to stress we should remember that the area we're trying to find is the result of projecting a line or a curve onto another graph in the same space.

In other words, we're raising the foundation of the wall (the line in line integral) to the ceiling (another curve or graph in the same space). Then we put the foundation in terms of the ceiling and solve for the area.

Previous

Big O

Next

Maxwell's Equations