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)
In [3]:
print x.sol
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 [ ]: