Subject: Re: CCL:gradients

From: Konrad Hinsen <[email-masked]>
Date: Tue, 21 Jul 1998 19:43:36 +0200 (DFT)

> I have a 3-D space and can calculate the value of the function
> at any sets of points in the space that I choose.  I must
> calculate the gradient of my function.  Can anybody give me 
> some pointers about the best way to do this (both in terms of
> comnputational efficiency and accuracy)?  Is it best to take

It all depends on your needs. Here are the options:

- Finite differences. This requires nothing but the possibility
  to calculate your function at any point, but it is an approximation.
  You can then either calculate your function at every point on
  a rectangular grid, and then take the derivatives all over
  the grid, or you can evaluate the function around a given point
  as needed. For an implementation of the first approach, for
  rectangular but not necessarily equidistant grids, see
    http://starship.skyport.net/crew/hinsen/Interpolation.py
  (that's in Python).

- Analytic derivatives. That gives the best accuracy and
  usually also efficiency, but it requires you to know the
  functional form of your function analytically. If you
  are distracted by the hard work of calculating derivatives,
  computer algebra packages like Mathematica or Maple could
  be of use.

- Automatic derivatives. That's an intermediate strategy,
  which calculates the analytic derivative numerically
  by applying the chain rule implicitly. It works for all
  functions that can be written in terms of a set of elementary
  functions whose derivatives are known analytically.
  For an implementation, see
    http://starship.skyport.net/crew/hinsen/Derivatives.py
  (that's in Python as well).
-- 
-------------------------------------------------------------------------------
Konrad Hinsen                            | E-Mail: [email-masked]
Centre de Biophysique Moleculaire (CNRS) | Tel.: +33-2.38.25.55.69
Rue Charles Sadron                       | Fax:  +33-2.38.63.15.17
45071 Orleans Cedex 2                    | Deutsch/Esperanto/English/
France                                   | Nederlands/Francais
-------------------------------------------------------------------------------