Andrew Que Sites list Photos
Projects Contact
Main
 _fcksavedurl=
 
   Today's demo is again about curvature.  This time I've added normal vector (in blue) next to the tangent line (in green), and the circle (in purple) representing curvature at the tangent location.  The curvature on any circle is the same at every point.  What this circle then shows is an equivalent circle with the same curvature as the point on the function.  With the driving example, the side-to-side G-force experience driving at that point on the curve would be the same as if you were on a circle pictured.
   Part of this calculation involved making a line segment for the tangent and normal lines.  I wanted the segment for these lines to be a constant length.  When I looked at the problem, I saw a use for polar coordinates.  This is because I had a center point, and I wanted to draw a line out some constant distance outward from that point.  In polar coordinates a vector is expressed as a radius from the origin, and an angle.  I had the radius, I just needed direction.
   The direction of this line has to come from my line equation.  That equation is m x + b, where m is the slope and b is the y-intercept.  The slope is expressed as rise over run, or y / x.  When looking at the triangle formed from this, it was clear the angle formed were the sides opposite (rise) and adjacent (run).   Opposite over adjacent is the tangent of the angle.  Thus tan( θ ) = m. which means θ  = tan-1( m ). 
   To convert back from polar coordinates we use the point ( r cos( θ ), r sin( θ ) ) where r is the radius.  Plugging in the calculation for the angle θ results in ( r cos( tan-1( m ) ), r sin( tan-1( m ) ) ).  With some trigonometric identities, this becomes ( r / 1+m2 , m r / 1+m2 ).  I could likely have figured this out using Pythagorean theorem but my method still worked. 
   To get the normal vector, one just has to rotates the tangent line 90 degrees.  For this, some matrix math can be used, but I cheated and looked it up.  Turns out to rotate a line function in the form m x + b, you just modify m such that m = -1 /  m.  So enjoy the demo!
 _fcksavedurl=  
    Today's demo is much the same as yesterday's, with one change.  Rather than getting curvature for a single point, the curvature is now displayed as a color gradient behind the graph.  This gives a better real-time indication of how curvature changes with the shape of the function.  In the graph, the darker blue means higher curvature.   Notice how curvature always increases around a local minimum or maximum.  A graph that has higher peaks and valleys also has much faster transitions in curvature.  That is, the curvature is relatively low between local min/max, but close to the min and max values for curvature quickly increase.
   This is really the first time I've used anything I've learned from calculus III, although I technically touched on curvature in calculus II.  I have yet an other demo planned about curvature, but we'll see if I have enough knowledge and time to complete it.  So stayed turned for more math...
 _fcksavedurl=  

An other demo similar to yesterday, but with one addition: the calculation of a value called curvature. In effect, the larger this value, the sharper the curve. Think about the function graph as a road. If you are driving down the road quickly and had to make the turns required to stay on the road, curvature would be related to how much sideways G-force you would feel through these turns. You can move the points around to make functions with varying degrees of curvature, then move the red line over the point in the function you would like to measure curvature. Notice the green tangent line. In locations with small curvature values, the tangent line runs closer to the function for a longer span than for locations with high curvature.

Calculating curvature required adding some calculus functions to my curve fitting script. First, let's examine the function for curvature.

We need the first and second derivative of the function (f) for this computation. Since the curve is always a polynomial, the derivative function isn't too difficult. The function always has this form:

Where n is the number of terms in the polynomial, and c is an array of coefficients. The first derivative of the function:

And the second derivative:

A pattern emerges, and the mth derivative of the function f is:

In software, this is quite easy to compute and didn't require a lot of changes to the loop for calculating the function at a point.

And by the way, Happy December!

 _fcksavedurl=
 

The above demonstration is on tangent lines. This is a concept learned early in calculus. A tangent line is a linear representation of an equation at some point. The closer to the point of origin, the closer (i.e. the less error) the function is approximated.

In this demo, the red bar can be moved to select the location at which the tangent line will be calculated. The resulting graph will show the calculated tangent line in green. As with previous math demos, the black dots may be moved around to modify the function, and more or less points can be used.

