Dan Bron wrote:
> Piet de Jong wrote:
>>  What am I misunderstanding.
>>  Why does D.2 not work as expected?
>
> D.  has known precision issues.  See, for example:
>
>       http://www.jsoftware.com/pipermail/general/2006-July/027701.html

Thanks to Dan for promoting me to expert.

The derivatives appear to be calculated with a step size of 1e_7, and
higher derivatives appear to be calculated by differentiating lower
derivatives:

   a=:+/@:*: D.2   [  1 1
   f=:+/@:*:
   1e_7 1e_7 f D: 2 [ 1 1
   1.95399 _0.0444089
_0.0444089    1.95399
   a
   1.95399 _0.0444089
_0.0444089    1.95399

Precision problems occur even for functions of one variable.

   g=:1+*:
   g D. 2 [ 1
1.95399
   h=:1e_7
   d=:1 : 'h %~ (u y+h)-u y'
   g d d [ 1
1.95399

By using a better approximation formula for the second derivative, you can
use a larger step size (h):

   h=:1e_5
   d2=:1 : '(*: h) %~ (u y-h)+(_2*u y)+(u y+h)'
   g d2 1
2

Best wishes,

John


----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to