In [1]:
%load_ext autoreload
%autoreload 2
%matplotlib inline
import sys
import pylab as pl
sys.path.insert(0, '..')
import pymoca.parser
import pymoca.backends.sympy.generator as generator
import pylab as pl
In [2]:
ast = pymoca.parser.parse('''
model Aircraft
parameter Real c = 0.1;
Real x(start=10);
Real y(start=100);
equation
der(x) = -x + y;
der(y) = -c*y;
end Aircraft;
''')
In [3]:
src = generator.generate(ast, 'Aircraft')
print(src)
In [4]:
exec(src)
ac = Aircraft()
res = ac.simulate()
res
Out[4]:
In [5]:
pl.plot(res['t'], res['x'])
Out[5]:
In [6]:
ss = ac.linearize()
ss[0]
Out[6]:
In [7]:
ac.linearize_symbolic()
Out[7]:
In [8]:
pl.matrix(ss[0]).astype(float)
Out[8]: