Skip to content

Instantly share code, notes, and snippets.

View jgillis's full-sized avatar

Joris Gillis jgillis

View GitHub Profile
@jgillis
jgillis / cla.md
Created January 20, 2026 11:57
lacemodelica_cla

Contributor License Agreement

Thank you for your interest in contributing to LaceModelica ("Project"), maintained by YACODA.

By submitting a pull request or otherwise contributing to this Project, you agree to the following terms.

@jgillis
jgillis / sympy2casadi
Last active August 18, 2025 10:56
Convert sympy expression to CasADi
def sympy2casadi(sympy_expr,sympy_var,casadi_var):
import casadi
assert casadi_var.is_vector()
if casadi_var.shape[1]>1:
casadi_var = casadi_var.T
casadi_var = casadi.vertsplit(casadi_var)
from sympy.utilities.lambdify import lambdify
mapping = {'ImmutableDenseMatrix': casadi.blockcat,
'MutableDenseMatrix': casadi.blockcat,
@jgillis
jgillis / debug_fatrop.m
Last active November 16, 2024 20:24
Fatrop debugging tools
% Load the matrices from files
actual = casadi.Sparsity.from_file('debug_fatrop_actual.mtx');
A = casadi.Sparsity.from_file('debug_fatrop_A.mtx');
B = casadi.Sparsity.from_file('debug_fatrop_B.mtx');
C = casadi.Sparsity.from_file('debug_fatrop_C.mtx');
D = casadi.Sparsity.from_file('debug_fatrop_D.mtx');
I = casadi.Sparsity.from_file('debug_fatrop_I.mtx');
errors = row(casadi.Sparsity.from_file('debug_fatrop_errors.mtx'));
% Create a new figure
Contributor's Statement of Intellectual Property Transfer
I certify that:
(a) I have read and understood the statement below on Ownership and Transfer of Intellectual Property;
(b) for any contribution I make to the CasADi project, I will make all reasonable efforts to determine the legal owners of the contribution, and I will obtain the permission of the owners of the contribution to make the contribution available under the terms of this agreement;
(c) if I am employed, I have discussed contributing to CasADi with my employer and have obtained their permission to transfer the intellectual property rights or have determined that they do not assert ownership rights to my contributions;
(d) I hereby transfer and assign all rights, title, and interest, including all intellectual property rights, in any contributions that I make to the CasADi project, to the CasADi copyright holders;
(e) I will not knowingly submit any contribution of which I am not the owner or for which I do not have the owner's permission, n
from casadi import *
# Example on how to use the DaeBuilder class
# Joel Andersson, UW Madison 2017
# Start with an empty DaeBuilder instance
dae = DaeBuilder('rocket')
# Add input expressions
/* This file was automatically generated by CasADi 3.6.5+.
* It consists of:
* 1) content generated by CasADi runtime: not copyrighted
* 2) template code copied from CasADi source: permissively licensed (MIT-0)
* 3) user code: owned by the user
*
*/
#ifdef __cplusplus
extern "C" {
#endif
@jgillis
jgillis / scalable.py
Last active April 2, 2024 10:11
bspline fitting
from casadi import *
# Generate 3D data to fit
x = np.linspace(0,2,10)
y = np.linspace(2,4,10)
z = np.linspace(3,5,10)
[X,Y,Z] = np.meshgrid(x,y,z)
xyz_flat = np.vstack((X.ravel(),Y.ravel(),Z.ravel())).T
@jgillis
jgillis / qp_casadi.m
Created December 6, 2018 11:57
Drop-in CasADi replacement for quadprog
function [x, lam_a, lam_x, f, stats] = qp_casadi(H,g,A,lba,uba,lb,ub,x0,lam_a0,lam_x0,solver,solver_options)
% QP_CASADI: solves a QP:
%
% min 1/2*x'Hx + g'x
% x subject to lba <= Ax <= uba
% lb <= x <= ub
%
% You may use [] to omit arguments.
%
% Other inputs
@jgillis
jgillis / demo.py
Created November 21, 2023 15:22
is_constraint_added
from casadi import *
opti = Opti()
x = opti.variable(10)
y = opti.variable(10)
opti.subject_to(x>=0)
opti.subject_to(x+y==0)
opti.subject_to(y>=0)
@jgillis
jgillis / outline.py
Last active September 7, 2023 08:16
m = 10 # Limite memory size
x_latest = MX.sym("x_latest",nx)
g_latest = MX.sym("g_latest",nx)
x_prev = MX.sym("x_prev",nx)
g_prev = MX.sym("g_prev",nx)
s_latest = x_latest-x_prev
y_latest = g_latest-g_prev