Adaptive Simpson Octave Implementation
John Bryan
- Setup
- a=lower limit of integration.
- b=upper limit of integration.
- $\text{h}_{1}=\frac{\text{b}-\text{a}}{2}$
- $\text{h}_{2}=\frac{\text{h}_{1}}{2}$
-
\begin{equation}
\text{S}_{1} = \frac{\text{h}_{1}}{3}(f(\text{a})+4f(\text{a}+\text{h}_{1})+f(\text{b}))
\end{equation}
\begin{equation}
\text{S}_{2} = \frac{\text{h}_{2}}{3}(f(\text{a})+4f(\text{a}+\text{h}_{2})+2f(({a}+2\text{h}_{2})+4f(\text{a}+3\text{h}_{2})+f(\text{b}))
\end{equation}
\begin{equation}
\text{Error}=\frac{|\text{S}_{2}-\text{S}_{1}|}{15}
\end{equation}
-
Use recursion to successively subdivide (a,b) integration approximation into sum of (a,$\frac{b+a}{2}$) and ($\frac{b+a}{2}$,b) integration approximations. The tolerance is divided by 2 at each level.
-
Continue to calculate integration approximations over smaller regions until the error is smaller than level tolerance.
Octave implementation.
Results.
$\int_0^{10} sin(x) dx$
|
Exact | 1.839071529076453 |
Adaptive Simpson |
1.839071529076453 |
Difference from exact |
0.000000000000000
|
eps |
2.220446049250313e-16
|