Skip to content

Instantly share code, notes, and snippets.

View AunSiro's full-sized avatar

Siro AunSiro

  • Barcelona
View GitHub Profile
@jgillis
jgillis / sympy2casadi
Last active May 6, 2024 19:32
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,
@folkertdev
folkertdev / lagrangePolynomial.py
Created September 27, 2015 14:12
A sympy-based Lagrange polynomial constructor
"""
A sympy-based Lagrange polynomial constructor.
Given a set of function inputs and outputs, the lagrangePolynomial function will construct an
expression that for every input gives the corresponding output. For intermediate values,
the polynomial interpolates (giving varying results based on the shape of your input).
This is useful when the result needs to be used outside of Python, because the
expression can easily be copied. To convert the expression to a python function object,
use sympy.lambdify.
"""