File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -50,7 +50,15 @@ of the differentials down to basic one-variable expressions.
5050Differential
5151expand_derivatives
5252ModelingToolkit.derivative
53+ ModelingToolkit.gradient
54+ ModelingToolkit.jacobian
55+ ModelingToolkit.hessian
5356```
57+
58+ Note that generation of sparse matrices simply follows from the Julian semantics
59+ imbued on the IR, so ` sparse(jac) ` changes a dense Jacobian to a sparse Jacobian
60+ matrix.
61+
5462### Adding Derivatives
5563
5664There is a large amount of derivatives pre-defined by
Original file line number Diff line number Diff line change 1+ """
2+ ```julia
3+ gradient(O::Expression, vars::AbstractVector{<:Expression}; simplify = true)
4+ ```
5+
6+ A helper function for computing the gradient of an expression with respect to
7+ an array of variable expressions.
8+ """
19function gradient (O:: Expression , vars:: AbstractVector{<:Expression} ; simplify = true )
210 out = [expand_derivatives (Differential (v)(O)) for v in vars]
311 simplify ? simplify_constants .(out) : out
412end
513
14+ """
15+ ```julia
16+ jacobian(O::Expression, vars::AbstractVector{<:Expression}; simplify = true)
17+ ```
18+
19+ A helper function for computing the Jacobian of an array of expressions with respect to
20+ an array of variable expressions.
21+ """
622function jacobian (ops:: AbstractVector{<:Expression} , vars:: AbstractVector{<:Expression} ; simplify = true )
723 out = [expand_derivatives (Differential (v)(O)) for O in ops, v in vars]
824 simplify ? simplify_constants .(out) : out
925end
1026
27+ """
28+ ```julia
29+ hessian(O::Expression, vars::AbstractVector{<:Expression}; simplify = true)
30+ ```
31+
32+ A helper function for computing the Hessian of an expression with respect to
33+ an array of variable expressions.
34+ """
1135function hessian (O:: Expression , vars:: AbstractVector{<:Expression} ; simplify = true )
1236 out = [expand_derivatives (Differential (v2)(Differential (v1)(O))) for v1 in vars, v2 in vars]
1337 simplify ? simplify_constants .(out) : out
You can’t perform that action at this time.
0 commit comments