Thursday, February 5, 2009

Fear Mongering and Liberal Math

Take a look at this video clip of Nancy Pelosi fear-mongering. I don't want to make this a political blog site, but this is just the kind of idiotic fear-mongering that causes dangerous and expensive rushed decisions. If you want to give the Madame Speaker the benefit of the doubt, she made the same statement in a Chris Wallace interview on January 18th. Scare me once, shame on you, fool me twice shame on me...



"Every month that we do no have an economic recovery package, 500 million Americans lose their jobs" - Speaker of the House, Nancy Pelosi

I always thought there were only somewhere on the order of 300-305M Americans at the present time (at least according to the CIA and Census Bureau). So for her statement to be true, if we delay just one month, we would have to have 100% employment rate (that is, everyone has at least one job), and 83% of those people would have to have two jobs (again, I don't think this is true). Finally, in that first month, we would all have to lose our 1 or 2 jobs, that is 5/6ths of the jobs would have to be lost (I guess that includes her too, hopefully). Actually strictly speaking even that wouldn't work since she said 500M Americans would lose their jobs, not 500M American jobs would be lost. Semantics aside, so what would happen the next month? There would be no more American jobs to lose.... or is she assuming that we all have 4, or 6, or 8 jobs so we can stretch this out to 2, or 3 or 4 months?!?

Liberal math does not compute! Maybe that's why so many of the democrats in power have had recently-surfaced serious tax evasion problems. These are not little errors here and there, but often multi-year spanning, tens to hundreds of thousands of dollar "accidents" or "mistakes" made by the likes of Daschle, Geithner, Murphy, and Rangle. Tax evasion is another topic for another time though. I want to discuss something else while we are still on the sub-topic of unemployment.

Unemployment Timeline

Check out this unemployment timeline. Here are some interesting observations:

  • The timeline does not have unemployment data points for the Great Depression years, but estimates were 23-25% for several years. So everyone comparing this, finally official, recession to the Great Depression is slapping the face those who survived through the 1930s. In fact in the '80s recession and many years before it had unemployment in excess of 10.0% (we are estimating that the current 2009 rate is ~7.5%), so what we are in is not even as bad as the '80s and other year s with regard to employment.
  • For a lot of the 1990s and 2000s the unemployment rate was below 6.00. These years included three Bush terms (G.H.W. and G.W.) and two Clinton administrations, but I will let you decide who should get more acclaim for this.
  • After the 2nd Gulf War began, you can see a prolonged decline in unemployment down to pre 9/11 rates. I am not promoting nor am I discounting the war, I am just saying that the statistics coincide and are probably correlated.
  • It's interesting to see that the recent congress, the 110th Congress, had the Democrats as the majority party. It's since 100th's meeting in 2007 that there was a gradual rise in unemployment leading up to the current events. The majority lead has even increased in the succeeding congress, the 111th Congress.
  • Just following a minimum wage increase, you can usually see an increase in unemployment, sometimes prolonged. Not being an economist, I can only speculate that if the two are correlated, then it is due to the sudden increase in operating costs that require spending cuts (in the form of decreased labor quantity).

Sunday, February 1, 2009

Numerical Methods for Solving Initial Value Problems

Overview

I warned you that this blog would be random, and now we will discuss an undergraduate math topic. Recently, I was cataloging some of my old text books and I came across one on differential equations. The title is Differential Equations Computing and Modeling, by C. Henry Edwards and David E. Penney. It occurred to me that while I had done some small computation projects in this class using formulas in Excel and some MATLAB programs, most people do not have access to MATLAB (at least legally), though they should have access to a C or C++ compiler. So, without further ado, here is a small project (single source file) with multiple numerical methods for differential equation solution.

Introduction

First we need to define some terminology.
  • ODE - Ordinary differential equation. This is an equation which contains functions of only one independent variable, and derivatives with respect to that variable.
  • IVP - Initial value problem. This is an ODE, together with an initial condition. For example, dy/dx = y, y(0) = 1 is an IVP. (Coincidentally, if you solve this for y(1), you will determine Euler's costant e).
  • Derivative - What is wrong with you? Go back to Calculus 1. Sorry, that was an inside joke.
Next, in order to solve your problem using these numeric methods (as implemented), you need to express your differential equation such that y'=dy/dx is on one side. For example:

y' - y = x

should be expressed as

dy/dx = y + x

Once this is done, you will be implementing dy/dx as a function ( that's a c++ function here) which takes two doubles and returns a double. Specifically, the signature is as below:

// This is your differential equation y'(x,y)... that is
// formulate the function dy/dx as a function of x,y
typedef double (*Y_primed)(double x, double y);

So, to implement the example function that was given, you could do something like the following

// This is the example y', following the signature above
double sample_y_primed(double x, double y) {
return x + y;
}

The Numerical Methods

Numerical methods are used for solving differential equations in an approximate way. There are three numerical methods used in this source. Space will not allow me to cover them thoroughly here, but here are some Wikipedia resources. You can find the algorithms there as well.

  • Euler's Method - created by Leonhard Euler, mathematical genius. http://en.wikipedia.org/wiki/Euler_method
  • Improved Euler's Method - also called Heun's Method, after Karl M. W. L. Heund. This method is an extension of the Euler Method. http://en.wikipedia.org/wiki/Heun%27s_method
  • Runge-Kutta Method - A numerical method created by C. Runge and M.W. Kutta which has much lower error for a given number of steps, and thus has better accuracy for the same number of iterations as Euler's Method. Alternatively, a lot of computational efficiency can be gained at the expense of a little bit of accuracy when compared to Euler's Method. http://en.wikipedia.org/wiki/Runge-Kutta_methods

The implemented numerical methods all follow this prototype
double SomeNumericalMethod(Y_primed f, double initial_x, double initial_y, double final_x, unsigned int steps)

... where f, is the y' function covered earlier, initial_x is the x-value at which the initial condition is true, initial_y is the y value at the initial condition, final_x is the x-value at which to calculate the new y value, and steps is the number of iterations. The approximate new y-value, that is the approximate y(final_x), is returned.

Here is a small example:

dy/dx = x + y, y(0) = 1

We shall call ImprovedEulersMethod() function

double y_of_1 = ImprovedEulersMethod(sample_y_primed, 0, 1, 1, 10);

You should find that y_of_1 is near 3.4282, which is approximately equal to the real y-value y(1) = 3.4366. Increase the number of steps (20, 40, 80, ...) to see how the accuracy increases.

Downloading

Here's a link to the C++ source code.

Unexplored Ideas
  1. What is the error of each method as a function of the number of iterations used?
  2. How many iterations does it take to have n-decimal places accurate?
  3. Derive and prove why the special IVPs and final x-values for e, ln(2), and pi arrive at those values.

Friday, September 19, 2008

Cheap Horsepower, or Blowing Hot Air?

Okay, so it's been a while since my last post, and I'll try to keep up more regularly. I have been thinking

Overview

Note: This part is a very basic overview of engines, and some tuners will find it boring. Skip to the next section if this includes you.

So most auto tuners and enthusiasts know that an engine is just a glorified air pump. Getting fuel to the cylinders is the easy part thanks to modern electric pumps and injectors. The hard part is pumping the air required for combustion. A typical engine, which breathes due to the vacuum created when the piston moves down the bore, is called naturally aspirated. (There is also the effect of the exhaust gasses rushing out via the exhaust valve, but this is out of scope)

Over the years, inventors have found clever ways to force more air into an internal combustion engine. There are two main schools of thought, and these are forced induction and oxidizers. But superchargers and turbocharges come with some complexities and high cost. Nitrous tends to be the easiest power adder to install, and the cheapest up front, but refill stations can be hard to come by and somewhat expensive. We will use much of the same concepts as N2O.

The Idea

I don't at all
think this is a brand new idea. In fact there are probably patents on it, and they are probably long expired. However, I have never seen a system like this before, so let's investigate this a bit. Okay, enough beating around a bush. How about feeding pre-compressed air into your engine? Here are some numbers for you.

A standard scuba tank is holds 80 ft3 air at 3000psi and weighs in at 6.5lbs. In SI units, these are 2.27 m3 of air at 2.07 x 107 N / m2, weighing in at 2.95kg.

Now let's pick a more or less standard engine. Let's say it's a late model 2.0L 4-cylinder four stroke engine. This means the engine breathes in 2.0L worth of air (assuming 100% VE at the given engine speed), every 720° of crankshaft rotation. Lets assume the engine redlines at 7000 RPM. So our engine theoretically inhales a whopping 3500 x 2.0L = 7000L of air a minute at this speed.

Disappointing Results?

That is approximately 247 cubic feet. Remember, our scuba tank only holds a mere 80 ft3. That means that if our engine were to breathe air from our scuba tank, it could sustain just 80/247 = 0.32 min ≈ 19 seconds... which is, if you ask me, not a very impressive duration. It may seem that I have disproved the usefulness of this invention, but I have glossed over a few details, and the keen reader may have already noticed this.
  • An engine is not going to be held at or near redline very long, so 19 seconds is several bursts of power, not just one elongated rush.
  • This boost would presumably be used at an earlier RPM, which would take linearly less air to satisfy combustion and thus would last longer. This is a corollary of the first point.
  • This is assuming 100% VE, which is not true internal combustion engines at all RPM.
  • And the biggest, and most important point is... We're not feeding the engine solely with air from the compressed tank! The tank is just for additional air above atmospheric pressure.

There's Still Hope


Let's take a look at that last point. Let's just assume that we want to boost the engines air intake by 50%. That would equate to roughly 124 ft3 of air — which would be roughly 7.5 psi of boost pressure at redline. Please bear with the fuzzy math/physics for the sake of brevity. Then, our burst would last about twice as long (80/124 ≈ 39 seconds). Now we're getting somewhere!

Unexplored Ideas

There are still a few problems I did not research as well as some additional ideas I have related to this topic:
  • How do we prevent reversion back through the intake system? with a supercharger or turbo charger this is accomplished by the compressor (the compressor would have to stall to allow the air to flow backwards through it). Could we use some sort of a check valve, like a PCV valve, and plumb it closer to the intake manifold (after the Mass Airflow Sensor, if so equipped)?
  • How do we regulate release for a constant flow rate (or alternatively, constant manifold pressure)? I suspect that a device similar to a pressure regulator could be used, but this would have to stand up to the initial tank pressure of 3000psi.
  • Is there a convenient way to compress the air "at runtime"? That is, does there exist an electric air compressor with the right characteristics to run in the car and fill the tanks when the boost system is not in use? The right characteristics being size, weight, power draw from the electrical system, max pressure near 3000psi, cost, noise (intake mufflers can do wonders for this).
  • Since the tanks are not very heavy (approx: 3 kg), can we run two or more in parallel with couplers to get more use between refills.
  • How do we add the additional fuel required? Should we plumb this in before the Mass Airflow Sensor/ Manifold Absolute Pressure sensor and let the ECU take care of fuel enrichment or should we add our own injector like many N2O systems typically do?

Friday, August 29, 2008

Into the Fray...

Hello and welcome to the first of what will hopefully be many blog posts! Probably you're thinking "who is this guy and why do I care?", to which I would retort "you must know or else how did you find me"? In all seriousness, I am interested in a wide range of topics and I would like one central place to brain dump, get feedback, and toss around ideas. Here are some of the categories I am interested in:
  • Computer programming, especially in C/C++, and occasionally assembler and machine architecture. I like systems-level programming like driver writing for NT or Linux, multi-threaded programming, virtualization and emulation. I also enjoy various scientific applications such as physics simulators, control systems, signal processing, etc../
  • General tips on computer administration, working-around problems with cutting edge beta software, reviews and insight into upcoming products/technologies, and similar topics.
  • Hardware design (schematics, layouts, DRC etc...)
  • Automotive tuning e.g. engine swaps, forced induction, EFI, weight reduction, etc..
  • The occasional rant/rave about current events, funny links, cheesy puns and joke references to obscure 80's, 90's trivia (okay so I have at least that one weakness).
I enjoy feedback and I don't mind being corrected when I am wrong, just know that there is no such thing as a wrong opinion - unless you believe that dogs lay eggs. I really enjoy when a reader takes it to the next level and posts great follow-up material: nobody is an expert in everything, so there will almost always be someone who has looked into the very same topic from another perspective, with a deeper understanding, or arrived at an alternate conclusion.

Also it's great to discuss and debate differing theories on phenomenon and to constructively compare/contrast tradeoffs of one particular technology, approach, or solution but to just plain flame or fly off the handle just shows how little you are :)

So I look forward to a lively debate, a lot of interesting topics and feedback, some laughs, and hopefully very few tears.