File Exchange

## Symbolic derivatives

version 1.1.0.0 (7.5 KB) by
Computation of symbolic derivatives without the Symbolic Math Toolbox.

Updated 05 Oct 2016

Entire functionality is accessible via symbderiv() function.
Compatibility:
--------------
Only Matlab BASE is needed, additional toolboxes are not required.
The codes have been tested on M2010b, M2012b, M2016b, M2011A (Mac version)
Installation:
-------------
Main folder containing symbderiv() must be added to the Matlab search path.
Intended use:
--------------
symbderiv('x^2','x') computes the derivative of 'x^2' with respect
to a variable named 'x'. In this case the function returns the expected
result '2*x'. Computation of partial derivatives is straight-forward in that
all variables other than the selected variable are treated as constant.
Therefore, e.g. symbderiv('x*y*z','x') returns y*z.
The input function has to be a string, and the output derivative is also
returned as strings. Standard Matlab function eval() can then be used to
evaluate all computed derivatives numerically at given points.
The symbderiv() function is not suited for the computation of
Jacobians and Hessians directly. One can, however, make use of repeated
calls to symbderiv().

Example :
equations = {'exp(x^2)+y';'sin(x)'};% The system of 2 equations
varlist = {'x','y'}; % List of variables
jac = cell(2,2); % Container for Jacobian
for i = 1:length(equations)
jac(i,:) = symbderiv(equations{i},varlist); % Each Jacobian row as a gradient call
end

Example :
equation = '(x+y)^2';
symbderiv( symbderiv(equation,'x') ,'y') % dF/dxdy -> symbderiv() is simply called twice

Example :
equation = 'x^2';
analderiv = symbderiv(equation,'x');
x = 5; % -> we plan to evaluate the derivative at this point
numderiv = eval(analderiv);

User customization
------------------
The file func_list.m contains definitions of derivatives
for commonly used elementary functions, such as log(), sin(), etc.
This file can be freely expanded with other functions (potentially
user-defined) and their derivatives.

Note
----
The computed symbolic derivatives may look weird at first sight.
E.g. symbderiv('(x+y)^2','x') yields '((2)*(x+y)^(2-1)*(((1))))'
instead of '2*(x+y)'. Simplification rules on top of the computed
result are not applied in order not to slow down the computations.
The consequent numerical evaluation of the computed derivatives
using eval() tends to be rather fast in Matlab even if the underlying
expression contains many nested parentheses and redundant algebraic
operations.

### Cite As

Jakub Rysanek (2021). Symbolic derivatives (https://www.mathworks.com/matlabcentral/fileexchange/59438-symbolic-derivatives), MATLAB Central File Exchange. Retrieved .

##### MATLAB Release Compatibility
Created with R2016b
Compatible with any release
##### Platform Compatibility
Windows macOS Linux