[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

lsode and symbolic function handles

From: Vikram Garg
Subject: lsode and symbolic function handles
Date: Fri, 28 Feb 2020 16:34:41 -0600

         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];


## 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.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]