Last active
May 28, 2023 21:27
-
-
Save jgillis/b55a3513d8af70ab56fcdfb8d0bdf0d6 to your computer and use it in GitHub Desktop.
How to do np.interp in CasADi
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 as cs | |
import numpy as np | |
xp = [1, 2, 3] | |
fp = [3, 2, 0] | |
x = [2.5,1.1] | |
print(np.interp(x=x,xp=xp,fp=fp)) | |
# np.interp as CasADi Function | |
# Note: CasADi functions always need fixed dimensions | |
grid = [len(xp)] # size of grid, list is used since can be multi-dimensional | |
cs_interp = cs.interpolant('cs_interp','linear',grid,1,{"inline": True}) | |
print(cs_interp) | |
# Using broadcasting on first argument to obtain an evaluation for all values in x | |
print(cs_interp(cs.DM(x).T,xp,fp)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment