Skip to content

Instantly share code, notes, and snippets.

@ghorn
Created July 17, 2014 12:13
Show Gist options
  • Save ghorn/3f67c0e6549e3c533621 to your computer and use it in GitHub Desktop.
Save ghorn/3f67c0e6549e3c533621 to your computer and use it in GitHub Desktop.
from casadi import *
x0 = MX.sym('x',10,1);
u = MX.sym('u',10,1);
f = MXFunction([x0,u],[x0])
f.setOption('name','f')
f.init()
h = MX.sym('h',1,1);
h2 = h/2
k1 = h*f.call([x0, u])[0]
k2 = h*f.call([x0 + k1/2, u])[0]
k3 = h*f.call([x0 + k2/2, u])[0]
k4 = h*f.call([x0 + k3, u])[0]
x1 = x0 + (k1 + 2*k2 + 2*k3 + k4)/6
rk4 = MXFunction([x0,u,h],[x1])
f.setOption('name','rk4')
rk4.init()
print rk4
print "="*80
rk4j = rk4.jacobian()
rk4j.init()
print rk4j
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment