Andrew Que Sites list Photos
Projects Contact
Main
Government Trucks

Government Trucks

   Yesterday afternoon I had a phone interview and a few hours latter I was hired.  I will be working for Rockwell-Collins in Ceder Rapids, Iowa starting on the 15th of this month.  This means I have to reallocate to Iowa for the duration of the contract.  Today I started the paper work and calling around for an apartment.  On the plus side, you mention the name Rockwell-Collins and most places are willing to do a short-term lease--so I have that on my side. 
   After doing a bunch of paper work, I did some driving around and found these scary government trucks.  They were all black, had key-code entry doors, lots of lights, a camera on a retractable mast and government plates.  There were a bunch more trucks behind me I didn't see at first.  My guess is that these trucks are Secret Service on their way back from Republican National Convention in Minneapolis.
   The river level has been pretty much the same for the past couple weeks, so I will venture to say that it is now where it normally should be for this time of year: 4.55 feet in height and 1.84 kcfs flow rate.  The river hasn't been this low since early June.  Now for a little statistics.
   I have data from June 5th until now in 15 minute intervals.  However, there are a lot of gaps.  Some are just 15 minutes, others are several hours.  I could have done a straight linear interpolation to fill in the blanks, but I had a polynomial interpolation algorithm that could do better.  On top of the gaps, there is a section where data exists in 2 and 13 minutes intervals.  I made a simple PHP script to do the number crunching.  After importing all the data from a CSV file, the script made even 15-minute intervals, interpolated all the missing data points and dumped out the data.
   From there it was easy to get the stats.  So hear is what was found: from June 5th to August 21st the river was above it's 4.55 foot norm.  During that time, an additional 333.27 billions of gallons of water flowed by--4.8 times the normal flow--1.38 billion additional tons of water.  That's a little bit of water ;)
   November of last year I wrote about calculating linear regression.  If the function d(x) returns some y for a given x, then the function for linear regression finds m,b such that m x + b ≈ d(x).  The linear regression algorithm is a curve fitting algorithm that works well for data sets that center around a straight line.  The function m x + b is a first degree polynomial.  It is possible to extend the polynomial to obtain the second degree polynomial, obtaining a x2 + b x + c.  Those who have taken pre-calculus will know that this produces a U-shaped graph.  If d(x) produces curves slightly, then a second order polynomial is required to reproduce the function.
   There is an algebraic answer to how to obtain a,b,c such that a x2 + b x + c ≈ d(x).  However, this works requires some linear algebra.  It may be best to start with the matrix form of linear regression. 

   Although at this level the pattern isn't too apparent, it becomes so when we add a third term.  For each row and column, the power of x keeps increasing.  This curve fitting function will work for as high an order polynomial as one desires and is the base for polynomial interpolation which I wrote about in January.

   Summations are quite easy to work with, despite looking intimidating in equations.  In software, summations are just for loops where something is accumulated every iteration of the loop.  These particular summations are very simple.  Most are summing the x values raised to some power.  To simplify the equation, a letter will be used to represent each summation.  The matrix thus becomes:
   Turning the matrix form into plain arithmetic so the algorithm can be coded wasn't something I was initially prepared to do.  Thanks to Cortney, I found my way to Wikipedia's article on Cramer's Rule and Determinants, and thus was able to find why the math I had worked. 
   What is needed are the determinamts, which can be multiplied out. 

   The finial step of Cramer's Rule is to divide the determinamts for a,b,c by D. 

   Now that the math is broken down, it is time for a demonstration.  I used my banded nonuniform scatter function on a second order polynomial to simulate imperfect data and plotted it with X/Y Plot.  The red dots represent the input data.  The blue line represents the "best guess" curve fit.  In the margins are the true values used for a,b,c and those calculated by the curve fitting algorithm.

x2 term (a)
x term (b)
Y-intercept (c)
Scatter coefficient (s)
Scatter magnitude (M)

 
    Below is some PHP source code for calculating the quadratic curve fit function.
//---------------------------------------------------------------------------
// Find values for a quadratic curve fit
// Finds a,b,c such that ax^2 + bx + c fits closest to data in $x and $y
// Returns array with a,b,c
//---------------------------------------------------------------------------
function FindQuadraticCurve$x $y )
{
   
// Arrays must be the same size (i.e. each x must have a y and vice versa)
   
assertcount$x ) == count$y ) );

   
// Elements in array
   
$n count$x );

   
// Various summations
   
$p array_sum$x );      // ∑ x
   
$q PowerSum$x );   // ∑ x^2
   
$r PowerSum$x );   // ∑ x^3
   
$s PowerSum$x );   // ∑ x^4
   
$t array_sum$y );      // ∑ y

   // ∑ xy
   
$u 0;
   for ( 
$Index 0$Index $n; ++$Index )
     
$u += $x$Index ] * $y$Index ];

   
// ∑ (x^2 * y)
   
