Right, our docs are long overdue on lookup tables.
I'll get it ready for coming release.
In the meantime, here you have some example code:
import casadi.*
%% 2.1
xgrid = -5:1:5;
ygrid = -4:1:4;
[X1,X2] = ndgrid(xgrid, ygrid);
R = sqrt(X1.^2 + X2.^2)+ eps;
V = sin(R)./(R);
interpn(X1,X2,V,0.5,1,'spline')
LUT = interpolant('LUT','bspline',{xgrid, ygrid},V(:));
LUT([0.5 1])
%% 2.2
xgrid = 1:6;
V = [-1 -1 -2 -3 0 2];
xs = linspace(1,6,1000);
interpn(xgrid,V,0.5,'spline')
LUT = interpolant('LUT','bspline',{xgrid},V);
LUT(0.5)
figure
hold on
plot(xgrid, V, 'o');
res_matlab = interpn(xgrid,V,xs,'spline');
plot(xs, res_matlab)
LUTmap = LUT.map(1000);
res_casadi = full(LUTmap(xs));
plot(xs, res_casadi)
figure()
plot(xs, res_casadi-res_matlab)
%% 2.3
x = MX.sym('x');
y = LUT(x);
solver = nlpsol('solver','ipopt',struct('x',x,'f',y));
sol = solver('x0',2,'lbx',1,'ubx',6);
sol.x
%% 2.4
y = LUT(x);
dy = jacobian(y,x);
ddy = jacobian(dy,x);
dddy = jacobian(ddy,x);
res = Function('f',{x},{y,dy,ddy,dddy});
resmap = res.map(1000);
[yv, dyv, ddyv, dddyv] = resmap(xs);
figure
hold on
plot(xs,full(yv))
plot(xs,full(dyv))
plot(xs,full(ddyv))
plot(xs,full(dddyv))
%%