Re: Numerical derivatives of compiled functions
- To: mathgroup at smc.vnet.net
- Subject: [mg32873] Re: Numerical derivatives of compiled functions
- From: Thomas Anderson <tga at stanford.edu>
- Date: Sat, 16 Feb 2002 04:35:36 -0500 (EST)
- Organization: Stanford University
- References: <a4if7p$9on$1@smc.vnet.net>
- Reply-to: tga at stanford.edu
- Sender: owner-wri-mathgroup at wolfram.com
It has always bothered me that ND[] does not hold the function argument when it constructs the symbolic expression for the derivative prior to evaluation. One way to get around this problem is to define a "wrapper" function that is defined only for real numbers: In: f = Compile[x, ...]; In: F[x_Real] := f[x] In: ND[F[x], ...] This tactic works well for me. -Tom In article <a4if7p$9on$1 at smc.vnet.net>, Kyriakos Chourdakis <k.chourdakis at qmul.ac.uk> wrote: > Dear all, > > I have a compiled function and want to find the Hessian matrix numerically > at a specific point. The function ND[] does not work even in simple cases > like: > > In: cf = Compile[{x, y}, Module[{a = 3}, Print[x, " ", y]; a x^a y]] > > Out: CompiledFunction[{x, y},Module[{a = 3}, Print[x, " ", y]; a x^a y], > -CompiledCode-] > > > In: ND[cf[q, 4], q, 2] > > CompiledFunction::"cfsa": "Argument q at position 1 should be a > machine-size real number. > q 4 > Out: 144. > > My guess is that ND[] tries to evaluate the function symbolically first. In > my problem I have the product/sum of over 10000 primitive functions, and > symbolic computations for all second-order derivs will take for ever. > > When plotting is concerned, I suppose that the option Compiled does the > trick. How would that work with ND[]? > > Cheers, > > Kyriakos