Skip to content

Commit d4eac34

Browse files
a bit more docs
1 parent 67d0839 commit d4eac34

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

docs/src/IR.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,15 @@ of the differentials down to basic one-variable expressions.
5050
Differential
5151
expand_derivatives
5252
ModelingToolkit.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

5664
There is a large amount of derivatives pre-defined by

src/direct.jl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,37 @@
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+
"""
19
function 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
412
end
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+
"""
622
function 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
925
end
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+
"""
1135
function 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

0 commit comments

Comments
 (0)