File Exchange

## Complex step Jacobian

version 1.0 (1.43 KB) by

Calculate Jacobian using complex step differentiation

Updated

Complex step differentiation (CSD) has many advantages in efferency and accuracy over finite difference approaches (central, forward and backward). This code demonstrates how the Jacobian matrix of a given function at the reference point can be calculated using the CSD approach.

Huck Febbo

### Huck Febbo (view profile)

In both this file and the hessian, can you please add functionality to deal with:

K>> [J,z]=jacobiancsd(fun,x)
Error using atan2
Inputs must be real.

http://www.mathworks.com/help/matlab/ref/atan2.html

They talk about improving these methods here:

http://aero-comlab.stanford.edu/Papers/martins.aiaa.01-0921.pdf

Xianzhen

Martin Drozdik

### Martin Drozdik (view profile)

Dear mr. Cao,

Your program is working perfectly. However there are two things I am curious about>
1. Why does the step size depend on the number of independent variables?
2. If we are computing a derivative of a function of one independent variable, and the derivative is for example 0.2, we are faced with the division (0.2eps)/eps. Why does Matlab not evaluate 0.2eps as 0 therefore leading to the incorrect derivative 0?

Thank You in forward

Yi Cao

### Yi Cao (view profile)

Angshul,

eps is the minimal distinguishable vnumer for a particular precision system. For double precision, eps = 2^(-52) and for single precision, eps = 2^(-23). Use "help eps" to find more details.

The complex step differentiation approach can use the minimum step size to get the maximum accuracy. Hence eps is the best step the algorithm can use.

HTH.

Yi

Angshul Majumdar

### Angshul Majumdar (view profile)

the step size 'eps' is not specified? Do U suggest a value?

V. Poor