Archive for the ‘Math’ category

Math: The Rabbit Hole – Sin, Cos and Derivatives

November 30th, 2009

Something I do recall from high school calculus class is that the derivative of sin x is cos x. This is one of those little nuggets of information that really helps you through bigger, tougher equations. But why is this so? Down the rabbit whole we go.

First, we need to define what a derivative is (again). Its just the slope of a line at a given point. Slope is just rise over run, or the change in y or the change in x: \dfrac{dy}{dx} or \dfrac{\bigtriangleup y}{\bigtriangleup x}. In simple geometric terms this is pretty easy. Let’s go back to our simple y = x line:

dydx1

Using just a paper and pencil we can figure out the slope of this line at any given point. We can probably come up with the slope of any line at any other given point, too. In this example finding the first derivative, and its meaning, are very easy. But how do we do it with tougher examples? Well, lets look at the idea of finding the rate of chang of x at a given point. This is tough to do. We really need two points to find the slope. How do we pick another point? On a tight curve, using our point at x and another point will probably give us a false (but perhaps close) slope. What we need is another point that is infinitely close to x. Let’s say we have x and another value, x + h. Our equation to figure out the slope based on these two values would look like:

\dfrac{f(x+h) - f(x)}{h}

This is pretty straight forward so far. Our value h needs to be very, very small to give us an accurate slope. In fact, to give us a precise slope it has to be approaching zero. So what if we create a limit where the difference in our points is disappearing?

\lim_{h \to 0}  \dfrac{f(x+h) - f(x)}{h}

This is pretty and all, but it doesn’t really get us anywhere. Remember, we are trying to find some general rules to find derivatives. Here we need to take another “guess” at trying to find an equation we can simplify. Our guess is going to be to use f(x) = x^2 as a starting point. We do this because we want do be able create multiple terms and hopefully find a way to get rid as much junk as possible.

#1 – Starting equation: f(x) = x^2

#2 – Plug into our slope formula: \dfrac{(x + h)^2 - x^2}{h}

#3 – Expand: \dfrac{(x + h)(x + h) - x^2}{h}

#4 – Multiply: \dfrac{x^2 + h^2 + 2hx - x^2}{h}

#5 – Add (or subtract):\dfrac{ h^2 + 2hx}{h}

#6 Divide by h: 2x + h

So we have a general formula that if f(x) = x^n the f'(x) = nx^{n - 1}. For our dead-simple line f(x) = x, the derivative is f'(x) = x^0 or 1.

If you recall, we started with the derivative of sin x being cos x. So let’s plug and chug. It’s calculus, but it looks like algebra!

#1 – Starting equation: f(x) = sin x

#2 – Slope equation with sin plugged in: \dfrac{sin(x + h) - sin(x)}{h}

#3 – Trig: sin a - sin a = 2 sin 1/2 (a - b) cos 1/2 (a + b), which simplifies to \dfrac{2 cos (x + h/2) sin (h/2)}{h}. I had to look all of this up, which is why I titled this post the rabbit hole.

#4 – Pull h/2 over to sin: 2 cos (x + h/2) \dfrac{sin (h/2)}{h}

#5 – Take the limit as h approaches 0. The limit of a product is the product of the limits. All of the h/2 elements go to 0, basically leaving cos(x).

To figure this out I had to relearn some trigonometry, the basic theorem of derivatives, and the limit product rule. Math is hard; let’s go shopping!

Math: The Taylor Series

November 30th, 2009

In yesterday’s post Not-so Easy e, I briefly covered The Taylor Series and how it is applied to solving for the value of e^x, or for specifically finding the value of e. I didn’t spend a lot of time covering The Taylor Series, and skipped some steps on my path to deriving the value of e. I figured I should take some time to go back over Taylor, show why it was chosen, and how it fits in with e.

The Taylor Series has a rich history in mathematics, and it is used to solve a number of classic problems. The Taylor Series is defined in Taylor’s Theorem. If a function (we used f(x) = e^x yesterday) is differentiable n times on a closed interval [a,x] and n + 1 times over the open interval (a,x), and n \ge 0, the function can be precisely approximated by The Taylor Series.

