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.* | |
% In this example, we fit a nonlinear model to measurements | |
% | |
% This example uses more advanced constructs than the vdp* examples: | |
% Since the number of control intervals is potentially very large here, | |
% we use memory-efficient Map and MapAccum, in combination with | |
% codegeneration. | |
% | |
% We will be working with a 2-norm objective: |
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
#!/usr/bin/python | |
import sys | |
import hashlib | |
import subprocess | |
import shutil | |
import os | |
args = sys.argv[1:] | |
cachedir = ".cache" |
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
casadi2matlabfun =@(F,castfun) @(varargin) subsref(cellfun(castfun,F(varargin),'UniformOutput',false),struct('type','{}','subs',{{':'}})); | |
Hf = casadi2matlabfun(H,@full) |
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 [out] = casadi_struct2vec(s) | |
flat = {}; | |
if isstruct(s) | |
for f=fieldnames(s)' | |
flat = {flat{:} casadi_struct2vec(s.(f{1}))}; | |
end | |
out = vertcat(flat{:}); | |
else if iscell(s) | |
for i=1:length(s) | |
flat = {flat{:} casadi_struct2vec(s{i})}; |
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 PSDchecker < casadi.Callback2 | |
properties | |
n | |
fwd | |
adj | |
end | |
methods | |
function self = PSDchecker(n) | |
self.n = n; | |
self.fwd = mydergen(n,true); |
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 functools import partial | |
class Infix(object): | |
def __init__(self, func): | |
self.func = func | |
def __or__(self, other): | |
return self.func(other) | |
def __ror__(self, other): | |
return Infix(partial(self.func, other)) | |
def __call__(self, v1, v2): |
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
function ret = classify_linear(e,v) | |
% | |
% Takes vector expression e, and symbolic primitives v | |
% Returns classification vector | |
% For each element in e, determines if: | |
% - element is nonlinear in v (2) | |
% - element is linear in v (1) | |
% - element does not depend on v at all (0) | |
% | |
% This method can be sped up a lot with JacSparsityTraits::sp |
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 * | |
H = DM([[1,-1],[-1,2]]) | |
G = DM([-2,-6]) | |
A = DM([[1, 1],[-1, 2],[2, 1]]) | |
LBA = DM([-inf]*3) | |
UBA = DM([2, 2, 3]) | |
LBX = DM([0]*2) |
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 | |
%FUNCTION 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 |