Showing posts with label calculus. Show all posts
Showing posts with label calculus. Show all posts

Friday, December 12, 2014

Basic Physics: Part 0, Section 5: Derivatives--Exponential Function

In the last post we covered all the rules we needed for calculating derivatives, but I mentioned that there were two special case functions that weren't really special cases that we needed to cover. They are usually thought of as special cases because the way we habitually use and write them hides what's actually going on when we take their derivatives. The first case is the exponential function, and the second is the trig functions sine and cosine. 

The exponential function is something you may or may not have run across directly, depending on how far you got in math or how nerdy your friends are. But it affects or models nearly everything in your life, from population growth to radioactive decay, and is integral to oscillatory functions and nearly every branch of mathematically describable knowledge. The 'natural' number \(e\) is a transcendental number (meaning it's not the root of any integer polynomial) and it's irrational--meaning it never repeats a sequence and it doesn't 
end:
 $$ e = 2.718281828459045235360287471352662497757247093699959574966967... $$ More importantly, it seems to be kinda built into the fabric of the universe because like \(\pi\) it shows up everywhere. Also, it is integral to one of the most beautiful equations in ever--Euler's Identity: $$e^{i \pi} + 1 = 0$$ What's so special about this you ask? Well, it includes 5 of the most basic and important concepts in math and relates them all in an absurdly simple, beautiful way*. The natural number (\(e\)), \(\pi\) and the complex number \(i\) are the most important numbers you've never heard of or used. One and zero are so fundamental explaining why they are fundamental usually leads you in circles. It's also a bit off topic. Back to derivatives!

 The exponential function, the most basic form of which is $$ e^{x} $$ though you can put other stuff (sometimes a lot of stuff) in that exponent. It's usually cited as a special case for derivatives because if you write it the way most people do, it seems like it is it's own derivative:
$$f(x) = e^x$$
$$\frac{df}{dx}= e^x$$
which is weird and uncomfortable and shouldn't be, should it?

This seems to completely violate all the rules we set out, except that it actually follows all the rules and you can demonstrate it three ways. Firstly, if you have enough time and a graphing calculator capable of finding tangents to curves, you can manually (and tediously) show that \(e^x\) is a weird curve whose slope is described by itself. I'm going to skip this way.

Another way to go is to use the power series expansion. This way feels like cheating to me, because in the strictest sense of things, it's an approximation unless I expand the series to infinite terms, but it's also the clearest way for a lot of people.

Let's first start by discussing what a series expansion is. Have you ever wondered how mathematicians can calculate things like thousands of digits of Pi or the natural number when they aren't simple fractions? The answer is power series. Series let you expression something very very complicator or long in a compact format of a bunch of additions. The catch is that, unless you take it out to infinite terms, it's only an approximation. The good news is, you don't need to take it out to infinity for most intents and purposes, because you don't need an infinite amount of precision. You just need 5 or 10 or 100 decimal places worth of precision, which you can get with way less than infinite terms.

The power series expansion for \( e^x \) is
$$e^x = \sum_{n=0}^{\inf} \frac{x^n}{n!}$$
Which looks like a lot of gibberish, but is just mathematician shorthand for
$$e^x = 1 + \frac{x}{1} + \frac{x^2}{1*2} + \frac{x^3}{1*2*3}+\frac{x^4}{1*2*3*4}+....$$
and on and on forever. That ellipsis at the end indicates that it just keeps going like that.

Fortunately, this is something that we know how to deal with, using the rules we learned in section 4.
$$e^x = 1 + x + \frac{1}{2} x^2+ \frac{1}{6}x^3+\frac{1}{24}x^4+....$$
$$\frac{d}{dx} e^x = 0 + 1 + \frac{1}{2} x^1 * 2 +\frac{1}{6}x^2 *  3 + \frac{1}{24}x^3 * 4 + ...$$
$$\frac{d}{dx} e^x = 1 + x+\frac{1}{2}x^2 + \frac{1}{6}x^3  + ...$$

Which is right back where we started! This is a neat and useful property of the exponential function.

The third way is to engage a rule that we didn't discuss last time because it doesn't show up very much, but it's very similar to the chain rule--it's called the power rule and having shown I wasn't lying about the things in part 4, I hope you can just trust me on this one. It's a little messy at the beginning, but just hang with me until the end.

 The power rule goes like this. For a function that has the form of [constant] to the power of [function of variable], like \( f(x) = a^{u_x}\) where \(u_x\) just denotes that \(u\) is a function of \(x\) (yes, a function within a function, it's perfectly legal and it doesn't look as weird as it sounds when you say it out loud...er write it out verbally?), the derivative is
$$\frac{df}{dx} = a^{u_x} *\ln{a} * \frac{du}{dx} $$
Which...looks pretty awful, doesn't it? Just hang with me a little longer. Let's look at a test case. Let's let our \(f(x) = 3^{4x^2}\).
$$\frac{df}{dx} = 3^{4x^2} *\ln{3} * (4*2x) $$
$$\frac{df}{dx} =(8 x) (3^{4x^2}) *\ln{3}  $$
$$\frac{df}{dx} = 8x \ln{3} 3^{4x^2}$$

So, what happens when we apply this to \(e^x\)? Let's see:
$$\frac{d}{dx}(e^x) = e^x * \ln{e} *1$$
Now, the natural log (\(\ln\)) and the natural number are inverses of sorts, so \( \ln(e) =  1\). So that just leaves us with
$$\frac{d}{dx}(e^x) = e^x$$
A perfectly law abiding, if funky looking, function. In reality, it mainly looks weird when we take the derivative because we leave out that \( \ln{e} \) step. Think of it like how a native speaker will use contractions.

Let's test this out on a few more examples to get the hang of it. How about \( g(x) = e^{2x}\)?
$$\frac{dg}{dx} = e^{2x} * \frac{d}{dx} (2x)$$
$$\frac{dg}{dx} = e^{2x} * 2$$
$$\frac{dg}{dx} =2 e^{2x} $$

Still a little weird looking, but not bad from an execution standpoint. Let's do one more for practice.
$$h(x) = 3 e^{4x^2} $$
$$\frac{dh}{dx} = 3 e^{4x^2} * \frac{d}{dx}(4x^2) $$
$$\frac{dh}{dx} = 3 e^{4x^2} * 4*2*x$$
$$\frac{dh}{dx} = 24 x e^{4x^2} $$

Hopefully this has helped you to see that even things that are "special cases" are not exceptions to the rules. If anything is still unclear, please let me know in the comments! Next time, we'll deal with one more "special case", that of trig function derivatives.

*And one of the reasons I will never, ever support tau replacing pi. I don't care if it removes a factor of two from some calculations--it ruins the beauty of Euler's identity to have to divide the exponent by 2.

Updated 12/12/14 8 pm: Corrected the first example. Thanks to @Lacci for alerting me to the problem. 

Tuesday, August 19, 2014

Basic Physics: Part 0, Section 4: Derivatives

Previously in this series, we covered algebra, trigonometry, vectors and vector multiplication. Now (after more delay than I would have liked) it's time to tackle the elephant in the room--calculus.

No, please don't close this tab! I swear, it's not as scary as you've been told. If you made it through trig and vectors (which, if you are reading this I assume you have) you've really made it through more mind bending stuff than we will need to cover here.

Why cover calculus at all? Aren't there algebra-based physics courses at every university? Yes, yes there are. And anyone who has taught physics with only algebra, trig and vectors will tell you it's actually harder to teach physics without reference to derivatives and integrals. Newton invented/discovered calculus so he could describe his theory of gravity and motion (his notation was abysmal, though). Calculus is the mathematics of change. Algebra is the mathematics of stability. And physics is really boring if nothing ever moves.

Now, depending on when you went to school, learning calculus may have been reserved for the students who were good at math, or who hadn't been told that "math wasn't for them". I am here to tell you this is like telling students who are going to live in another country that they don't need to learn the past or future tense, they can get along just fine with the present tense. Technically, this is true in a lot of cases, but it limits their ability to get everything out of their trip. Try to think of calculus in this way--not as some strange new kind of math, but just a different tense in this language.

We'll begin where most calculus textbooks begin with derivatives. Calculus has a very intuitive explanation of derivatives: they are the slopes of lines. That's it. What makes derivatives interesting is that they give you the slope at any point along a line*. You will generally hear the included caveat that the line must be smooth and continuous, but this isn't a calc class and I'm not going to show you any equations which are not differentiable (capable of having their derivative taken), so we aren't going to worry about that here.

Let's start with the simplest case, a straight line going through the origin of our coordinate system:

In this case, the slope of the line is going to be the same everywhere, and we can find the slope using the tried and true "rise over run" method. In moving 4 units to the right, the line has moved 3 units up, so our slope \(a\) is $$ a = 3/4 = .75 $$ So far so good. Nothing scary or uncomfortable  to date. A little algebra, that's all, and a little reading off a plot. Now, what if we were just given the equation for this line, in the slope-intercept form encountered in algebra class: $$ y = ax$$ $$y = .75 x$$
Still not too bad. And if I had presented this to your first, you probably could have told me the slope of this line just from this--the coefficient of \(x\) gives the slope, so \(.75\). Congratulations, you just took your first derivative without knowing it!

So, if derivatives are that easy, you ask your computer suspiciously, why is there an entire semester of calculus dedicated to it, hmm? Well, two reasons. First of all, because there are way more complicated kinds of lines than straight lines, and second of all, no one dedicates an entire semester to derivatives. They usually also teach limits (proto-derivatives) and numerical integration (proto-integrals) in the same semester. Derivatives are usually 4-5 weeks of the semester, a lot of that learning special cases.

What if I gave you the line with the equation $$ y = x^2 + 3, $$ would you know what it's slope is? It looks similar to the linear equation in slope-intercept form, but you probably have a feeling that the \(x\) being squared complicates things. And it does, since \(x^2\) is a parabola.


Parabola!

Now, you could draw tangent lines at a sampling of points along the parabola, and find the slope of those tangent lines, plot those slope values and approximate the slope of \(y = x^2 + 3\) and you would find that it came close to \(2x\). I can't speak for everyone here, but I find doing that unbelievably boring. Some algebra teacher once made me do that once and  it was tiresome to say the least.

But calculus and the tool of differentiation gives us a much better way.  Remember, mathematicians do not "invent" new kinds of math to torture students and non-mathematicians. They develop new techniques because the old way was inefficient or tedious or just didn't work all that well. Calculus is  a great example of this. Rather than calculating a bunch of individual slope points and extrapolating what we think the slope is, we can find the exact slope with a few simple rules, and a little new notation.

Let's look at our parabola again. So we have the equation $$y = x^2 +3$$ which describes the line itself. If we want to say that we are looking at the equation for the slope of that line we can write it in Leibniz notation as $$ \frac{dy}{dx}$$ which is nice and concise (there is also Lagrange notation and Newton notation). But Leibniz is nice for beginning with because it has a nice math to english translation: the change in \(y\) over the change in \(x\). This is the more formal way to say "rise over run" and is more generally applicable. Also, now that we are finding the slope of the parabola everywhere we call it a "derivative", and we find it by the process of "differentiation".

To find this, we need two rules. The first rule is formally known as the "elementary power rule" but I just learned it as "this is how you do it". For a function \(f(x)\) that has the form (i.e., it looks like or follows the pattern of) $$ f(x) = c x^n $$ where \(c\) is a constant, \(x\) is the variable and \(n\) is a real number (usually integer, but not necessarily) the derivative can always be found in the following manner: $$\frac{df}{dx} = c*n*x^{n-1} $$ If you are wondering what that \(f(x)\) is doing here, since I kinda just started using it, think of it as a way to label a generic equation. You could keep saying \(y=\) such and such, but then it's not always clear which \(y\) you're talking about. If you instead use the notation of Letter(variable) it lets you label both the equation uniquely (function f, function g, function h) and specify which letter is acting as your variable (x, y, z). Neat, huh?

That's it. That is the most basic rule and definition of the derivative. For the special case where there is no variable, just a constant, the derivative of a constant is \(0\). So, to summarize,

  1. Given a function \( f(x) = c x^n\), the derivative is \(\frac{df}{dx} = c*n*x^{n-1}\).
  2. Given a constant function \(f(x) = c\), the derivative is \( \frac{df}{dx} = 0 \)

So, let's apply these rules to the equation for our parabola.
$$y = x^2 + 3$$
$$\frac{dy}{dx} = (2) x^{(2-1)} + 0$$
$$\frac{dy}{dx} = 2x^1 = 2x$$

And so we find in three lines of calculus the  same answer that a bunch of line drawing and measuring and plotting got you. Let's try another one, that's a little longer.
And really funky looking on a graph.
$$f(x) = 3 x^{5} - 2 x^{2} + x^{-3} $$
$$\frac{df}{dx} = 3*5 x^{(5-1)} - 2*2 x^{(2-1)} + -3 x^{(-3-1)} $$
$$\frac{df}{dx} = 15 x^{4} -4 x - 3 x^{-4} $$

Longer, but still not too bad, right? See, I told you calculus wasn't the terror it was made out to be. One more rule and we've knocked out all the differential calculus we'll need for both physics 1 and physics 2. This rule is called the "chain rule" and it covers almost every other situation we could face outside of a calculus book or more advanced physics. What it is, really, is a short cut when your variable of interest is buried inside a parenthetical expression, instead of having to bother to separate it out by algebra (if it can be separated by algebra at all).

Let's start with something that we could mess around with algebra and get it into a form that our first two rules apply. Let's begin with the equation $$g(x) = (x+2)^2$$ By using the FOIL method, we  find that this could also be stated as $$g(x) = x^2 + 4 x + 4$$ Using the two rules laid out above, we find that it's derivative is $$\frac{dg}{dx}= 2x + 4$$ Now we have something to check the chain rule against.
Displaced parabola!

The chain rule is a way to approach these things methodically, working from the outside in. You start by treating everything inside the parentheses as a block. It does not matter how complicated it is inside the parentheses, or how simple. Treat it all as though it were just the variable. So step one of the chain rule gives us $$\text{ Step 1: } \frac{dg}{dx} = 2 (x+2)^{2-1}$$
Now you take the derivative of what's inside the parentheses, and multiply that result by the result of Step 1. $$\text{Step 2: } \frac{dg}{dx} = 2(x+2)^{1} (1+0) = 2x+4$$
Lo and behold, it's the same result. Now for something this simple is using the chain rule worth it? Maybe, maybe not. But what about something that I don't know how to FOIL, like $$h(x)= (x+2)^{-1/2} =\frac{1}{\sqrt{x+2}} $$
How do you FOIL a square root?! Tell me!
Let's try the chain rule on this and see if it doesn't save us having to look that one up in an obscure algebra text.
Step 1: Ignore what's inside parentheses, take the derivative as if (blah blah) = variable.
$$\frac{dh}{dx} = (-.5)(x+2)^{(-.5 - 1)} $$
Step 2: Take the derivative of what's inside the parentheses, multiply it by Step 1.
$$ \frac{dh}{dx} = -.5(x+2)^{-1.5} (1)$$
Step 3: Simplify if necessary
$$\frac{dh}{dx} = -.5 (x+2) ^(\frac{-3}{2}) = \frac{-1}{2 (x+2)^{\frac{3}{2}}}$$

I can guarantee that that was easier than trying to FOIL a square root. But what about something really nasty, like THIS
Honestly had no idea what this would look like before I graphed it
Behold, the rollercoaster that is $$ k(x) = (x^3 + 2)^{-.5}$$ Surely my nasty, terrifying calculuses gets horrifying and complicated now, heh? Stupid physicistses.

Um, nope. Not really. Let's take a look, shall we?
Step 1: Ignore what's inside parentheses, take the derivative as if (blah blah) = variable.
$$\frac{dk}{dx} = (-\frac{1}{2})(x^3+2)^{(-.5 - 1)} $$
Step 2: Take the derivative of what's inside the parentheses, multiply it by Step 1.
$$ \frac{dk}{dx} = (-\frac{1}{2})(x^3+2)^{-1.5} (3x^2)$$
Step 3: Simplify if necessary
$$\frac{dh}{dx} = (\frac{-3x^2}{2})(x^3+2)^{-1.5}  = \frac{-3x^2}{2 (x^3+2)^{\frac{3}{2}}}$$

Still just 3 bite sized steps.

Ah ha, you say, but what if there are parentheses inside the parentheses? What if I have a russian nesting doll of a problem?

You just repeat step 2 until you run out of parentheses inside parentheses. But I honestly can't say that I've ever seen that happen.

And that's nearly all you really need to know about differential calculus to conquer introductory physics! Hopefully you can see, at least a little bit, why physicists and mathematicians love it. It's like upgrading from a hand drill to a power drill. Or a sheet of sandpaper to a power sander. It might take a little getting used to, but it is a very powerful tool in our toolbox and one that will open up the rules of the physical universe to us in a way that algebra just can't. Because as I said in the beginning, the physical world is dynamic and changing, and algebra is the math of the static and stable.

There are two "special cases" that aren't really special cases that we will need, and they are very easy to use, but a bit lengthy to explain, so I'll cover them in a separate section, partly because they are both really cool, and partly because this post is already pretty long.

If anything is still unclear, or even a little foggy, let me know in the comments and I'll do my best to explain! And I hope to see you next time for integration!

* there are a few significant exceptions to this, which we don't have to be concerned with here. If you are interested in knowing more about these exceptions, brownian motion is a particularly interesting case being continuous everywhere and differentiable nowhere.