I am trying to solve an optimal control problem. I have to create a discrete variable that takes only 5 possible values that are not integers. I created a function as shown below whose input 'u' takes discrete values from 0 to 4. The output of the function will be my desired discrete variable. But I am getting an exception. Could anyone help me to solve this problem or suggest some alternative to solve the problem?
%% Code starts here
import casadi as ca
arr = ca.SX([13.45, 7.57, 5.01, 3.77, 2.83690619])
u = ca.MX.sym('u')
get_ratio=ca.Function('get_ratio',u,arr[u])
%% Code ends here
I am getting the below exception.
Exception: Implicit conversion of symbolic CasADi type to numeric matrix not supported.
This may occur when you pass a CasADi object to a numpy function.
Use an equivalent CasADi function instead of that numpy function.
Thanks a lot in advance,
Hemanth Mohan.