Physics with Danno

Previous Chapter: Simulation graphs
Next Chapter: Momentum

Lesson 3: Calculus primer

Wow, this is a weird spot for this chapter, huh? Eh, whatever.

Calculus is *extremely* important to the study of physics. It's foundational to the subject. Unfortunately it's a large and long subject to teach, so we won't really be covering it. If you're interested in learning calculus, there's like a billion sites on the internet that will teach you it, go find one.

Instead, I'm going to be giving a break-neck overview of the important bits for us.

Let's recall the simulation loop we'll be working with:

loop for every instant of time {
    loop for every object {
        1. force = ...
        2. dvel = force / mass * dt
        3. velocity += dvel
        4. dpos = velocity * dt
        5. position += dpos
    }
    time += dt
}

There are 2 important constructs that are studied in calculus: the derivative and the integral. But we're only really going to be talking about integrals.

The integral

For us, integrals look like this:

k=T1T2quantitykdother-quantityk

Meaning, summing up, for every timestamp between time T1 and T2, the product of some quantity and the "d" form of some other quantity. The values are subscripted, meaning that, for each timestamp, we're using the quanties as they were *at that timestamp*, and then moving on to the next timestamp.

An example:

k=T1T2forcekdposk

Here's another one, this time using "dforce". That isn't present in the loop above but it means the same thing, the change in force between each successive timestamp:

k=T1T2(forcek+velocityk)dforcek

Another one, where I don't subscript dt because it's the same at every timestamp:

k=T1T2velocitykdt

We've seen this last integral already, actually. This is just lines 4 and 5 of the simulation loop above! An object's position is just the sum of the velocity at each timestamp, times dt:

positionT2=positionT1-dt+k=T1T2velocitykdt

There are a few things to know about integrals.

Convergence

The two integrals that are present in the simulation loop, the one for velocity and the one for position, they both *converge*. Every time you make dt smaller, the values of velocity and position "settle further into" their final value.

dtposition of left ball at t=3.0
dt = 1-2.875
dt = 1/40.011004274380613504
dt = 1/160.024260614298508315
dt = 1/320.024890049185773932
dt = 1/1280.02508617623223446
dt = 1/5120.0250984251867963
dt = 1/20480.025099190711406923

The other two integrals that I listed above as examples also converge. The conditions for convergence are a bit touchy, but here's the general idea:

There's some more subtlety to it, but this should be good enough for us. If you're interested in learning more, the subject is usually called "Real Analysis" or some variant of "Modern Calculus" in textbooks and college courses.

Antiderivaties

Another big thing to know about integrals is that they have something called "antiderivatives". Essentially, if an integral is convergent, the exists a function, that we'll call U here, that satisfies:

k=T1T2quantitydother-quantitydt 0U(T2)-U(T1)

U here is called an antiderivative. What form exactly U takes is difficult to determine. A large part of a calculus course involves learning tricks to let you figure out what U is given the integrand and differential.

The weird arrow thing is trying to convey that the left-hand side will converge to the right-hand side as dt gets smaller.

One important thing for us to know is that the form that U takes depends ONLY on the choice of integrand and differential, NOT the choice of upper and lower bounds T1 and T2.

The other important property is best shown through an example. If, say, the differential is dvel, and the integrand is some expression involving ONLY velocity, then there exists a form of the antiderivative that can be expressed as the difference between a function evaluated at the velocity at the beginning and end timestamps. So as a concrete example:

k=T1T2velocity2dveldt 0(13velocityT23)-(13velocityT13)

I don't really want to get into why they're called antiderivatives.

Areas under graphs

An important interpretation of integrals is as describing the area under a graph:

The idea is that you can approximate the area under a graph with a bunch of thin rectangles and adding up their area, and it can be made more accurate by making the rectangles thinner. Again, if you don't get this, there are other places online that will teach you calculus.

The integral that we outlined above corresponds to the right-point formulation of the area under the graph. The integrand is the height of the graph at a particular timestamp, and the differential is the distance between that timestamp and the previous one.

Another thing you learn in a calculus class is that other formulations, like the midpoint or trapezoidal formulations, will also converge to the same value. Here's the left-point formulation:

This corresponds to the integral:

k=T1T2quantitykdother-quantityk+dt

Something that's rarely taught in school is that it's perfectly fine to offset in the other direction:

Which corresponds to the integral:

k=T1T2quantityk+dtdother-quantityk

I'm not sure if this one has a name. But we'll be using it in a couple lessons, so I guess I'll call this one the double-right-point formulation. It's sort of offset from the actual graph by a little bit, but as dt get smaller the difference converges to 0.

Changelog:

Previous Chapter: Simulation graphs
Next Chapter: Momentum

© by Daniel Taylor