Created
June 1, 2017 22:21
-
-
Save jaeandersson/1224b1c3ac09b137809b5ac4887ea092 to your computer and use it in GitHub Desktop.
Modified rocket example, with local variable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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