Automatic Differentiation with Matlab Objects

Automatically compute derivatives of functions, without using finite-difference approximations.
3.1K Downloads
Updated 29 Mar 2011

View License

Automatic differentiation is a technique for computing the derivatives of a function using the chain rule. Matlab objects make it easy to implement automatic differentiation. Note that this package is implemented in a rather old version of Matlab. You may need to edit it for newer versions.

An example of using automatic differentiation to compute the value and derivative of the Rosenbrock function at the point [1,2] is as follows:

x=adiff([1,2]); % create the automatic differentiation object at [1,2]
rosen = 100*(x(1)^2-x(2))^2+(x(1)-1)^2; % compute rosenbrock func.
[x,dx] = adiffget(x); % retrieve the value x and derivative dx

Then x = 100 and dx = [-400,200].

The adiff object includes a helper function to convert any optimization without derivatives into one with derivatives. For example, if you have a function f which you wish to optimize, but it doesn't compute derivatives, it is usually enough to call

fminunc('autodiff',x0,options,'f',...)

The zip file includes a pdf help file.

Cite As

William McIlhagga (2024). Automatic Differentiation with Matlab Objects (https://www.mathworks.com/matlabcentral/fileexchange/26807-automatic-differentiation-with-matlab-objects), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R11.1
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Systems of Nonlinear Equations in Help Center and MATLAB Answers

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.4.0.0

Changed code & documentation to fix problem noted by Dan.

1.1.0.0

Minor bug fix to atan function

1.0.0.0