Skip to content

Instantly share code, notes, and snippets.

@edxmorgan
Last active October 20, 2024 22:02
Show Gist options
  • Save edxmorgan/196bd746a43b26249a36ee4afe9b9e3b to your computer and use it in GitHub Desktop.
Save edxmorgan/196bd746a43b26249a36ee4afe9b9e3b to your computer and use it in GitHub Desktop.
linearize a nonlinear function in casadi
#method 0
def linearize_new(f, x, x0):
x_lim = SX.sym('x_lim', x.sparsity())
return substitute(f + jtimes(f, x, x_lim - x0), vertcat(x_lim, x), vertcat(x, x0))
f_linear_new = Function('f_linear_new', [x, x0, u, mu, I_sym], [linearize_new(x_next, x, x0)])
#method 1
F_next_linear = Function('Xnext_linear', [x, x0, u, mu, I_sym], [linearize(x_next, x, x0)])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment