You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/tutorials/symbolic_functions.md
+13-11Lines changed: 13 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,17 +7,15 @@ The way to define symbolic variables is via the `@variables` macro:
7
7
@variables x y
8
8
```
9
9
10
-
After defining variables as symbolic, symbolic expressions, which we
11
-
call a `Term`, can be generated by utilizing Julia expressions.
12
-
For example:
10
+
After defining variables as symbolic, symbolic expressions, which we call a
11
+
`istree` object, can be generated by utilizing Julia expressions. For example:
13
12
14
13
```julia
15
14
z = x^2+ y
16
15
```
17
16
18
-
Here, `z` is the `Term` for "square `x` and add `y`". To
19
-
make an array of symbolic expressions, simply make an array of
20
-
symbolic expressions:
17
+
Here, `z` is an expression tree for "square `x` and add `y`". To make an array
18
+
of symbolic expressions, simply make an array of symbolic expressions:
21
19
22
20
```julia
23
21
A = [x^2+y 02x
@@ -30,7 +28,10 @@ A = [x^2+y 0 2x
30
28
y ^2+ x 00
31
29
```
32
30
33
-
Note that by default, `@variables` returns `Sym` or `Term` objects wrapped in `Num` in order to make them behave like subtypes of `Real`. Any operation on these `Num` objects will return a new `Num` object, wrapping the result of computing symbolically on the underlying values.
31
+
Note that by default, `@variables` returns `Sym` or `istree` objects wrapped in
32
+
`Num` in order to make them behave like subtypes of `Real`. Any operation on
33
+
these `Num` objects will return a new `Num` object, wrapping the result of
34
+
computing symbolically on the underlying values.
34
35
35
36
To better view the results, we can use [Latexify.jl](https://github.com/korsbo/Latexify.jl).
36
37
ModelingToolkit.jl comes with Latexify recipes so it works automatically:
@@ -282,11 +283,11 @@ sufficiently large!)
282
283
One common thing to compute in a symbolic system is derivatives. In
283
284
ModelingToolkit.jl, derivatives are represented lazily via operations,
284
285
just like any other function. To build a differential operator, use
285
-
`@derivatives` like:
286
+
`Differential` like:
286
287
287
288
```julia
288
289
@variables t
289
-
@derivatives D'~t
290
+
Differential(t)
290
291
```
291
292
292
293
This is the differential operator ``D = \frac{\partial}{\partial t}``: the number of
@@ -450,7 +451,7 @@ z = g(x) + g(y)
450
451
451
452
One of the benefits of a one-language Julia symbolic stack is that the
452
453
primitives are all written in Julia, and therefore it's trivially
453
-
extendable from Julia itself. By default, new functions are traced
454
+
extendible from Julia itself. By default, new functions are traced
454
455
to the primitives and the symbolic expressions are written on the
455
456
primitives. However, we can expand the allowed primitives by registering
456
457
new functions. For example, let's register a new function `h`:
0 commit comments