f(a) + \dfrac{f'(a)}{1!}(x-a) + \dfrac{f''(a)}{2!}(x-a)^2 \cdot\cdot\cdot \dfrac{f^{(n)}(a)}{n!}(x-a)^n

Math note: The open interval (a,x) includes all values between a and x exclusively, and the closed interval [a,x] includes all values between a and x inclusively.

I am not going to go through the whole theorem here, but I will show in more detail how it is applied to e^x. Lets go through step by step.

#01 – Original equation: f(x) = e^x

#02 – First Derivative: f(x)' = e^x

#03 – Taylor: f(a) + \dfrac{f'(a)}{1!}(x-a) + \dfrac{f''(a)}{2!}(x-a)^2 \cdot\cdot\cdot \dfrac{f^{(n)}(a)}{n!}(x-a)^n

#04 – What value a should we use that is near x? We will use 0, which will produce a value of 1 when the function f(a) = e^a.

#05 – Substitute in e^x derivatives: 1 + \dfrac{1}{1!}(x-0) + \dfrac{1}{2!}(x-0)^2 \cdot\cdot\cdot \dfrac{1}{n!}(x-0)^n

#06 – Obvious: e^x = 1 + x + \dfrac{1}{2}x^2 \cdot\cdot\cdot \dfrac{1}{n!}x^n

#07 – Finished: e^x = \sum_{n=0}^{\infty}\dfrac{x^n}{n!}

I have stumbled over uses for The Taylor Series from time to time working as a software engineer. Its pretty easy to compute a value to an arbitrary precision using a loop. In the practical world an approximation is good enough, and even a loop that is run 100 times with most math should return almost immediately on modern hardware. Apparently this is how scientific calculators do a number of computations. Very cool.

Math: Not-so Easy e

November 29th, 2009

In mathematics, something of interest is the slope of a graphed equation at a give point on the line. The slope is defined as rise over run. For straight lines the slope is easy:

x = y

f(x) = x

The line is defined as f(n) = x, which just means if we set x to 0 then the result is 0, x to 1 then the result is 1. This straight line has a slope of 1/1, or 1. If it rises one unit, it runs one unit. This is pretty straight forward, but how do we determine the slope for a curved line like the one below?

exp

f(x) = a^x

The equation f(x) = a^x is generating the line where a is a constant raised by variable x. The important thing to take away is that we have a curve (in blue), and on a specific point we want to know the slope (in red). There are various ways to determine the slope. The simplest way in a simple case like the one illustrated is to just draw the curve on some graph paper, then guess the slope by drawing it like we see. This isn’t very fancy, and isn’t necessarily very accurate, but it does work well for simple situations. Luckily math comes to the rescue to give us a more accurate answer, and provides a method that works in more complex situations. Modern Calculus (invented independently by some guy named Issac Newton and another guy named Gottfried Wilhelm Leibniz) can find the slope using something called a derivative. I am not going to dig into derivatives here; I am going to cheat a little. I learned derivatives in high school calculus and used them in both high school and college math and science. I know I am blogging about a calculus class I am taking so that isn’t fair. For our discussion we only need to know that there is a transformation that will take an equation and (transformer sounds here) turn it into an equation for the slope at a given point. I will be providing that transformation shortly.

The point of this blog post really isn’t just about slope, its about a special constant known as e. This constant is one of the most important constants in math for a variety of reasons, almost as important as \pi. The constant e has two very unique qualities. First, the derivative of e^x is e^x! What we reallycare about here is that for the general function f(x) = a^x, the only value for a that produces the slope of 1 where x is 0 is e. That figure above is actually the graph of f(x) = e^x. So, what the hell is e? Its a constant value that starts 2.71828182845904523536*. The next question we should ask is, how the hell do we get this number?

An option that is provided by the online textbook of my class is to try to create an infinite series to estimate this value. This didn’t jump out at me as the obvious way to discover the value of e. I thought, “Why the heck is the prof pointing towards this crazy solution?” There was no explanation, so I went searching for why one would use an infinite series to solve for anything, let alone this. I found this interesting web page explaining that infinite series expansions are a rather useful tool in math. What I discovered is that the prof was suggesting the use of something called a Maclaurin Series to find the value of e.

We start with x^n, which we will use to generate our series. Using Maclaurin, the series is:

e^x = a_0 + a_1x + a_2x^2 + (etc)

We know that in the original formula f(x) = e^x that that value will be 1 when x is 0. When you put this in context of the series, a_0 = 1 if we start with 1 as x value.

When we differentiate the series, we get:

\dfrac{d e^x}{dx} = a_1 + 2a_2x + 3a_3x^2 + (etc)

This sets up an interesting equality. The derivative of e^x can be proven to equal e^x as stated above. So we can match up these two equations and see that a_0 = a_1, and 2a_2 = a_1, 3a_3 = a_2, a_1 = 1/2, etc. In general this boils down to each position being:

\dfrac{x^i}{i!}

So to sum the whole series we get:

\sum_{i=0}^{\infty}\dfrac{x^i}{i!}

Plugging 1 into x yields the sum to find e. You can see that is one of the common equations for e here.

Again, understanding a fundamental value of math requires some work. There are others ways to solver for e, but this is the one that seemed to make the most sense for me. I thought of going through the proof here for why \dfrac{d e^x}{dx} =  e^x, but it involved even more math external to the problem at hand and probably would have doubled the length of the post.

Math: The Golden Ratio

November 27th, 2009

The Golden Ratio is an interesting concept in mathematics. The ratio is found in a number of places throughout nature. For example, the ratio has been found in see shells and pineapples. It is common in architecture. But the Golden Ratio is rooted in mathematics, where it can be derived a number of ways including from a Golden Triangle. Someplace I had forgotten that it occurs is in the Fibonacci Sequence, which actually appears to be one of the most fundamental sources of the ratio. In case you had forgotten about the Fibonacci Sequence or Numbers, they start like this:

1, 1, 2, 3, 5, 8, 13, 21, 34, etc.

The pattern works like this: start at 1, and then for each number take the current number + the number before it to create a new number. So in the Fibonacci Sequence, every number is the sum of the two previous brother numbers. Pretty straight forward, huh?

Where it gets interesting is when you divide each number by its previous number. The results look like this for the first few numbers:

1 : 1/1 = 1
2 : 2/1 = 2
3 : 3/2 = 1.5
5 : 5/3 = 1.6*
8 : 8/5 = 1.6
13 : 13/8 = 1.625
21 : 21/13 = 1.61538461538462
34 : 34/ 21 = 1.61904761904762

You can view a longer version of this at a Google Doc Spreadsheet I created. You will need a Google account to view it.

See that number starting 1.618? That is the golden ratio (or an approximation). The Fibonacci Sequence division scheme I have presented here converges on the ratio. So how do we ever discover the “real value”? Well, there are several ways. One way is to use a limit. But I found that the lesson plan on this showed a very interesting, purely algebraic way of doing it.

The Golden Ratio value for each number, lets call it r for “ratio”, is based on the division of any number via its previous number. If we write this formula out it is r = f(n) / f(n -1), if n is the number and f is the function that creates a Fibonacci number. Another way of writing this is f(n) = r f(n-1). We can take any given n-1, put it into the function, then multiple it by r, and we will get the result of f(n). This part was pretty easy for me, too. The Fibonacci Sequence tells us that every number is the sum of its two previous brothers, so we can also state f(n) = f(n-2) + f(n-1). So far we have two identities:

#1: f(n) = r f(n-1)
#2: f(n) = f(n-2) + f(n-1)

The goal here is to solve for r. This is the tough part. This stumped me, but I got some help from Reddit Math. The key here is to make an educated guess that we can do some substitution here that will get us the quadratic equation (which we can easily solve). Looking at the equation, we can see that there might be a path to this type of equation, and if we have a quadratic equation then we can solve for r. So how do we get here from there?

The first thing to note is that r f(n-1) is the same value as it’s previous brother times r. In other words, r f(n-1) is the same as r ( r f(n - 1 -1)) or r^2 f(n-2). OK, now we are closer to a quadratic equation, since we have a power of two. The first equation can now be written as f(n) = r^2 f(n-1). Now we are rocking! We can now see in our soup of equations that we have all the parts of a quadratic equation, except one part. We still have an “n-1″ floating around and everything else is an “n-2″, and we need the same variable across everything to do a quadratic equation. But we already know f(n-1) is the same as r f(n-2)! Here are those two identities again, with both transformed:

#1: f(n) = r f(n-1)
#1a: f(n) = r^2 f(n-2)
#2: f(n) = f(n-2) + f(n-1)
#2a: f(n) = f(n-2) + r f(n-2)

We can now set 1a and 2a as equal, since they both equal f(n):

r^2 f(n-2) = r f(n-2) + f(n-2) or r^2 f(n-2) - r f(n-2) - f(n-2) = 0 or r^2 - r - 1 = 0

And that is a quadratic equation. Given a quadratic equation ax^2 + bx + c = 0, then one may solve it with:

x = \dfrac{-b \pm \sqrt{b^2 - 4ac}}{2a}

When we plug that in it looks like:

r = \dfrac{-1 \pm \sqrt{5}}{2}

Which equals 1.6180339887498948482045868343656 (approx).

Very cool.

Math: Relearning It

November 27th, 2009

In the following days and hopefully weeks or months I am going to do a series of posts on Math.  I am taking a course, Calculus with Applications, through MIT’s OpenCourseWare, and will be doing a number of exercises from that course and posting them here.

This course’s “Philosophy of Learning” is rather interesting.  Here is what the course textbook has to say:

Philosophy of Learning

  1. Amount learned is proportional to time put in.
  2. Best way to learn is to figure out ideas yourself or teach them to someone else.
  3. Second best is to do so with hints from others like your friends or us.
  4. Third best is to get the ideas from reading; but pause in your reading to think about them.
  5. Fourth best: unacceptable: don’t get them at all.
  6. The object of a lecture is not so much to inform you of important facts, but rather to stimulate you to try to learn about some concept.
  7. The object of the course is to empower you to use the concepts of calculus in any context.

Point #2 seemed to ring true for me.  When I have had to learn a particular subject deep enough so that I could teach others, I usually learned that subject well.  I don’t kid myself into thing that many, of any, people actually read this blog.  However, posting some of my lessons here will still fill that same roll.  I will still go through the motions of having to learn something enough to teach it.

Its going to be slow going.  Its been a while since I was in a math class, but I hope that as I get going the cobwebs and dust will be shaken from my brain and some of the old math I learned will come back.  And even if it doesn’t, I can still learn new things!