In [1]:
%matplotlib inline
In [2]:
from pylab import *
from optoy import *

x = state()
y = state()
q = state()

u = control()
T = var(lb=0,init=10)

x.dot = (1-y**2)*x-y+u
y.dot = x
q.dot = x**2+y**2

print ocp(T,[u>=-1,u<=1,q.start==0,x.start==1,y.start==0,x.end==0,y.end==0],T=T,N=20)
(1, 1)

******************************************************************************
This program contains Ipopt, a library for large-scale nonlinear optimization.
 Ipopt is released as open source code under the Eclipse Public License (EPL).
         For more information visit http://projects.coin-or.org/Ipopt
******************************************************************************

2.96157509007
In [3]:
print x.sol
[DMatrix(1), DMatrix(0.987388), DMatrix(0.943018), DMatrix(0.858367), DMatrix(0.728705), DMatrix(0.555001), DMatrix(0.343747), DMatrix(0.104317), DMatrix(-0.154994), DMatrix(-0.430419), DMatrix(-0.585801), DMatrix(-0.580591), DMatrix(-0.569645), DMatrix(-0.550801), DMatrix(-0.521654), DMatrix(-0.479655), DMatrix(-0.42228), DMatrix(-0.34723), DMatrix(-0.252625), DMatrix(-0.137136), DMatrix(0)]
In [4]:
plot(x.sol,label='x')
plot(y.sol,label='y')
plot(u.sol,label='u')

ylim([-1.5,1.5])
xlabel("Time step")
title("optimal solution")
legend()
grid(True)
show()
In [ ]: