Skip to content

Instantly share code, notes, and snippets.

@higham
Created April 21, 2018 12:58
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save higham/5c32cce0532ed5c863615d588548518d to your computer and use it in GitHub Desktop.
Complex step approximation to derivative.
function fd = complex_step(f,x,h)
%COMPLEX_STEP Complex step approximation to derivative.
% fd = COMPLEX_STEP(f,x,h) computes the complex step approximation
% fd to the derivative of f at x, using step h (default 1e-100).
if nargin < 3, h = 1e-100; end
fd = imag( f(x + sqrt(-1)*h) )/h;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment