Showing posts with label Derivations. Show all posts
Showing posts with label Derivations. Show all posts

Saturday, March 15, 2014

JFLAP and the Sierpinski Gasket (aka Triangle)

      One of the coolest things that we get to work on in MATH201: Discrete Mathematics is recursive functions and fractals. From pine cones to coastlines to the tree in your backyard, fractals are found everywhere in nature. I'm not going to get into specifics on what a fractal is at this moment (there are tons of resources out there that can explain them better than I can), but it's basically this:

  1. Make a basic shape
  2. Use that shape to make the same shape on a larger or smaller scale
  3. Repeat step 2 ... 
      The results that a simple recursive algorithm produces can be amazing. You can generate fractals with a program called JFLAP. On a recent quiz in class, one question asked students to create Wacław Sierpiński's famous gasket known as the Sierpinski Triangle. There are many ways to construct this triangle. One method involves starting with a large filled-in triangle and cutting out smaller triangles inside the existing triangles. The Wikipedia page has a good illustration of this:

Courtesy of Wikimedia Commons
      Another way of doing this is to use a recursive function to draw the outline of the triangle. In JFlap this can be accomplished by using something called an L-System or Lindenmayer System. An L-System uses an axiom which tells the system where to start and calls other defined functions.

      To make a Sierpinski Triangle in JFLAP, two functions are required in addition to the axiom. We'll label these functions A and B, while g tells the program to draw a line forward, + and - tell it to turn right or left.

Axiom: A
A -> B g - g A g - g B
B -> A g + g B g + g A
angle = 60

      On the second iteration of this system, a shape is drawn:
n = 2

      We use this shape again in the next iteration and the general pattern shows up for the first time:
n = 3

      You may be able to see a triangle emerging in the middle:
n = 4
      
n = 5

n = 6

n = 7

n = 8

n = 9

n = 10
      That's pretty cool, right? Well prepare to have your mind blown in the next minute. You can see that as the number of iterations increases, the finer the structure of the triangles become. Look back at the early iterations and find that no two lines ever actually touch each other. So, it can be shown that as the number of iterations goes to infinity, the perimeter of this shape tends to infinity while the area enclosed is precisely zero. Wait, what?!? That's crazy. How can something have infinite perimeter and no area?

      This is the beauty of fractals. Veritasium has a great video about the fractals and the coastline paradox:






      

Wednesday, July 3, 2013

The Quadratic Formula : Derivations

The quadratic formula $x = \frac{-b \pm \sqrt{b^2 -4ac}}{2a}$ is a thing of beauty, but how is it derived? Well, it requires quite a few steps and some understanding of a squared binomial which I hope I can explain.  The first thing to note is the expansion of a squared binomial using alpha and beta as our terms: $$(\alpha + \beta)^2 = (\alpha +\beta)(\alpha +\beta) = \alpha ^2 +2\alpha \beta + \beta ^2 $$

Next, let's look at a quadratic equation:
$$ax^2 + bx + c = 0$$
How do we solve for $x$ from that? We can't use our basic algebra toolkit of using arithmetical operations alone. We have to think a bit more outside the box...

Start by subtracting $c$ from both sides and factoring out an $a$ from the left side:
$$a(x^2+ \frac{b}{a}x) = -c$$

Dividing both sides by $a$:
$$x^2 + \frac{b}{a}x = \frac{-c}{a}$$

Now this is where the box starts to look a bit fuzzy (as dirty minds chuckle). Fortunately we remembered that we can do something called completing the square. To do this we must think about how we can take what we've worked out so far and get it into the expanded version of the squared binomial form that I introduced earlier. So let's make an initial substitution:
$$\alpha^2 = x^2  \Longrightarrow \alpha = x $$

The next substitution we'll make needs a bit of prep work. Let's focus on the left side of the equation and multiply our $\frac{b}{a}x$ term by $\frac{2}{2}$ and see what we get:
$$\alpha^2 + \frac{2}{2} \cdot \frac{b}{a} \alpha \Longrightarrow \alpha^2 + 2 \left(\frac{b}{2a}\alpha \right)   \Longrightarrow \alpha^2 + 2 \alpha \left(\frac{b}{2a}\right) $$

Wait a minute! This $2 \alpha \left(\frac{b}{2a}\right)$ term looks awfully similar to that aforementioned 2nd term of the expanded squared binomial, $2\alpha \beta$. In fact, our next substitution can define the value of $\beta$:
$\beta = \frac{b}{2a}$  so that must mean that $\beta^2 = \left(\frac{b}{2a}\right)^2 = \frac{b^2}{4a^2}$

Now we can add $\beta^2$ to both sides of our equation and complete the square:
$$\alpha^2 + 2\alpha \beta + \beta^2 = \frac{-c}{a}+\beta^2$$
We can "unexpand" the left side now to get:
$$(\alpha + \beta)^2 =\frac{-c}{a}+\beta^2$$
Taking the square root of both sides, being careful to note that there is a negative result and a positive one (hence the $\pm$):
$$\alpha + \beta = \pm \sqrt{\frac{-c}{a}+\beta^2}$$

This might be looking a bit confusing now so let's substitute back in our original terms now that we should have a clear idea of what we did with completing the square:
$$x+\frac{b}{2a} = \pm \sqrt{\frac{-c}{a}+ \frac{b^2}{4a^2}} \Longrightarrow x = -\frac{b}{2a} \pm \sqrt{\frac{-c}{a}+ \frac{b^2}{4a^2}}$$

Well that kind of looks like the quadratic formula but not quite...
Let's try simplifying that radical and see where that gets us. Creating a common denominator by multiplying $\frac{-c}{a}$ by $\frac{4a}{4a}$ and rearranging terms:
$$x = -\frac{b}{2a} \pm \sqrt{ \frac{4a}{4a} \cdot \frac{-c}{a}+ \frac{b^2}{4a^2}} \Longrightarrow  x = -\frac{b}{2a} \pm \sqrt{ \frac{b^2}{4a^2} - \frac{4ac}{4a^2} }$$
$$x = -\frac{b}{2a} \pm \sqrt{\frac{b^2-4ac}{4a^2}}$$

The next few steps may be popping out at you. Take the $\frac{1}{4a^2}$ out of the radical and we have a common denominator which yields:
$$x = -\frac{b}{2a} \pm \frac{\sqrt{b^2-4ac}}{2a} \Longrightarrow$$
$$x = \frac{-b \pm \sqrt{b^2-4ac}}{2a}$$
We did it!  We have derived the quadratic formula $x = \frac{-b \pm \sqrt{b^2 -4ac}}{2a}$ from our quadratic equation $ax^2 + bx + c = 0$

And now it might be obvious why the quadratic formula only works when $a \ne 0$ since $\frac{something}{0}$  is undefined. Well that was fun practice for my $\LaTeX$ coding skills, thanks for following!