There are two ways to do this. The most common, and usually fastest, way is to take advantage of your integration function (RHSODE
in your case) and evaluate your function f
after performing the integration. You haven't provided many details with your code but it might look something like this:
ydot = RHSODE(t,y);
z = f(y,ydot);
where t
and y
are the outputs from ode23tb
. This requires that both RHSODE
and f
be vectorized (or you can wrap the above in a for
loop).
The other way requires that you create an additional equation (or equations if z
is a vector) inside of your integration function, RHSODE
. Normally ode23tb
integrates anything in this function so f
must be multiplied by a factor of t
to cancel this out. Again, your code might look something like this:
function ydot = RHSODE(t,y)
ydot0 = ... % Your original ODE(s)
z = f(y,ydot);
ydot = [ydot0;z*t]; % Make column vector