First derivative can be calculated by the complex-step derivative formula:


Generalization of the above for calculating derivatives of any order employs multicomplex numbers, resulting in multicomplex derivatives:


According to the Wiki Complex-variable methods:

enter image description here

In Matlab, the calculation of the first order derivative is very easy to implement:

hold on

I do not understand how to implement the calculation of the second order derivative, because I do not understand what is $i^{(1)},i^{(2)}...i^{(n)}$ and how the operator $C^{(n)}_{n^2-1}$ is calculated.

EDIT: Here is the program for the second order derivative, which is calculated incorrectly. I don't understand how to use $Imag_{12}$

df = imag((imx1).^2)./h;
ddf = imag((imx2).^2)./h^2;
  • $\begingroup$ ancs.eng.buffalo.edu/pdf/ancs_papers/2008/complex_step08.pdf In this article, I found the formula ((8), page 4), but did not understand the relationship with the formula from Wikipedia. $\endgroup$
    – dtn
    Aug 8, 2022 at 3:36
  • $\begingroup$ The formula from this article for the 2nd derivative works. $\endgroup$
    – dtn
    Aug 8, 2022 at 3:45
  • 1
    $\begingroup$ Use truncated Taylor expansions. The propagation of those through elementary functions and operations is well-known. The complex-step derivative is just an approximation of dual numbers or linear Taylor expansions. $\endgroup$ Aug 8, 2022 at 4:36
  • $\begingroup$ @LutzLehmann This approach works, but it fails when searching for the 3rd order derivative, because its calculation requires the difference between the approximate and exact value of the first order derivative. $\endgroup$
    – dtn
    Aug 8, 2022 at 6:43
  • 1
    $\begingroup$ That article is "sour grapes", a la "I do not understand Taylor propagation, thus it is incredibly hard". In the context of AD, Taylor propagation is as complicated as dual numbers, aka first derivatives forward differentiation. Mixed higher derivatives will always be complicated, there is a trade-off of huge memory footprints vs. numerical stability. The multi-complex case falls into the huge memory footprint direction, similar to the cross-derivatives approach I was once working at. There is a middle region of derivatives in 2 to 3 directions where both approaches work equally well. $\endgroup$ Aug 8, 2022 at 10:40

1 Answer 1


$ \def\bbR#1{{\mathbb R}^{#1}} \def\LR#1{\left(#1\right)} \def\m#1{\left[\begin{array}{r}#1\end{array}\right]} $Since you're using Matlab, a simpler approach is to create a Jordan block matrix $$\eqalign{ &J = (xI + N) \; \in\,\bbR{n\times n} \\ &N^n = 0 \qquad \big\{{\rm nilpotent}\big\} }$$ Have Matlab evaluate the function using this matrix as its argument, and since $$f(J) = \sum_{k=0}^{n-1}\frac{N^k\,f^{(k)}(x)}{k!}$$ the $k^{th}$ derivative can be read off of the $k^{th}$ superdiagonal of the result for $\,1\le k<n$


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .