integrators/simulator.py

This example looks at a use for the Simulator class

View output (PDF) | source (python)

See also
Function object.
Definition: function.hpp:60
1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 from casadi import *
28 from numpy import *
29 from pylab import *
30 
31 
32 
33 
34 
35 t = SX.sym('t')
36 
37 u = SX.sym('u')
38 v = SX.sym('v')
39 states = vertcat(u,v)
40 
41 eps = SX.sym('eps')
42 mu = SX.sym('mu')
43 alpha = SX.sym('alpha')
44 k = SX.sym('k')
45 sigma = SX.sym('sigma')
46 Omega = 2 + eps*sigma
47 
48 params = vertcat(eps,mu,alpha,k,sigma)
49 rhs = vertcat(v,-u-eps*(2*mu*v+alpha*u**3+2*k*u*cos(Omega*t)))
50 
51 
52 
53 dae={'x':states, 'p':params, 't':t, 'ode':rhs}
54 ts = linspace(0, 50, 1000)
55 integrator = integrator('integrator', 'cvodes', dae, {'grid':ts, 'output_t0':True})
56 
57 sol = integrator(x0=[1,0], p=[0.1,0.1,0.1,0.3,0.1])
58 
59 
60 
61 plot(array(sol['xf'])[0,:], array(sol['xf'])[1,:])
62 xlabel('u')
63 ylabel('u_dot')
64 show()
65 
CASADI_EXPORT Function integrator(const std::string &name, const std::string &solver, const SXDict &dae, const Dict &opts=Dict())