Code Generation for Gradients and Hessians Using Symbolic AD
Version 1.0.0 (42.8 KB) by
Per Bergström
This package provides symbolic automatic differentiation tools for efficient code generation of gradients and Hessians.
This package contains functions for performing symbolic automatic differentiation to efficiently generate code for gradient and Hessian expressions. It relies on Matlab’s Symbolic Math Toolbox, which must be available.
The examples "Example1" and "Example2" demonstrate how the automatic differentiation works, both with and without simplification of expressions. The corresponding scripts "Example1toC" and "Example2toC" show how to generate C code from the resulting expressions. The generated code can then be compiled into executable functions, as illustrated in the scripts "testExampleFun1", "testExampleFun2", and "testExampleFun1Fun2".
A C compiler must be installed for this step, see the Matlab documentation on mex.
There is also support for generating Hessians in sparse matrix format with block structure, demonstrated in "ExampleCameraEstimation1" and "ExampleCameraEstimation2". Generating this code takes longer due to the larger size and complexity of the symbolic expressions.
Cite As
Per Bergström (2025). Code Generation for Gradients and Hessians Using Symbolic AD (https://in.mathworks.com/matlabcentral/fileexchange/180850-code-generation-for-gradients-and-hessians-using-symbolic-ad), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Created with
R2024b
Compatible with any release
Platform Compatibility
Windows macOS LinuxTags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
| Version | Published | Release Notes | |
|---|---|---|---|
| 1.0.0 |
