$f^{(n)}(z) \approx \frac{n!}{mr } \sum_{j=0}^{m-1} \frac{f( z+re^{i\frac{2\pi j}{m}} )}{e^{i\frac{2\pi j n }{m}} }$ did not work for $n\geq 2$

41 Views Asked by At

In Eq. 17 of the paper, $$ f^{(n)}(z) =\frac{n!}{2\pi i} \int_\Gamma \frac{f(\epsilon)}{(\epsilon -z)^{n+1}} d\epsilon $$ can be approximated as $$ f^{(n)}(z) \approx \frac{n!}{mr } \sum_{j=0}^{m-1} \frac{f( z+re^{i\frac{2\pi j}{m}} )}{e^{i\frac{2\pi j n }{m}} } $$

I tried it out, for the first order derivative $n=1$

-0.0998334166468281578301968678586166
-0.0998334166468281578301968678586166+ 2.15881442577989072945968065863562208-156j

the result from the finite difference agreed with the complex contour method. However, for the higher order derivative, the complex contour method failed,

n=2
-0.995004165
-0.009950041- 2.9820389126-156j

n=3
0.099833416
0.000009983- 1.281060154-155j

where the code was

def numerical_derivative_contour(f, x, n=1, h=mp.mpf("1e-6")):

    if n == 0:
        return f(x)
    else:
        output=0
        mx=1000
        for jx in range(0,mx):
            output=output+f(x+ h* mp.exp(mp.mpc(0,1)*2*mp.pi*jx/mx) )/mp.exp(mp.mpc(0,1)*2*mp.pi*jx*n/mx)
            
        output=(mp.factorial(n)/mx/h )*output
        return output

What's wrong with the approximation?

1

There are 1 best solutions below

0
On

\begin{equation} f^{(n)}(z) =\frac{n!}{2\pi i} \int_\Gamma \frac{f(\epsilon)}{(\epsilon -z)^{n+1}} d\epsilon \end{equation}

\begin{equation} \begin{split} f^{(n)}(z) &=\frac{n!}{2\pi i} \int_\Gamma \frac{f(\epsilon)}{(\epsilon -z)^{n+1}} d\epsilon\\ &=\frac{n!}{2\pi i} \int_0^1 \frac{f(z+re^{2\pi i x})}{(z+re^{2\pi i x} -z)^{n+1}} \frac{d z+re^{2\pi i x}}{dx} dx\\ &=\frac{n!}{2\pi i} \int_0^1 \frac{f(z+re^{2\pi i x})}{(re^{2\pi i x})^{n+1}} 2\pi i re^{2\pi i x} dx\\ &=\frac{n!}{r^n} \int_0^1 \frac{f(z+re^{2\pi i x})}{(e^{2\pi i x})^{n}} dx\\ \end{split} \end{equation}

Thus, \begin{equation} f^{(n)}(z) \approx \frac{n!}{mr^n } \sum_{j=0}^{m-1} \frac{f( z+re^{i\frac{2\pi j}{m}} )}{e^{i\frac{2\pi j n }{m}} } \end{equation} (Dr. Robbins)

There was a small typo on the order of $r$. I didn't notice it at first glance either, too fixated at the phase.