automaticdifferentiation
Version 1.0.0 (3,13 ko) par
David Codony
Computes the differentiation of a function handle with respect to specified variables at queried points
automaticdifferentiation
Computes the differentiation of a function handle with respect to specified variables at provided points. It makes use of the built-in automatic differentiation (AD) framework of Matlab's Deep Learning Toolbox.
Calls
df = automaticdifferentiation(f,x,n);
df = automaticdifferentiation(f,x,nx,y,ny...);
df = automaticdifferentiation(...,ParallelFlag); % ParallelFlag = true/false
Inputs
f
Function handle. The number of inputs that f admits must match the number of provided Coordinates and Orders of differentiation. Must return a numeric array for each evaluation point.
x, y, ...
Coordinates of the points where derivatives are to be evaluated (numeric arrays of the same size).
nx,ny, ...
Order of differentiation for each variable (non-negative integer scalars).
ParallelFlag
Allow parallel for loops or not (scalar boolean). Optional input, the default is serial for loops.
Outputs:
df
Derivative of f with respect to specified variables, evaluated at the provided points. Numeric array with size equal to the concatenation of the sizes of theCoordinate inputs and the output of f, without singleton dimensions.
Note: The evaluation of the function f is not vectorized. Instead, a serial or parallel for loop is executed for each evaluation point. Therefore, f does not need to be defined using point-wise operators.
Examples
Scalar field in R2
x = 0:0.01:0.1;
y = 0:0.01:0.2;
[xx,yy] = meshgrid(x,y);
f = @(x,y) sin(2*pi*x.*y)+ y.^2; figure; surf(xx,yy,f(xx,yy));
dfdx = automaticdifferentiation(f,xx,1,yy,0); figure; surf(xx,yy,dfdx);
d2fdx2 = automaticdifferentiation(f,xx,2,yy,0); figure; surf(xx,yy,d2fdx2);
d2fdxdy = automaticdifferentiation(f,xx,1,yy,1); figure; surf(xx,yy,d2fdxdy);
Vectorial field in R1
g = @(x) [sin(2*pi.*x), x.*tan(2*pi.*x)]; figure; plot(x,g(x));
dgdx = automaticdifferentiation(g,x,1); figure; plot(x,dgdx(:,1),x,dgdx(:,2));
Citation pour cette source
David Codony (2026). automaticdifferentiation (https://fr.mathworks.com/matlabcentral/fileexchange/129229-automaticdifferentiation), MATLAB Central File Exchange. Extrait(e) le .
Compatibilité avec les versions de MATLAB
Créé avec
R2022b
Compatible avec les versions R2021a et ultérieures
Plateformes compatibles
Windows macOS LinuxTags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Découvrir Live Editor
Créez des scripts avec du code, des résultats et du texte formaté dans un même document exécutable.
| Version | Publié le | Notes de version | |
|---|---|---|---|
| 1.0.0 |
