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
To get the time grid, state, control, and costate, but also to retrieve the number of iterations and the objective value, OptimalControlProblems provides the following getters:
123
123
124
124
```@example main
125
-
t = time_grid(:beam, nlp) # t0, ..., tN = tf
126
-
x = state(:beam, nlp) # function of time
127
-
u = control(:beam, nlp) # function of time
128
-
p = costate(:beam, nlp) # function of time
129
-
o = objective(:beam, nlp) # scalar objective value
130
-
i = iterations(:beam, nlp) # number of iteration
125
+
t = time_grid(nlp) # t0, ..., tN = tf
126
+
x = state(nlp) # function of time
127
+
u = control(nlp) # function of time
128
+
p = costate(nlp) # function of time
129
+
o = objective(nlp) # scalar objective value
130
+
i = iterations(nlp) # number of iteration
131
131
132
132
tf = t[end]
133
133
println("tf = ", tf)
@@ -142,14 +142,14 @@ println("iterations: ", i)
142
142
If the `problem` includes additional optimisation variables, such as the final time, you can retrieve them with:
143
143
144
144
```julia
145
-
v = variable(problem, nlp)
145
+
v = variable(nlp)
146
146
```
147
147
148
148
Now, we can add the state, costate, and control to the plot:
149
149
150
150
```@example main
151
-
n = length(metadata(:beam)[:state_components]) # dimension of the state
152
-
m = length(metadata(:beam)[:control_components]) # dimension of the control
151
+
n = state_dimension(nlp)
152
+
m = control_dimension(nlp)
153
153
154
154
for i in 1:n # state
155
155
plot!(plt[i], t, t -> x(t)[i]; color=2, linestyle=:dash, label=:none)
0 commit comments