The equation for the tangent line at some point a is g( x ) = m ( x a ) + b, where m = f '( a ), b = f( a ), and f is the function. This demo creates a polynomial function for f based on the points the function needs to intercept. The resulting polynomial function can be expressed:

f( x ) = c0 + c1 x + c2 x2 + c3 x3 + … + cn xn

The derivative is then:

f '( x ) = c1 + 2 c2 x + 3 c3 x2 + … + n cn xn-1

This is quite easy to compute. So the slope (m) of the line is based on the derivative, and the intercept (b) is based on the root function.

The demonstration is (I hope) the first part of a more complected demonstration I plan on doing latter on.

   I've been playing with VirtualBox for sometime, and I learned a new fetcher I like. DrQue.net runs on a Ubuntu-based web server. When developing the PHP code for demos I've made in the past, I've always had the server next to me. However, without instant access to the server, I needed a way to have a LAMP setup running. I decided VirtualBox was the answer. Using “Host-only networking” I was able to use a Ubuntu virtual machine, and setup a LAMP server visible to the local host. I was able to use my local web browsers to develop the PHP and Javascript just as if I had DrQue.net sitting next to me.
   The picture is one in a series of shots taken at Disaster House.
Chelsea

Chelsea

   Back in March I had a class in linear algebra which unfortunately I didn't feel was taught all that well.  Since I felt the homework wasn't doing a good job of getting me to learn the techniques we were being taught, I decided to write a C++ library that implemented several of the methods this class covered. 
   For my linear algebra class, I used OpenOffice Calc to do my matrix calculations.  This made it easy to check my steps and eliminate arithmetic mistakes (which I seem to make a lot).  One thing I noticed was that OpenOffice often ended up with tinny rounding errors.  I would get results like 1E-15 (1-15) that I had to manually replace with 0.  The reality was, all the matrix math I was doing used integer numbers.  Since all the matrix operations I did were just addition, subtraction, multiplication, and division, everything could be done using rational numbers.  So my first task was to write a rational number template class.
   A rational number is a number that can be expressed as a quotient, so in the form a/b or "a over b".  Rational numbers (set Q) are made of two integer number (set Z), a and b.  In C/C++, there are several integer types, so I decided a template class would work the best so the programmer could select the integer type they needed.  In addition, as long as the type supported basic arithmetic (subtraction, multiplication, and division), any class that overloaded these operators could be used.  This allows the use of arbitrary precision libraries such as the GNU Multiple Precision Arithmetic Library
   The matrix class is also a template.  The elements of the matrix can be of any type (integer, floating-point, rational, ext.)  I implemented the following functions: addition/subtraction, transpose, row echelon reduction, determinants, dot product, matrix product, inversion, and LU decomposition.
   The libraries are available here, and linked on the projects page.

1 comment has been made.

From LJBarre

South Carolina

November 26, 2011 at 5:53 PM

Aha, very good information with template function. This should help the phobic matrix deviants who are trying a to teach a subject that they understand but are unable to teach.

November 01, 2011

Adult Math

So in my calculus III class, we're learning how to solve multiple integrals. I like to write about what I'm learning in my math classes, but I don't really have a lot of application for this. So, I decided to expand on my favorite integral. Here is my result:

For those of you who can solve this, go ahead—it's fun. But for those of you who can't, let me walk you through it. We first solve the inside most integral.

Substitute this back...

Now solve the inside integral again...

Substitute this back... (math is sometimes a lot of 'rinse and repeat')

Now, solve the finial integral...

There you have it. Mathematically I've shown that if you use the correct limits of integration, and do so three times (i.e. if you do it right) then can end up being 69. Don't get it? Then try and read the letters of the previous equation. Yep, I've learned so much now that I am attending a university raked in the top 20 in the country, I'm making licentious innuendos using math for lack of anything else to demonstrate.

1 comment has been made.

From Ericaceous :)

December 05, 2011 at 8:40 AM

I would like to take this moment to thank my awesome high school calculus teacher for making all of this simple and undaunting . . . Thank God. Everyone is capable of 'higher' maths, it's just bad teachers who don't know what they're doing and make it seem impossible for most people.