Showing posts with label equations. Show all posts
Showing posts with label equations. Show all posts

Monday, February 26, 2018

EqualX: The Power of LaTeX in a Nicely Pre-Configured Interface

A few weeks ago while putting together my elevator pitch video I found myself in need of a few nicely-typeset equations to show in it. I knew the solution would involve \(\LaTeX\) (which I've written in praise of before), but many \(\LaTeX\) editors are geared towards writing substantial papers. There's a bit of boilerplate code you need to set up, and it feels like overkill if you just want a picture of a few equations, as I did. (It's much like setting up a webpage: it's not a problem for a substantial page, but if you just want to put a sentence or two on it then your boilerplate code will be longer than your content!)

Thankfully while looking around online I stumbled upon a program called EqualX which is dedicated to taking care of that initial busywork and letting you simply create equations and formulae and export the result to seven different formats, including JPG, PNG, PDF, and (most importantly for my purposes) SVG.

 The eagle-eyed may notice the presence of \(\tau\) instead of \(\pi\)…

This picture shows the exceedingly simple interface. You just write your math in the bottom box, and by default EqualX will compile what's written there every one and a half seconds after you've finished typing into what you see in the middle box (though this behavior is configurable, and you can turn off the auto-updating if you like and just update it manually). When you're done, simply right-click in the middle box to set your export format, then save your output it to an image. Easy as \(\pi\)!

Okay, even I feel bad about that pun. A hui hou, folks!

Thursday, December 25, 2014

The Twelve Days of Christmas: Fun with Algebra

If you're like me, after hearing the song "The Twelve Days of Christmas" for the umpteenth time, you start wondering how all those gifts stack up. How many lords-a-leaping do you end up with at the end, anyway? What do you have the most of? And what's the total?

This problem can be solved by a little bit of math no more complicated than multiplication, but this being my blog I'm going to complicate things unnecessarily for fun. Let's call an arbitrary day of Christmas n (where \(1\leq n \leq12\)). The number of gifts given for the first time on that day is then also n (one partridge in a pear tree on the first day, two turtle doves on the second day, etc.). Then the total number of each gift is simply n times the number of times that gift is given. A little thought shows that this number is simply \(13-n\) (a partridge in a pear tree will end up being given on all twelve days, while the twelve drummers will end up being given only once on the twelfth day).

Putting these facts together, we arrive at a function (I'll call it "g" for "gifts") that will give us the total number of gifts of a particular type received, given a day of Christmas as input. Symbolically:
\[\text{g}(n)=n\cdot(13-n)=-n^2+13n\]This is a simple quadratic equation (a parabola, to be exact); I've marked the locations of integer value inputs in the plot below with annotations to show what each one is.


Looking at this plot, we see that the number of each gift begins at a minimum of twelve, rises to a maximum of forty-two for days 6 & 7, and drops off again to twelve on the twelfth day.

This leaves us with the question of how many total gifts you would receive from all this. Luckily, this is very simple: since the number of gifts is symmetrical after the sixth day, we can simply evaluation the following equation:
\[\text{Total gifts}=2\cdot(12+22+30+36+40+42)=364\]which, I think we can agree, is a whole lot of gifts. A hui hou!

Edit (1/16/2016): Of course, what escaped me at the time is that the song is actually about discrete gifts, not continuous ones, and thus trying to represent it as a continuous function as I did above makes pretty much zero sense.

I'd actually originally planned to do some calculus and integrate under the curve where the gray shaded part is and show how it came out to 364 as well…except it doesn't. I couldn't figure out why at the time and thus just sort of ignored it while leaving the talk leading up to the subject intact, leading to a somewhat disjointed blog post. Sometime later I realized that it's because this is a situation where you can't describe something with a continuous function; instead of a parabola, each point should be connected by a straight line—and then the area underneath that collections of points and lines should add up to 364.

Friday, December 9, 2011

The Power of Calculus

Recently a classmate of mine asked for some help with a physics problem falling under the purview of classical mechanics, and I, not having had a chance to use the ol' calculus for a while, eagerly proffered it.

Start by imagining a jet fighter flying along at a supersonic speed, leaving a hyperbolic shock wave (the famous "sonic boom") behind it.

(Pretend the red dot is a jet fighter.)

Now, the only two pieces of information we have about this problem is that the angle the shock wave makes with the horizontal is 30\(^\circ\), and that the speed of sound in the surrounding air is 330 meters/second. Can we figure out the plane's speed using just this information? You're probably not too surprised to hear that, indeed, we can, through the power of calculus.

Calculus is, at its heart, a study of how things change in relation to each other. And what is speed, but a measure of how position is changing with time? In the language of calculus, we can represent this using differentials, which give rise to differential equations. Differentials themselves are odd mathematical beasts, whose existence has been hotly debated over the centuries since Leibniz first proposed them, but like good physicists we can ignore that aspect of their nature for this post and focus instead on how we can use them.

Let's assume the jet is moving in the positive \(x\) direction, so that we can represent the jet's position by \(x\). This is simply a function of time (we're assuming the jet moves at constant speed), so \(x=f(t)\). We don't know what \(f(t)\) is yet, but if we find it out, we can then differentiate \(x\) to get the speed. I'm going to gloss over how exactly we accomplish that (it's not too difficult, it just takes a while to explain), but it involves taking a differential of the variable on each side of the equation \((dx=f\,'(t)dt)\), then dividing one by the other to get a derivative,
\[\frac{dx}{dt}=f\,'(t)\tag{1}\]
Such a cavalier treatment of differentials is likely to drive any mathematician reading this crazy, but it works well enough for physicists. The prime (\('\)) on the \(f\,'(t)\) simply says that the function it represents (which we also don't know) is simply the first derivative of \(f(t)\). We could continue to take derivatives, but there's no need for this problem (a second derivative would tell us about the jet's acceleration, for example).

Equation \((1)\) can be thought of as the instantaneous change in the jet's position divided by an instantaneous amount of time. Since we can't attack this equation directly with the information we have, let's look at it from another angle. We know information about the shock wave the jet is leaving that could be helpful to us. To see how so, let's briefly review how a sonic boom forms.

When a jet is traveling at sub-sonic speeds, any noise emitted by the jet will be able to expand out from it in a circle. If the jet had a system that emitted brief "pings" several times a second, it might look something like this if you could see the pressure front of the sounds waves:


Note how the sounds waves are closer together in front, and farther apart in back. If you keep increasing the jet's speed, the wave fronts will get closer and closer to each other, until:


BAM! the jet exceeds the speed of sound, meaning that it is now leaving those expanding circles of sound behind as it out-races them. The expanding wave fronts naturally create a hyperbolic shape behind the jet, leading to a huge buildup of sound that all hits at once as the shock wave passes a point, leading to a sonic boom.

Now, from the problem, we know one piece of information about these circles: namely, that they expand at the speed of sound, 330 m/s. In the picture above I've drawn in a radius of the largest circle, call its length \(r\). How fast the length of \(r\) changes can be represented mathematically as
\[\frac{dr}{dt}=330\tag{2}\]
where the units are implicitly recognized to be m/s (although it is important to keep units in mind to make sure the answer we eventually get makes sense). If we want to know the length of \(r\) as a function of time, we can antidifferentiate it in a manner analogous to how we differentiated \(x\) a while ago. Although in more complicated case antidifferentiation is more an art than a science when done by hand, it's fairly simple for this simple equation. First we multiply by \(dt\) on both sides (again, making mathematicians wince), then antidifferentiate (which we denote with the special symbol \(\int\) ). Antidifferentiation "undoes" the action of differentiation in the same way that multiplication "undoes" division, and that fact is so important it's one of the Fundamental Theorems of Calculus.
\[\begin{align}
dr&=330\,dt\\
\int dr&=\int330\,dt\\
\int dr&=330\int dt\\
r&=330t\tag{3}\end{align}\]
Now, what this equation tells us is that the length of \(r\) is equal to the time (from some specified starting point) times 330. We could re-write it in a manner equivalent to equation \((1)\), \(r=g(t)\), except that in this case we know that \(g(t)=330t\).

So, we know how fast the shock fronts from the sound waves expand. How does this help us? Well, note that the radius creates a right angle to the shock wave surface (i.e., the circle is tangent to the shock wave where they meet). This means that we have a right triangle, and we know from the information provided that the smaller angle is 30\(^\circ\).

In the figure below I've redrawn this triangle with just the essential information. We have the two known angles (and by extension the third), \(r\), and \(x\). We know how \(r\) is changing with time (\(dr/dt=330\)); can we determine how \(x\) is changing?


We can, if we can figure out a relation between \(r\) and \(x\). From basic trigonometry we know that \(r=x\sin30^\circ\) (Strictly speaking this wouldn't be an actual triangle because the hyperbolic nature of the shock wave would mean that the right corner of the triangle would be rounded instead of pointy, but it's close enough to reality to be useful for this simple problem.). But from equation \((3)\) above, we also know that \(r=330t\). If we combine those two equations, and do a little algebra, we can figure out how \(x\) depends on \(t\), i.e., what \(f(t)\) is in equation \((1)\):
\[\begin{align}
330t&=x\sin30^\circ\\
x&=\frac{330t}{\sin30^\circ}=f(t)\tag{4}\\
\end{align}\]
Remembering our discussion from above, we know that we can find the speed of the plane simply by differentiating equation \((4)\). When we do that, we get
\[\begin{align}
x&=\frac{330t}{\sin30^\circ}\\
dx&=\frac{330}{\sin30^\circ}dt\\
\frac{dx}{dt}&=\frac{330}{\sin30^\circ}=f\,'(t)\tag{5}
\end{align}\]
(again setting mathematicians' teeth on edge). So the speed of the jet turns out to be \(330/\sin30^\circ=660\) m/s. We can sanity check our work by noting that this is greater than the speed of sound (by twice), as it should be since the plane is supposedly flying supersonically. We could also generalize this into a formula for any angle that the shock wave makes by replacing the 30\(^\circ\) by a variable (say, \(\theta\)). Then we would have
\[\frac{dx}{dt}=\frac{330}{\sin\theta}\tag{6}\]
which would allow us to calculate the plane's speed for any (valid) angle we could measure.

Now, you may be looking at that last equation and thinking to yourself that it's putting the cart before the horse, so to speak. After all, the angle of the shock wave is dependent on the speed of the jet, not the other way 'round \(-\) yet that's exactly what the equation seems to be saying. This is part of the beauty and power of calculus, that we can ascertain relationships among variables from unconventional directions. It all depends on what you're solving for. You could invert the equation to find the angle as a function of the speed like so,
\[\theta=\csc^{-1}\left(\frac{1}{330}\frac{dx}{dt}\right)\]
and it would be just as valid as equation \((6)\), and would  better reflect what's physically happening to boot, but as we've just seen that doesn't mean that equation \((6)\) can't be useful too.

So the lesson to take home is that calculus is an immensely powerful tool, precisely because it allows us to see the world in a different way, and one that allows us to unleash the full power of mathematics upon it. Calculus is, in my opinion, one of the seminal works of Western civilization, and one, moreover, that richly rewards its studiers. We could all, I think, stand to know a little more calculus.