]> gitweb.factorcode.org Git - factor.git/blob - unmaintained/math/derivatives/derivatives-docs.factor
84f456aacf0a8f97519ed3973fbd75fc6246039c
[factor.git] / unmaintained / math / derivatives / derivatives-docs.factor
1 USING: help.markup help.syntax math math.functions ;
2 IN: math.derivatives
3
4 HELP: derivative
5 { $values { "x" "a position on the function" } { "function" "a differentiable function" } { "m" number } }
6 { $description
7     "Approximates the slope of the tangent line by using Ridders' "
8     "method of computing derivatives, from the chapter \"Accurate computation "
9     "of F'(x) and F'(x)F''(x)\", from \"Advances in Engineering Software, Vol. 4, pp. 75-76 ."
10 }
11 { $examples
12     { $example
13         "USING: math math.derivatives prettyprint ;"
14         "4 [ sq ] derivative >integer ."
15         "8"
16     }
17     { $notes
18         "For applied scientists, you may play with the settings "
19         "in the source file to achieve arbitrary accuracy. "
20     }
21 } ;
22
23 HELP: (derivative)
24 { $values
25     { "x" "a position on the function" }
26     { "func" "a differentiable function" }
27     {
28         "h" "distance between the points of the first secant line used for "
29         "approximation of the tangent. This distance will be divided "
30         "constantly, by " { $link con } ". See " { $link init-hh }
31         " for the code which enforces this. H should be .001 to .5 -- too "
32         "small can cause bad convergence. Also, h should be small enough "
33         "to give the correct sgn(f'(x)). In other words, if you're expecting "
34         "a positive derivative, make h small enough to give the same "
35         "when plugged into the academic limit definition of a derivative. "
36         "See " { $link update-hh } " for the code which performs this task."
37     }
38     {
39         "err" "maximum tolerance of increase in error. For example, if this "
40         "is set to 2.0, the program will terminate with its nearest answer "
41         "when the error multiplies by 2. See " { $link check-safe } " for "
42         "the enforcing code."
43     }
44     {   "ans" number }
45     {   "error" number }
46 }
47 { $description
48     "Approximates the slope of the tangent line by using Ridders' "
49     "method of computing derivatives, from the chapter \"Accurate computation "
50     "of F'(x) and F'(x)F''(x)\", from \"Advances in Engineering Software, "
51     "Vol. 4, pp. 75-76 ."
52 }
53 { $examples
54     { $example
55         "USING: math math.derivatives prettyprint ;"
56         "4 [ sq ] derivative >integer ."
57         "8"
58     }
59     { $notes
60         "For applied scientists, you may play with the settings "
61         "in the source file to achieve arbitrary accuracy. "
62     }
63 } ;
64
65 HELP: derivative-func
66 { $values { "func" "a differentiable function" } { "der" "the derivative" } }
67 { $description
68     "Provides the derivative of the function. The implementation simply "
69     "attaches the " { $link derivative } " word to the end of the function."
70 }
71 { $examples
72     { $example
73         "USING: kernel math.derivatives math.functions math.trig prettyprint ;"
74         "60 deg>rad [ sin ] derivative-func call 0.5 .001 ~ ."
75         "t"
76     }
77     { $notes
78         "Without a heavy algebraic system, derivatives must be "
79         "approximated. With the current settings, there is a fair trade of "
80         "speed and accuracy; the first 12 digits "
81         "will always be correct with " { $link sin } " and " { $link cos }
82         ". The following code performs a minumum and maximum error test."
83         { $code
84             "USING: kernel math math.functions math.trig sequences sequences.lib ;"
85             "360"
86             "["
87             "           deg>rad"
88             "            [ [ sin ] derivative-func call ]"
89             "           ! Note: the derivative of sin is cos"
90             "            [ cos ]"
91             "       bi - abs"
92             "] map minmax"
93         }
94     }
95 } ;
96
97 ARTICLE: "derivatives" "The Derivative Toolkit"
98 "A toolkit for computing the derivative of functions."
99 { $subsections
100     derivative
101     derivative-func
102     (derivative)
103 } ;
104
105 ABOUT: "derivatives"