$v 0;
   for ( 
$Index 0$Index $n; ++$Index )
     
$v += pow$x$Index ] , ) * $y$Index ];

   
//
   // The following math comes form the linear algebra:
   //
   //  /       \ /   \   /   \
   //  | n p q | | a |   | t |
   //  |       | |   |   |   |
   //  | p q r | | b | = | u | 
   //  |       | |   |   |   |
   //  | q r s | | c |   | v |
   //  \       / \   /   \   /
   //
   //  We can solve for a,b,c using Cramer's Rule.  First we need 
   //  the determinants for the matrices.

   //       | n p q |                        
   //       |       |                        
   //  D =  | p q r | = nqs + prq + qpr - nrr - pps - qqq
   //       |       |                        
   //       | q r s |                        
   //
   
$d =  $n $q $s
       
$p $q $r
       
$p $q $r
       
$q $q $q
       
$p $p $s
       
$n $r $r;

   
//       | n p t |
   //       |       |
   //  Da = | p q u | = nqv + puq + tpr - nur - ppv - tqq
   //       |       |
   //       | q r v |
   
$da $n $q $v
       
$p $r $t
       
$p $q $u
       
$q $q $t
       
$p $p $v
       
$n $r $u;

   
//       | n t q | 
   //       |       | 
   //  Db = | p u r | = nus + trq + qpv - nrv - tps - quq
   //       |       | 
   //       | q v s | 
   //
   
$db $n $s $u
       
$p $q $v
       
$q $r $t
       
$q $q $u
       
$p $s $t
       
$n $r $v;

   
//       | t p q |
   //       |       |
   //  Dc = | u q r | = tqs + prv + qur - trr - pus - qqv
   //       |       |
   //       | v r s |
   
$dc $q $s $t
       
$q $r $u
       
$p $r $v
       
$q $q $v
       
$p $s $u
       
$r $r $t;

   
// The result is the varable determinants divided by the determinant
   
$a $da $d;
   
$b $db $d;
   
$c $dc $d;

   return array( 
$a $b $c );
}
And lastly a shout out to Erica--keep with the math!

3 comments have been made.

From Wendy

August 26, 2008 at 10:46 PM

Just wow!

From Noah

Here

August 30, 2008 at 4:51 PM

...I think you forgot to carry the '2' in that first set there... Haha that's evil. Really tight PHP code, as always!

From ERica

January 02, 2009 at 4:02 PM

NOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO!

August 31, 2008

Renaissance Faire

Kelly

Kelly

   Took a trip to the Bristol Renaissance Faire today.  It was suppose to be a group thing, but I was not involved in the organization of said trip.  When the day came around, I found most parties had backed out.  Really wanting to go, I grabbed who was around and we set off.
    We spent about 6 hours at the faire.  I took a fair number of pictures, but it was hard for me to remain focused on photography.  Perhaps I need to try going twice a year--spending one day looking around and an other shooting pictures.  Maybe it's the engineering side of me, but I find myself facinated by the buildings at the faire, admiring style and implementation.
   Pictured is Kelly at the start of our day.  She had never been to Ren. Faire but had a dress.  I felt bad for her because she selected shoes to go with the outfit--heals--which are not really the kind of shoes one wants for walking all day.  By the end of the day she was a little sore.

August 30, 2008

Domain name squatter

   An other domain name squatter has tried to sell me "DrQue.com"  This one, called "i-Time Marketing, Inc" claims to be based out of Falcon, Colorado.  The phone number given is from east Iowa.  The domain information of the sender's e-mail is all private, but a little searching on the web shows this company owns over 230,000 domains and is based in Davenport Iowa.  I tried searching the Iowa court records for "Kenneth Palm"--the name given in the e-mail for contract.  I didn't find anything recent for anyone by that name and my guess is that it's an alias. 
   Naturally, these squatters are almost 100% automated.  There's no point in trying to remind them the name of the site is "DrQue.net" and a .com version of the domain name is rather silly--this isn't a commercial site.  I changed my e-mail address (again) and we'll see for how many months the new one lasts.
   I bought the domain DrQue.net in July of 2002 through Network Solutions and I've never been happy with that company.  I don't consider not displaying one's e-mail address a "service" and it's defiantly not worth $9/month.  Now when I log in, I'm bombarded with advertisements for serves I don't care about and it's hard to find the management serves for the things I need.  Perhaps this is the new way of the web, but I think it sucks.  If I'm paying you for a service, give me what I want and leave me alone.  It's because of miserable companies like Network Solutions I have to deal with things like domain name squatters.
   For the last couple days, Noah had been working on this project.  The purpose was to mount his monitor above his head in the storage space above the closet in the bedroom.  Here he is enjoying the results.  I personally don't know if I could use my computer this way, but Noah does get a punch in his Garage Engineering card for this one.