Skip to content

Commit 7b749a5

Browse files
committed
add simple examples for plot and print in doc
1 parent 243d1da commit 7b749a5

File tree

4 files changed

+62
-2
lines changed

4 files changed

+62
-2
lines changed

.markdownlint.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"MD046": false,
3+
"MD013": false
4+
}

docs/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[deps]
2+
CTParser = "32681960-a1b1-40db-9bff-a1ca817385d1"
23
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
34
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
45
JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"

docs/src/plot.md

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,46 @@ Order = [:module, :constant, :type, :function, :macro]
3838
julia> private_fun(x)
3939
```
4040

41+
## Simple example
42+
43+
```@example
44+
using CTModels, Plots
45+
import CTParser: @def
46+
47+
t0, tf, x0 = 0.0, 1.0, -1.0
48+
49+
ocp = @def begin
50+
t ∈ [t0, tf], time
51+
x ∈ R, state
52+
u ∈ R, control
53+
x(t0) == x0
54+
-Inf ≤ x(t) + u(t) ≤ 0, (mixed_con)
55+
ẋ(t) == u(t)
56+
∫(0.5u(t)^2) → min
57+
end
58+
59+
sol = CTModels.build_solution(
60+
ocp,
61+
collect(range(t0, tf; length=201)),
62+
t -> x0 * exp(-t),
63+
t -> -x0 * exp(-t),
64+
Float64[],
65+
t -> exp(t - tf) - 1;
66+
objective = exp(-1) - 1,
67+
iterations = 0,
68+
constraints_violation = 0.0,
69+
message = "",
70+
status = :optimal,
71+
successful = true,
72+
)
73+
74+
plot(sol)
75+
```
76+
4177
## Documentation
4278

4379
```@autodocs
4480
Modules = [CTModelsPlots]
4581
Order = [:module, :constant, :type, :function, :macro]
4682
Pages = ["plot.jl", "plot_utils.jl", "plot_default.jl", "CTModelsPlots.jl"]
47-
```
83+
```

docs/src/print.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,29 @@ Modules = [CTModels, Base]
88
Order = [:module, :constant, :type, :function, :macro]
99
```
1010

11+
## Simple example
12+
13+
```@example
14+
using CTModels, Plots
15+
import CTParser: @def
16+
17+
t0, tf, x0 = 0.0, 1.0, -1.0
18+
19+
ocp = @def begin
20+
t ∈ [t0, tf], time
21+
x ∈ R, state
22+
u ∈ R, control
23+
x(t0) == x0
24+
-Inf ≤ x(t) + u(t) ≤ 0, (mixed_con)
25+
ẋ(t) == u(t)
26+
∫(0.5u(t)^2) → min
27+
end
28+
```
29+
1130
## Documentation
1231

1332
```@autodocs
1433
Modules = [CTModels]
1534
Order = [:module, :constant, :type, :function, :macro]
1635
Pages = ["print.jl"]
17-
```
36+
```

0 commit comments

Comments
 (0)