The trapezoid approximation: f is the function, [a,b] the interval, k the number of subintervals.
|
|
The trapezoid error: M is an upper bound on the second derivative of f.
|
|
An example: Let f=e^{-x^2}, on the interval [0,1].
|
|
Compute and plot the second derivative to find the maximum value of |f^{(2)}|.
|
|
So the maximum appears to be 2. Now compute the approximation until the error is small; try increasing j until the two values A-E and A+E round to the same value to two decimal places.
0.745119412436179 0.00462962962962963 0.740489782806550 0.749749042065809 0.745119412436179 0.00462962962962963 0.740489782806550 0.749749042065809 |
The Simpson's rule function and error computation are similar. You must put in an even number for k; the function doesn't check for this.
|
|
|
|
|
|
The maximum value of |f^{(4)}| appears to be 12.
0.746855379790987 0.000260416666666667 0.746594963124320 0.747115796457654 0.746855379790987 0.000260416666666667 0.746594963124320 0.747115796457654 |
Let's see what Sage thinks the value is.
0.746824132812427 0.746824132812427 |
|
|