What is the "best" product rule for finite difference computations?

839 Views Asked by At

I am currently writing a code for physics modeling, and in it I am computing (spatial) derivatives of some functions, but most importantly : derivatives of products (and quotients) of functions.

In order to compute first order derivatives I use the central difference method : $$f^\prime (i) \simeq \frac{f(i+1)-f(i-1)}{2\Delta x}$$

We all know the product rule $(fg)^\prime = f^\prime g + f g^\prime$, however, applying the finite difference to the left hand side or the right-hand side we will get very different results : $$2\Delta x \times (fg)^\prime = f(i+1)g(i+1) - f(i-1)g(i-1)$$ or $$2\Delta x \times (f^\prime g + f g^\prime) = (f(i+1)-f(i-1)) g(i) + f(i) (g(i+1)-g(i-1))$$

(similar topic : Product rule in discrete derivative in finite difference scheme. )

After reading Numerical differentiation and the product rule , I did understand that both methods are correct, and my guess is that the error obtained from one method or the other is simply different.

However, my questions are : is one or the other is better ? Are there situations where one or the other is better ? Are there any criteria that can tell me which one should I use ? Or should I choose the one I prefer the most, and stick to it ?

Thank you in advance.

1

There are 1 best solutions below

1
On

Having been facing this kind of problems for products and quotients including powers, what I did is the following based on logarithmic differentiation $$h(x)=\prod_{i=1}^n\big[f_i(x)\big]^{a_i} \implies \log(h(x))=\sum_{i=1}^n a_i\log\big[f_i(x)\big]$$ $$\frac {h'(x)}{h(x)}=\sum_{i=1}^n a_i\frac{f_i'(x)}{f_i(x)}\implies {h'(x)}=\Big[ \sum_{i=1}^n a_i\frac{f_i'(x)}{f_i(x)}\Big]\,h(x)$$

In $1997$, in the frame of the Automatic Differentiation Cape Open project, this was extensively tested and approved.