# ModelingToolkit Nonlinear Optimal Control

I ran the example nonlinear optimal control problem in the documentation, reproduced below:

``````using ModelingToolkit

@variables t x(t) v(t) u(t)
@parameters p[1:2]
D = Differential(t)

loss = (4-x)^2 + 2v^2 + u^2
eqs = [
D(x) ~ v - p*x
D(v) ~ p*u^3 + v
]

@named sys = ControlSystem(loss,eqs,t,[x,v],[u],p)

dt = 0.1
tspan = (0.0,1.0)
sys = runge_kutta_discretize(sys,dt,tspan)

u0 = rand(length(states(sys))) # guess for the state values

using GalacticOptim, Optim
sol = solve(prob,BFGS())
``````

My question is now how do we interpret the solution?

The solution is a 142 element vector. I am guessing it contains all the information required, including values of state variables at the discretized time points, values of the control variable in the time elements, and possible some values related to the collocation nodes. However I am unable to deconstruct and extract this information. Any information on how to interpret and extract the state and control variable values at various time points will be welcome.