x u D: n y Secant Slope Conjunction
The math/calculus addon defines a conjunction sslope_jcalculus_ that replaces the functions of this primitive. Execute
to load this addon after you have downloaded it through Tools|Package Manager.
The slope of a straight line drawn through point y and point y+x on the curve of the mathematical function [implemented by verb] u
...That is for n=1. More generally D:n is an approximation to the n-th derivative of u
sin D.1 y=:i.6 NB. The 1st derivative, for comparison purposes 1 0.540302 _0.416147 _0.989992 _0.653644 0.283662 0.0001 sin D:1 y NB. Secant slope for interval(s) [y,y+0.0001] 1 0.54026 _0.416192 _0.99 _0.653606 0.28371 0.001 sin D:1 y NB. Secant slope for wider interval 1 0.539881 _0.416601 _0.990063 _0.653265 0.284142 0.01 sin D:1 y NB. Secant slope for still wider interval 0.999983 0.536086 _0.420686 _0.990682 _0.649849 0.288452
1. To approximate a derivative, especially when better control over the step size x is needed
func =: verb define NB. function (x-2)^2 + (y-3)^2, with critical point at (2,3) 'x y' =. y (*: x-2) + (*: y-3) ) ]hessian =: func D. 2 (2 3) NB. Matrix of mixed second partial derivatives 2 _0.5 0.333333 2 NB. Whoops!! That's wrong. D. 2 chose a bad stepsize ]hessian =: 1e_6 func D: 2 (2 3) NB. Matrix of mixed second partial derivatives 2 0 0 2
Derivative (u D. n)
2. Multiple slopes (corresponding to partial derivatives) are calculated when the cells of u y have rank greater than 0. The result contains the slope of each result atom with respect to each input atom.
(frame of y wrt verb u) , (shape of y) , (shape of result of u on a single cell) |<---- shape of result of single cell of u D: 1 ---->|
3. Higher derivatives are requested by a value of n greater than 1. These results are sensitive to step size
0j13 ": 1e_3 sin D:3 (1) NB. Some bad results 111.0223024625157 0j13 ": 1e_2 sin D:3 (1) _0.5390394797189 0j13 ": 1e_2 sin D:3 (1) _0.5276133364651 0j13 ": sin"0 D.3 (1) NB. This is the correct result _0.5403023058681
4. Higher-order secants are allowed.
((shape of `y`) , (shape of result of `u` on a single cell)
The shape of u D: 2 y is
(frame of y wrt verb u) , (shape of y) , (shape of y) , (shape of result of u on a single cell) |<---- shape of result of single cell of u D: 1 ---->| |<----------- shape of result of single cell of u D: 2 ------------>|
The pattern continues for higher-order secants. These approximate all the possible mixed partial derivatives of u at y. The indexes in the "shape of y" sections of the above schematic select a particular mixed partial derivative.
1. If any atom of n is less than 0, J signals an error.
n is converted to 1 >. '' $!.1 , n before processing, i.e. the first atom of n, but with 0 changed to 1.
(frame of y wrt verb u) , (; n # <$y) , (shape of result of u on a single cell)