Hello,
I would like to be able to evaluate symbolic function handles to construct the forcing vector of an ODE.
For example, in the code below,
## Construct symbolic vector b
syms b1 b2;
b(1) = b1;
b(2) = b2;
## Handle for symbolic vector b
bh = function_handle(b);
## function to be passed to lsode
function xdot = f(x,t)
xdot = zeros(2,1);
xdot(1) = bh(x(1), x(2))*[1;0];
xdot(2) = bh(x(1), x(2))*[0;1];
endfunction
## Initial conditions and time vector for lsode
x0 = [0;1];
t = linspace (0, 500, 1000);
y = lsode("f",x0, t);
Running this gives an error,
error: 'bh' undefined
error: lsode: evaluation of user-supplied function failed
Trying to declare the function handle as global (global bh = function_handle(b);) did not help. But I think there must be a way to do this, since we can use built in functions inside of the ode integrator functions.
Any pointers would be appreciated.