| Copyright | (c) Eric Zoerner 2023 |
|---|---|
| License | BSD3 |
| Maintainer | eric.zoerner@proton.me |
| Safe Haskell | Safe-Inferred |
| Language | GHC2021 |
Chapter04
Description
Documentation
type Derivative = (R -> R) -> R -> R Source #
A derivative is a function of a real to real that yields another function of real to real
derivative :: R -> Derivative Source #
Numerical derivation given a small delta
Exercise 4.1
Why does derivative 0.1 not produce exactly the identity function on real numbers?
Because 0.1 cannot be represented exactly in a Double.
See: Why 0.1 Does Not Exist In Floating-Point
>>>derivative 10 f41 11.0>>>derivative 1 f41 11.0>>>derivative 0.1 f41 11.0000000000000002
Exercise 4.2
(See functions f42, err42 below.)
Evaluating the derivative at different values of x (the second argument):
>>>err42 1 60.25
>>>err42 1 0.50.25
>>>err42 1 10.25
It appears empirically that the error does not depend on x at all,
it only depends on a.
Exploring the error for different values of a:
>>>err42 1 10.25
>>>err42 0.1 12.500000000002167e-3
>>>err42 0.01 52.4999998515795596e-5
>>>err42 0.02 59.999999903698154e-5
>>>err42 0.03 52.249999984940132e-4
After some trial and error, it is deduced that it follows a pattern like:
err(a) = a²/4
This formula is the implementation of the errA function below.
When x = 4, Df (4) = 48. What value of a produces an error of
1 percent at x = 4?
Use the formula we came up with, and solving for a:
a²/4 = (0.01)(48) a² = (0.01)(48)(4) a = √ ((0.01)(48)(4))
>>>sqrt $ 0.01 * 48 * 41.3856406460551018
When x = 0.1, Df (0.1) = 0.03.
What value of a produces an error of 1 percent at x = 0.1?
Again, solving for a:
a²/4 = (0.01)(0.03) a² = (0.01)(0.03)(4) a = √ ((0.01)(0.03)(4))
>>>sqrt $ 0.01 * 0.03 * 43.4641016151377546e-2
Arguments
| :: (R -> R) |
|
| -> (R -> R) |
|
| -> R |
|
| -> R |
|
| -> R | Returns the error |
Error function: Returns the error between a numerical derivative estimate and the provided analytical derivative.
Error function for f42.
Returns the error in terms of a (the "delta").
The expression for the error is apparantly a²/4.
This formula was just determined empirically by putting a bunch of
a values into err42 and looking at the pattern of results.
Exercise 4.3
Using the expression from Exercise 4.2,
using errA a0.01 for the value of a, solve for x in errA 0.01 >= 0.10 * x.
0.01²/4 ≥ 0.10x 0.10x ≤ 0.01²/4 x ≤ 0.01²/4/0.10
>>>0.01 ** 2 / 4 / 0.102.5e-4
Therefore:
x ≤ 2.5e-4
Exercise 4.4
- - TO DO
Exercise 4.5
- - TO DO