Skip to content

Instantly share code, notes, and snippets.

View jgillis's full-sized avatar

Joris Gillis jgillis

View GitHub Profile
@jgillis
jgillis / sparse.py
Last active August 10, 2016 10:05
Hand code a sparse matrix in an easy way
n = np.nan
A = DM([[2, 3, n, n, n],
[3, 0, 4, n, 6],
[n, 4, 1, 5, n],
[n, n, 5, 0, n],
[n, 6, n, n, 1]])
A = A[sparsify(A==A).sparsity()]
@jgillis
jgillis / pdfrecord.py
Created October 1, 2016 19:22
pdf recorder
import wx
import sys
import wx.lib.wxcairo as wxcairo
import poppler
W = 640
H = 480
class PDFWindow(wx.Window):
def __init__(self, parent, document):
wx.Window.__init__(self, parent, wx.ID_ANY)
@jgillis
jgillis / interp1 with SX
Last active October 4, 2017 07:16
Bspline interpolation
from casadi import *
import pylab as plt
# ====================================
# Data to be interpolated
#
# =====================================
N = 20
import sys
import re
import os
import fnmatch
subs = [
(r"""#if defined\(OS_LINUX\)
\s*\.type (\w*), @function
def jacobian_trick(e,p):
Af = MXFunction("Af",[],[jacobian(e, p)])
bf = MXFunction("bf",[p],[e])
A = Af([])[0]
b = bf([0])[0]
return reshape(mul(A, p), e.shape)+b
from casadi import *
from os import system
from casadi import *
x=SX.sym("x",4,1)
y=SX.sym("y")
z = vertcat(sin(x[0]*y),cos(x[1]*sqrt(y)-x[2]),x[3])
f = Function('f',[x,y],[z])
@jgillis
jgillis / data.mat
Last active April 22, 2017 15:31
parameter estimation exercise
1.0000000000000000e+01 1.0000000000000001e-01
1.0666666666666668e+01 1.0989010989010992e-01
1.1235358048544862e+01 1.2221002561287966e-01
1.1701859220591565e+01 1.3728271770477346e-01
1.2066998116159821e+01 1.5547027283854981e-01
1.2334965535516069e+01 1.7716899023142940e-01
1.2511742313862481e+01 2.0280025980514024e-01
1.2603862495569533e+01 2.3279581514402420e-01
1.2617588856146511e+01 2.6757585710433329e-01
1.2558478671677529e+01 3.0751866873574418e-01
classdef SwigRef < handle
properties(Hidden = true, Access = public)
swigPtr
end
methods(Static = true, Access = protected)
function obj = Null()
persistent obj_null
if isempty(obj_null)
obj_null = SwigRef();
end
from casadi import *
x = SX.sym("x",2)
p = SX.sym("p")
f = sin(x[0]*x[1]*p)
g = cos(x[0]/x[1]*sum1(x)*p)
nlp = {"x":x,"p":p,"f":f,"g":g}
@jgillis
jgillis / tips.md
Created October 8, 2017 08:34
Exploring codegen files

Limit line length:cut -c -80 file.c

Match headers: grep -n "^/\*" file.c