# Course notes/Numerical integration

Numerical integration is the process of going background from a given derivative of a function to the function itself using computational tools. The simplest form of numerical integration takes advantage of the approximation to the derivative that we get but stopping short of letting $h$ go all the way to zero. That is,

- $\displaystyle f'(x)\approx \frac{f(x+h)-f(x)}{h}$

for a sufficiently small value of $h$. We'll use $h=0.1$ for now.

Suppose we are given a velocity function $v(t)= e^{-t^2}$ but not the position function $x(t)$ and are told that

- $\displaystyle\frac{dx}{dt} = v(t)= e^{-t^2}$.

How do we find the function $x(t)$ if we don't recognize $v(t)$ as the derivative of some known function?

To do this using a computational approach, we need to know the position at some starting time $t_0$. Let's suppose we know that $x(2)=3$. From there on, we can use the approximation above. Let's try to determine the position at $t=5$.

Let's find the position at a time $h$ later, which we'll call $t_1=t_0+h$. Using the approximation

- $\displaystyle v(t_0)=x'(t_0) \approx \frac{x(t_0+h)-x(t_0)}{h}=\frac{x(t_1)-x(t_0)}{h}$

Solving this equation for \(x(t_1)\) we find that

- \(x(t_1) = x(t_0)+h \ v(t_0)\).

Plugging in numbers, we get

- $x(2.1) = x(2)+0.1 \ v(2) = 3+0.1 e^{-4}$.

Repeating this process, replacing $t_0$ with $t_1$, we find that \(x(t_2) = x(t_1)+h \ x(t_1)\) where \(t_2=t_1+h\).

- $x(2.2) = x(2.1)+0.1 \ v(2.1) = (3+0.1 e^{-4}) + 0.1 e^{-(2.1)^2}$.

- $x(2.3) = x(2.2)+0.1 \ v(2.2)$.
- $x(2.4) = x(2.3)+0.1 \ v(2.3)$.

We can repeat this as long as we want, stopping when we get to some desired final time. If we start at $t=2$ and want the position at $t=5$, using $h=0.1$, we'll have to repeat the process 30 times.

### Choosing $h$

There is still the issue of choosing a value of $h$. We know that the derivative approximation is better for smaller \(h\) so we can expect that our estimate of $x(5)$ will be better for smaller $h$. However, the smaller we choose it, the more steps it will take to get to $t=5$. To achieve a desired accuracy, start with a convenient (big) value like $h = 0.4$, record the resulting $x(5)$, and repeat the process for $h=0.2$. Repeat again with $h=0.1$. Repeat again with an $h$ yet again half the size. After three or four repetitions, you will see less and less change in the successive values of $x(5)$. When the change is less than 0.01%, the accuracy of your approximate $x(5)$ value should be sufficient for WeBWorK.