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
classdef dms_gn < handle | |
properties | |
% Symbolic representation of the OCP | |
ocp | |
% OCP data | |
data | |
% Solver options | |
opts | |
% Verbose output | |
verbose |
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
from casadi import * | |
# Simple function: | |
x = SX.sym('x',2) | |
y = SX.sym('f',2) | |
F = Function('F', [x,y],[sin(x)*cos(y), dot(x,y)], ['x','y'], ['f','g']) | |
# Generate code, including derivatives | |
CG = CodeGenerator('F') | |
CG.add(F) |
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') |
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
function varargout = import(varargin) | |
% Import elements from a package | |
% | |
% Cache of aliase | |
persistent imported; | |
% Make sure cell array | |
if ~iscell(imported) | |
imported = cell(0, 1); |
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
function import(varargin) | |
% Import a package. Only entire packages can be imported currently. | |
error(nargchk(1, inf, nargin, 'struct')); | |
% Import the packages one-by-one | |
for i=1:nargin | |
import1(varargin{i}); | |
end | |
end | |
function import1(pkgname) |
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
# Pendulum collocation | |
# w position of cart | |
# w1,y1 position of pendulum | |
import numpy as NP | |
from casadi import * | |
from casadi.tools import * | |
import matplotlib.pyplot as plt | |
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
classdef Function < casadi.SharedObject | |
%General function. | |
% | |
%A general function $f$ in casadi can be multi-input, multi-output. Number of | |
%inputs: nin n_in() Number of outputs: nout n_out() We can view this | |
%function as a being composed of a ( nin, nout) grid of single-input, single- | |
%output primitive functions. Each such primitive function $f_ {i, j} | |
%\\forall i \\in [0, nin-1], j \\in [0, nout-1]$ can map as $\\mathbf | |
%{R}^{n, m}\\to\\mathbf{R}^{p, q}$, in which n, m, p, q can take | |
%different values for every (i, j) pair. When passing input, you specify |
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
from casadi import * | |
# 1D | |
grid = [[0, 1, 2]] | |
values = [0, 1, 2] | |
print "grid = ", grid | |
print "values = ", values | |
F = interpolant('F', 'linear', grid, values) | |
print 'F(2.4) = ', F(2.4) |
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
from casadi import * | |
c = MX.sym('c') | |
x = MX.sym('x') | |
z1 = if_else(c, sin(x), cos(x)) | |
z2 = conditional(c, [sin(x), cos(x)], exp(x)) |
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
import casadi as ca | |
import pylab as pl | |
# [...] | |
# A is of type SX, column vector, shape (788, 1), dense | |
# B is of type sx, column vector, shape (984, 1), dense | |
# V is of type struct_symSX, shape (1594, 1), dense | |
# W is a numpy array, matrix with shape (788, 788), almost diagonal |
NewerOlder