Numerical integration and differentiation

Often in an experiment, some quantity is measured as a function of time. For instance, by videotaping a moving object it is possible to determine the position of the object in every frame of the videotape. Using a Doppler radar, it is possible to record the velocity of an object as a function of time. Using the accelerometer in a mobile phone, it is possible to record the acceleration as a function of time. If one of these quantities is measured, the others can be calculated. If the measured data is in tabular form, the integration or differentiation must be done numerically.

This page contains some programs for integrating and differentiating numerical data. A function $f(t)$ is can be specified either by inputting a mathematical formula at the top or by pasting two columns of data in the textbox at the top-left. When the "Calculate from formula" button is pressed, the formula is used to fill the table with 1000 equally spaced values of $f(t)$ equally spaced between $t_1$ and $t_2$. When the "calculate from table" button is pressed, the data is plotted on the right. Below the data and plot of $f(t)$, the derivative $\frac{df}{dt}$ and the second derivative $\frac{d^2f}{dt^2}$ are tabulated and plotted. Below the derivatives, the integral of $f(t)$ is shown as well as the integral of the integral. The integration routines assume that the measurements are equally spaced with an interval $\Delta t$.

$f(t)=$ 
in the range from $t_1=$  to $t_2=$ .

 $t$   $f(t)$

  

$f(t)$

$t$

The derivative
The derivative of $f(t)$ is calculated as,

$\Large \frac{df}{dt}\approx \frac{f(t+\Delta t)-f(t)}{\Delta t}.$

 $t$   $\large \frac{df}{dt}$

  

$\large \frac{df}{dt}$

$t$

The second derivative
The derivative of $f(t)$ is calculated as,

$\Large \frac{d^2f}{dt^2}\approx \frac{\frac{df}{dt}(t+\Delta t)-\frac{df}{dt}(t)}{\Delta t}.$

 $t$   $\large \frac{d^2f}{dt^2}$

  

$\large \frac{d^2f}{dt^2}$

$t$

The integral of $f(t)$

$\large I_1(t)=\int\limits_{t_1}^{t} f(t')dt' +I_1(t_1)$.

Here $I_1(x_1)$ is the integration constant. For instance, suppose $f(t)$ represents the velocity in the $x$-direction, $v_x$. The position is the integral of the velocity,

$\large x(t)= \int \limits_{t_1}^{t} v_x(t')dt' +x(t_1).$

In this case, the integration constant is the initial position at time $t_1$, $I_1(t_1) = x(t_1)$.

$I_1(t_1)=$

The integral of $f(t)$ is calculated numerically using a method called Simpson's rule.

$\large \int \limits_a^b f(t) dt \approx \frac{b-a}{6}\left(f(a) + 4f\left(\frac{a+b}{2}\right)+f(b)\right).$

 $t$   $I_1(t)$

  

$I_1(t)$

$t$

The integral of the integral of $f(t)$
Simpson's rule was used a second time to calculate the integral of the integral of $f(t)$.

$\large I_2(t) = \int \limits_{t_1}^{t} I_1(t')dt' + I_2(t_1).$

Where $I_2(x_1)$ is the integration constant. For instance, suppose $f(t)$ represents the acceleration in the $x$-direction, $a_x$. The velocity is the integral of the acceleration,

$\large v_x(t)= \int \limits_{t_1}^{t} a_x(t')dt' +v_x(t_1),$

and the position is the integral of the velocity,

$\large x(t)=\int \limits_{t_1}^{t} v_x(t')dt' +x(t_1).$

Here $I_1(t_1)=v_x(t_1)$ and $I_2(t_1)=x(t_1)$ are the integration constants.

$I_2(t_1)=$

 $t$   $I_2(t)$

  

$I_2(t)$

$t$

For problems involving position, velocity, acceleration, and force

  • If you have a table of data that describes the position as a function of time:
    Paste the data in the top textbox and press calculate. The velocity is the derivative; the acceleration is the second derivative; the force is the mass times the acceleration (use a spreadsheet to calculate the force). Ignore the integrals. The values of $I_1(t_1)$ and $I_2(t_1)$ are irrelevant.
  • If you have a table of data that describes the velocity as a function of time:
    Paste the data in the top textbox. The position is the integral of velocity. The constant $I_1(t_1)$ is the initial position $I_1(t_1)=x(t_1)$. The acceleration is the derivative; the force is the mass times the acceleration (use a spreadsheet to calculate the force). Ignore the second derivative and the integral of the integral. The value of $I_2(t_1)$ is irrelevant.
  • If you have a table of data that describes the acceleration as a function of time:
    Paste the data in the top textbox. The velocity is the integral of the acceleration. The constant $I_1(t_1)$ is the initial velocity $I_1(t_1)=v_x(t_1)$. The position is the integral of velocity which is the integral of the integral of the acceleration. The constant $I_2(t_1)$ is the initial position $I_2(t_1)=x(t_1)$. The force is the mass times the acceleration (use a spreadsheet to calculate the force). Ignore the derivatives.
  • If you have a table of data that describes the force as a function of time:
    Use a spreadsheet to divide the force by the mass to get the acceleration. Use the acceleration to calculate the position and velocity.
  • If the data points you have are not equally spaced in time, you can use either of the apps linear interpolation, or cubic spline to generate data points that are equally spaced in time.