Difference between revisions of "Course notes/Numerical integration"

From UBCMATH WIKI
Jump to: navigation, search
(Created page with "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...")
 
Line 1: Line 1:
 
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,
 
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,
:$f'(x)\approx \frac{f(x+h)-f(x)}{h}$
+
:$\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.
 
for a sufficiently small value of $h$. We'll use $h=0.1$ for now.
  
 
Suppose we are given a velocity function $v(t)$ but not the position function $x(t)$ and are told that  
 
Suppose we are given a velocity function $v(t)$ but not the position function $x(t)$ and are told that  
:$\frac{dx}{dt} = v(t)= e^{-t^2}$.  
+
:$\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?
 
How do we find the function $x(t)$ if we don't recognize $v(t)$ as the derivative of some known function?
  
Line 10: Line 10:
  
 
Let's find the position at a time $h$ later, which we'll call $t_1=t_0+h$. Using the approximation
 
Let's find the position at a time $h$ later, which we'll call $t_1=t_0+h$. Using the approximation
:$v(t_0)=x'(t_0) \approx \frac{x(t_0+h)-x(t_0)}{h}=\frac{x(t_1)-x(t_0)}{h}$
+
:$\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
 
Solving this equation for \(x(t_1)\) we
 
find that
 
find that
  
:\(x(t_1) = x(t_0)+h v(t_0)\).
+
:\(x(t_1) = x(t_0)+h \ v(t_0)\).
  
 
Replacing all the letters but numbers, we get
 
Replacing all the letters but numbers, we get
  
:\(x(2.1) = x(2)+0.1 v(2) = 3+0.1 e^{-4}\).
+
:$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
 
Repeating this process, replacing $t_0$ with $t_1$, we find that
\(x(t_2) = x(t_1)+h x(t_1)\)
+
\(x(t_2) = x(t_1)+h \ x(t_1)\)
 
where \(t_2=t_1+h\).
 
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}$.
  
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   times.
+
:$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$===
 
===Choosing $h$===
 
There is still the issue of choosing a value of $h$. We know that the
 
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
 
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.5$, record the resulting $x(5)$, and repeat the process for
+
$h = 0.4$, record the resulting $x(5)$, and repeat the process for
$h$ half the size. Repeat. Repeat. After three or four repetitions, you will see less
+
$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
 
and less change in the successive values of $x(5)$. When the change is less
than 0.01%, your accuracy should be sufficient for WeBWorK.
+
than 0.01%, the accuracy of your approximate $x(5)$ value should be sufficient for WeBWorK.

Revision as of 09:45, 16 September 2014

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)$ 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)\).

Replacing all the letters but 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.