Compressed Differentiation
Differentiating a function of many variables a large number of times can be very slow and memory consuming. The Matlab function jacobian.m differentiates symbolic functions, but it does so without exploiting the sparse structure of the derivatives (how many nonzero derivatives there are), and the symmetry of mixed derivatives.
The new function compderivs.m performs the differentiation in a compressed manner. With each differentiation, only the nonzero unique derivatives are differentiated. The function returns compressed vectors (collected in a cell array) that contain only the nonzero unique derivatives, and matrices (collected in a cell array) that uncompress the compressed vectors.
A test file shows that compderivs.m is faster than using jacobian.m iteratively, especially if one has to evaluate the symbolic derivatives numerically. Also, memory consumption is much lower, because only the nonzero unique derivatives are stored.
Details are provided in the paper Levintal, Oren, "Fifth Order Perturbation Solution to DSGE Models".
Cite As
Oren (2024). Compressed Differentiation (https://www.mathworks.com/matlabcentral/fileexchange/48035-compressed-differentiation), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
Tags
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.3.0.0 | Sub function create_UW changed. The change does not affect the output of compderivs, but may resolve future incompatibility problems. |
||
1.2.0.0 | The function logical is used to detect zeros of symbolic variables. |
||
1.1.0.0 | The subfunction create_UW is included in the main function. |
||
1.0.0.0 |