@@ -7,10 +7,10 @@ import math
77fn central_deriv (f func.Fn, x f64 , h f64 ) (f64 , f64 , f64 ) {
88 /*
99 Compute the derivative using the 5-point rule (x-h, x-h/2, x,
10- * x+h/2, x+h). Note that the central point is not used.
11- * Compute the error using the difference between the 5-point and
12- * the 3-point rule (x-h,x,x+h). Again the central point is not
13- * used.
10+ * x+h/2, x+h). Note that the central point is not used.
11+ * Compute the error using the difference between the 5-point and
12+ * the 3-point rule (x-h,x,x+h). Again the central point is not
13+ * used.
1414 */
1515 fm1 := f.eval (x - h)
1616 fp1 := f.eval (x + h)
@@ -23,9 +23,9 @@ fn central_deriv(f func.Fn, x f64, h f64) (f64, f64, f64) {
2323 dy := math.max (math.abs (r3 / h), math.abs (r5 / h)) * (math.abs (x) / h) * prec.f64_ epsilon
2424 /*
2525 The truncation error in the r5 approximation itself is O(h^4).
26- * However, for safety, we estimate the error from r5-r3, which is
27- * O(h^2). By scaling h we will minimise this estimated error, not
28- * the actual truncation error in r5.
26+ * However, for safety, we estimate the error from r5-r3, which is
27+ * O(h^2). By scaling h we will minimise this estimated error, not
28+ * the actual truncation error in r5.
2929 */
3030 result := r5 / h
3131 abserr_trunc := math.abs ((r5 - r3 ) / h) // Estimated truncation error O(h^2)
@@ -40,15 +40,15 @@ pub fn central(f func.Fn, x f64, h f64) (f64, f64) {
4040 if round < trunc && (round > 0.0 && trunc > 0.0 ) {
4141 /*
4242 Compute an optimised stepsize to minimize the total error,
43- * using the scaling of the truncation error (O(h^2)) and
44- * rounding error (O(1/h)).
43+ * using the scaling of the truncation error (O(h^2)) and
44+ * rounding error (O(1/h)).
4545 */
4646 h_opt := h * math.pow (round / (2.0 * trunc), 1.0 / 3.0 )
4747 r_opt , round_opt , trunc_opt := central_deriv (f, x, h_opt)
4848 error_opt := round_opt + trunc_opt
4949 /*
5050 Check that the new error is smaller, and that the new derivative
51- * is consistent with the error bounds of the original estimate.
51+ * is consistent with the error bounds of the original estimate.
5252 */
5353 if error_opt < error && math.abs (r_opt - r_0 ) < 4.0 * error {
5454 result = r_opt
@@ -61,9 +61,9 @@ pub fn central(f func.Fn, x f64, h f64) (f64, f64) {
6161fn forward_deriv (f func.Fn, x f64 , h f64 ) (f64 , f64 , f64 ) {
6262 /*
6363 Compute the derivative using the 4-point rule (x+h/4, x+h/2,
64- * x+3h/4, x+h).
65- * Compute the error using the difference between the 4-point and
66- * the 2-point rule (x+h/2,x+h).
64+ * x+3h/4, x+h).
65+ * Compute the error using the difference between the 4-point and
66+ * the 2-point rule (x+h/2,x+h).
6767 */
6868 f1 := f.eval (x + h / 4.0 )
6969 f2 := f.eval (x + h / 2.0 )
@@ -75,9 +75,9 @@ fn forward_deriv(f func.Fn, x f64, h f64) (f64, f64, f64) {
7575 dy := math.max (math.abs (r2 / h), math.abs (r4 / h)) * math.abs (x / h) * prec.f64_ epsilon
7676 /*
7777 The truncation error in the r4 approximation itself is O(h^3).
78- * However, for safety, we estimate the error from r4-r2, which is
79- * O(h). By scaling h we will minimise this estimated error, not
80- * the actual truncation error in r4.
78+ * However, for safety, we estimate the error from r4-r2, which is
79+ * O(h). By scaling h we will minimise this estimated error, not
80+ * the actual truncation error in r4.
8181 */
8282 result := r4 / h
8383 abserr_trunc := math.abs ((r4 - r2 ) / h) // Estimated truncation error O(h)
@@ -92,15 +92,15 @@ pub fn forward(f func.Fn, x f64, h f64) (f64, f64) {
9292 if round < trunc && (round > 0.0 && trunc > 0.0 ) {
9393 /*
9494 Compute an optimised stepsize to minimize the total error,
95- * using the scaling of the estimated truncation error (O(h)) and
96- * rounding error (O(1/h)).
95+ * using the scaling of the estimated truncation error (O(h)) and
96+ * rounding error (O(1/h)).
9797 */
9898 h_opt := h * math.pow (round / trunc, 1.0 / 2.0 )
9999 r_opt , round_opt , trunc_opt := forward_deriv (f, x, h_opt)
100100 error_opt := round_opt + trunc_opt
101101 /*
102102 Check that the new error is smaller, and that the new derivative
103- * is consistent with the error bounds of the original estimate.
103+ * is consistent with the error bounds of the original estimate.
104104 */
105105 if error_opt < error && math.abs (r_opt - r_0 ) < 4.0 * error {
106106 result = r_opt
0 commit comments