Differentiation with a Computer
- Forward-difference approximation. A computer can calculate an approximation to the derivative, if a very small value is used for
.
- Recalculating with smaller and smaller values of
starting from an initial value.
- What happens if the value is not small enough?
- We should expect to find an optimal value for
.
- Because round-off errors in the numerator will become great as
approaches zero.
- When we try this for
at
. The analytical answer is 4.1653826.
Apply Forward-difference approximation to
. (Example py-file:
myforwardderivative.py)
Table 4.1:
Forward-difference approximation for
.
![\begin{table}\begin{center}
\includegraphics[scale=0.3]{images/5-1a}
\end{center}
\end{table}](img124.svg) |
Figure 4.1:
Forward-difference approximation for
.
|
Apply Backward-difference approximation to
. (Example py-file:
mybackwardderivative.py)
Table 4.2:
Backward-difference approximation for
.
![\begin{table}\begin{center}
\includegraphics[scale=0.3]{images/5-1b}
\end{center}
\end{table}](img129.svg) |
Figure 4.2:
Backward-difference approximation for
.
|
- If we add Eqs. 4.2 and 4.3, then divide by 2, we get the central-difference approximation to the derivative:
- We had to extend the two Taylor series by an additional term to get the error because the
terms cancel.
- This shows that using a central-difference approximation is a much preferred way to estimate the derivative.
- Even though we use the same number of computations of the function at each step,
- We approach the answer much more rapidly.
Apply Central-difference approximation to
. (Example py-file:
mycentralderivative.py)
Table 4.3:
Central-difference approximation for
.
![\begin{table}\begin{center}
\includegraphics[scale=0.3]{images/5-1c}
\end{center}
\end{table}](img143.svg) |
Figure 4.3:
Central-difference approximation for
.
|
Apply Forward-difference approximation to Simple Harmonic Motion. (Example py-file:
shm.py)
Figure 4.4:
Time change of position and velocity in motion under the force F=-kx.
|