Skip to content

Commit

Permalink
foo
Browse files Browse the repository at this point in the history
  • Loading branch information
ocots committed Oct 5, 2023
1 parent b5e166b commit c7da462
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
4 changes: 4 additions & 0 deletions docs/src/tutorial-init.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Initial guess

```@meta
CurrentModule = OptimalControl
```

We present in this tutorial the different possibilities to provide an initial guess to solve an optimal control problem using the [`solve`](@ref) command. For the illustrations, we define the following optimal control problem.

```@example main
Expand Down
2 changes: 1 addition & 1 deletion docs/src/tutorial-lqr-basic.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,6 @@ pu = plot(plt[5], legend=false, xlabel="s", ylabel="u")
plot(px1, px2, pu, layout=(1, 3), size=(800, 300), leftmargin=5mm, bottommargin=5mm)
```

!!! note
!!! note "Nota bene"

We can observe that $x(t_f)$ converges to the origin as $t_f$ increases.
19 changes: 11 additions & 8 deletions docs/src/tutorial-plot.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Plot a solution

In this tutorial we explain the different ways to plot a solution from an optimal control problem.
In this tutorial we explain the different ways to plot a solution of an optimal control problem.

Let us start by importing the necessary package.

Expand Down Expand Up @@ -35,11 +35,11 @@ plot(sol)

As you can see, it produces a grid of subplots. The left column contains the state trajectories, the right column the costate trajectories, and at the bottom we have the control trajectory.

Attributes from `Plots.jl` can be passed to the `plot` function:
Attributes from [`Plots.jl`](https://docs.juliaplots.org) can be passed to the `plot` function:

- In addition to `sol` you can pass attributes to the full `Plot`, see the [attribute plot documentation](https://docs.juliaplots.org/latest/generated/attributes_plot/) from `Plots.jl` for more details. For instance, you can specify the size of the figure.
- You can also pass attributes to the subplots, see the [attribute subplot documentation](https://docs.juliaplots.org/latest/generated/attributes_subplot/) from `Plots.jl` for more details. However, it will affect all the subplots. For instance, you can specify the location of the legend.
- In the same way, you can pass axis attributes to the subplots, see the [attribute axis documentation](https://docs.juliaplots.org/latest/generated/attributes_axis/) from `Plots.jl` for more details. It will also affect all the subplots. For instance, you can remove the grid.
- In addition to `sol` you can pass attributes to the full `Plot`, see the [attributes plot documentation](https://docs.juliaplots.org/latest/generated/attributes_plot/) from `Plots.jl` for more details. For instance, you can specify the size of the figure.
- You can also pass attributes to the subplots, see the [attributes subplot documentation](https://docs.juliaplots.org/latest/generated/attributes_subplot/) from `Plots.jl` for more details. However, it will affect all the subplots. For instance, you can specify the location of the legend.
- In the same way, you can pass axis attributes to the subplots, see the [attributes axis documentation](https://docs.juliaplots.org/latest/generated/attributes_axis/) from `Plots.jl` for more details. It will also affect all the subplots. For instance, you can remove the grid.

```@example main
plot(sol, size=(700, 450), legend=:bottomright, grid=false)
Expand Down Expand Up @@ -84,11 +84,12 @@ sol2 = solve(ocp, display=false)
nothing # hide
```

We first plot the solution of the first optimal control problem. Then, we plot the solution of the second optimal control problem on the same figure, but with dashed lines.
We first plot the solution of the first optimal control problem, then, we plot the solution of the second optimal control problem on the same figure, but with dashed lines.

```@example main
# first plot
plt = plot(sol, size=(700, 450))
# second plot
style = (linestyle=:dash, )
plot!(plt, sol2, state_style=style, costate_style=style, control_style=style)
Expand Down Expand Up @@ -118,6 +119,8 @@ u = sol.control
plot(t, norm∘u, label="‖u‖")
```

!!! note
!!! note "Nota bene"

The `norm` function is from `LinearAlgebra.jl`. The `∘` operator is the composition operator. Hence, `norm∘u` is equivalent to `t -> norm(u(t))`. The `sol.state`, `sol.costate` and `sol.control` are functions that return the state, costate and control trajectories at a given time.
- The `norm` function is from `LinearAlgebra.jl`.
- The `∘` operator is the composition operator. Hence, `norm∘u` is the function `t -> norm(u(t))`.
- The `sol.state`, `sol.costate` and `sol.control` are functions that return the state, costate and control trajectories at a given time.

0 comments on commit c7da462

Please sign in to comment.