Skip to content

Instantly share code, notes, and snippets.

@jaeandersson
Created June 1, 2017 22:21
Show Gist options
  • Save jaeandersson/1224b1c3ac09b137809b5ac4887ea092 to your computer and use it in GitHub Desktop.
Save jaeandersson/1224b1c3ac09b137809b5ac4887ea092 to your computer and use it in GitHub Desktop.
Modified rocket example, with local variable
# Modified version of the rocket example in Section 7.2 of the CasADi v3.2 User Guide
# Cf. http://guide.casadi.org/
from casadi import *
dae = DaeBuilder()
# Add input expressions
a = dae.add_p('a')
b = dae.add_p('b')
u = dae.add_u('u')
h = dae.add_x('h')
v = dae.add_x('v')
m = dae.add_x('m')
# MODIFICATION: Define a local variable
air_resistance = dae.add_w(a*v**2, 'air_resistance')
# Add output expressions
hdot = v
vdot = (u-air_resistance)/m-g
mdot = -b*u**2
dae.add_ode(hdot)
dae.add_ode(vdot)
dae.add_ode(mdot)
# Specify initial conditions
dae.set_start('h', 0)
dae.set_start('v', 0)
dae.set_start('m', 1)
# Add meta information
dae.set_unit('h','m')
dae.set_unit('v','m/s')
dae.set_unit('m','kg')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment