MathGroup Archive 2003

[Date Index] [Thread Index] [Author Index]

Search the Archive

Numerical Divergence

  • To: mathgroup at smc.vnet.net
  • Subject: [mg42909] Numerical Divergence
  • From: Selwyn Hollis <selwynh at earthlink.net>
  • Date: Sat, 2 Aug 2003 04:12:34 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

I've made a couple of attempts at writing a function

NDiv[f_List, x:{_Symbol..}, h_Real][p:{_?NumericQ..}]

that computes a numerical approximation of div(f) at p, using central 
differences with stepsize h. My (successful) attempts have used (1) Tr 
and (2) MapIndexed, and neither is very fast. Since the divergence can 
be computed symbolically as

Inner[D,f,x,Plus],

one would think that NDiv could be computed in an some analogous way 
with Inner. However, my attempts have been unsuccessful.

Can any of you wizards help me out?

FYI: Here's the basic idea of my MapIndexed version:

NDiv[f_List, x:{_Symbol..}, h_Real][p:{_?NumericQ..}] :=
Module[{nPD, idm = IdentityMatrix[Length[p]]},
   nPD[f_, {i_}] :=
     ((f/.Thread[x-> p+h*idm[[i]]]) - (f/.Thread[x-> 
p-h*idm[[i]]]))/(2*h);
   Plus@@MapIndexed[nPD, f] ]

-----
Selwyn Hollis
http://www.math.armstrong.edu/faculty/hollis


  • Prev by Date: Re: Severe ToExpression Fault?
  • Next by Date: RE: multiple roots finder.
  • Previous by thread: Re: Justification of graphics in cells
  • Next by thread: Re: Numerical Divergence