File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -62,6 +62,33 @@ function finite_difference{T <: Number}(f::Function,
6262 end
6363end
6464
65+ # #############################################################################
66+ # #
67+ # # Complex Step Finite Differentiation Tools
68+ # #
69+ # # Martins, Sturdza, and Alonso (2003) suggest the only non-analytic
70+ # # fuction of which complex step finite difference approximation
71+ # # will fail and finite difference will not is abs().
72+ # # They suggest redefining as follows for z = x + im*y
73+ # #
74+ # # if x < 0
75+ # # -x - im * y
76+ # # else
77+ # # x + im * y
78+ # #
79+ # # This is provided below as complex_differentiable_abs (renaming encouraged!)
80+ # #
81+ # # Also, if your fuctions has control flow using < or >, you must compare
82+ # # real(z) for your control flow.
83+ # #
84+ # #############################################################################
85+
86+ function complex_differentiable_abs {T <: Complex} (z:: T )
87+ if real (z) < 0
88+ return - real (z) - im * imag (z)
89+ else
90+ return real (z) + im * imag (z)
91+
6592# #############################################################################
6693# #
6794# # Gradient of f: R^n -> R
You can’t perform that action at this time.
0 commit comments