This file contains hidden or 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
import numpy as np | |
import casadi as ca | |
from numpy import exp,pi | |
def ode(): | |
# Plant parameter values | |
T0 = 350 # K | |
c0 = 1 # kmol/m^3 |
This file contains hidden or 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
from casadi import * |
This file contains hidden or 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
package CSTR | |
model CSTR "A CSTR" | |
parameter Modelica.SIunits.VolumeFlowRate F0=100/1000/60 "Inflow"; | |
parameter Modelica.SIunits.Concentration c0=1000 "Concentration of inflow"; | |
Modelica.Blocks.Interfaces.RealInput Tc "Cooling temperature"; | |
parameter Modelica.SIunits.VolumeFlowRate F=100/1000/60 "Outflow"; | |
parameter Modelica.SIunits.Temp_K T0 = 350; | |
parameter Modelica.SIunits.Length r = 0.219; |
This file contains hidden or 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
from casadi import * | |
from casadi.tools import * | |
from plotter import * | |
from pylab import * | |
""" | |
NOTE: if you use spyder, | |
make sure you open a Python interpreter | |
instead of an IPython interpreter | |
otherwise you wont see any plots |
This file contains hidden or 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
import numpy as NP | |
from casadi import * | |
# Choose collocation points | |
d = 4 # Degree | |
tau_root = collocationPoints(d,"legendre") | |
# Calculate coefficients | |
C = DMatrix.nan(d+1,d+1) # For the collocation equation | |
D = DMatrix.nan(d+1) # For the continuity equation |
This file contains hidden or 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
from casadi import * | |
from casadi.tools import * | |
import numpy | |
from numpy import cos,sin, vstack, hstack, multiply | |
class Quadcopter: | |
""" | |
Quadcopter model |
This file contains hidden or 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
#import casadi | |
import numpy | |
from casadi import * | |
# Initial and final position | |
px0 = 0.0; py0 = 1.5 | |
pxF = 20.0; pyF = 0.0 | |
# Time horizon and discretization | |
T = 3.0 |
This file contains hidden or 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
from casadi import * | |
from numpy import * | |
import matplotlib.pyplot as plt | |
N = 20 # Control discretization | |
T = 10.0 # End time | |
# Declare variables (use scalar graph) | |
u = SX.sym("u") # control | |
x = SX.sym("x",2) # states |
This file contains hidden or 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
from casadi import * | |
from numpy import * | |
import matplotlib.pyplot as plt | |
N = 20 # Control discretization | |
T = 10.0 # End time | |
# Declare variables (use scalar graph) | |
u = SX.sym("u") # control | |
x = SX.sym("x",2) # states |
This file contains hidden or 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
from pylab import * | |
# End time | |
T = 10. | |
# Number of control intervals | |
N = 20 | |
# Number of Runge-Kutta 4 steps per interval and step size | |
NK = 20 |