**This post is for computer programmers who sort of remember Calculus from school and always thought it was kind of cool, but don’t really think about it that much any more.**

**First, I’m going to construct a point that has no width, height or depth.**

This dot obviously has some width and height in order to be visible on the page. But just pretend that it has no width or height and that its an invisible logical point in space.

**And now I’ll integrate that logical point into a one dimensional line.**

This line represents a logical object which is infinitely long, but still has no height and no depth.

**Next, I’ll integrate my logical line along a perpendicular axis to make it into a 2D square.**

This square is infinitely long on a single plane, but it has no depth.

**And finally I’ll integrate my 2D square along a final perpendicular ‘z-axis’.**

Which gives the shape depth and produces a logical representation of the 3D space we know and love.

**Consider the transition from a 1D line into 2D rectangle**

The transition from a line to a rectangle happens by integrating a line of width across some height into a rectangle of width x height. This can be symbolically written as the well known formula for the area of a rectangle:

**If I want to calculate the area of a shape defined by the function x**

The principle remains the same but with a slightly more complicated implementation.

**And my point is that the area under a curve is the integral of the function used to create the curve.**

**Consider a car steadily traveling in variable traffic and subject to arbitrary speed adjustments due to unpredictable environmental conditions.**

In this case it would be impractical to construct a symbolic model to represent the car’s speed as a function of time, but I can still sample the car speed at regular intervals and then use a numerical method to calculate the area under a graph of the samples taken.

What’s cool about this example is that the integral of speed over some time period is both the area under the curve and the distance traveled. And so by estimating the area, I’ll also have an estimate for distance.

To see how this is true, consider the following visualization in which both distance and the area of the graph are calculated with rate*time.

In this next scenario, distance can be calculated by adding up the areas of the two visible rectangles.

So for instance if drive for an hour at about 60 mph, and then another hour at about 30 mph then i’ll expect to have gone a total of about 90 miles.

**I’ve created a black box function to numerically model the speed of a car traveling along in variable traffic. It will be run 60 times to represent gathering speed measurements every minute for an hour. The speeds are recorded and then the total distance is estimated by adding up the distance traveled each minute.**

```
class BlackBox
def initialize
@base_speed = 55
@rnd = Random.new
end
def speed(t)
@base_speed - 5*Math.sin(7.5*t)
end
end
car = BlackBox.new
car_speeds = Array.new
minutes_per_hour = 60.0
duration_in_hours = 1
measurements_per_hour = 60.0
num_measurements = duration_in_hours * measurements_per_hour
time_per_measurement = duration_in_hours/num_measurements
num_measurements.to_i.times do |minute|
time_in_hours = minute/minutes_per_hour
car_speeds.push(car.speed(time_in_hours))
end
distance = car_speeds.inject(0){|sum, speed| sum + speed * time_per_measurement }
puts distance
=> 54.60407418218318 miles
```

**
Because the black box function is actually known in this example (speed(t) above), I can confirm the numerical result is a good approximation by symbolically integrating over the same interval to yield a more accurate but similar result.
**

And as a final reality check, I do expect to travel about 55 miles if I drive about 55 mph for an hour.