I have a system of stiff ODEs that I solve with ode15s. The time derivative is of the type:
yt = A*y - u.*y;
Where yt
, y
and u
are column vectors and A
is a sparse matrix. The computation of u
has to be carried every evaluated time and it's computationally intensive (u is non-linear and it's the cause of the stiffness). I don't want to pre-compute u
becase I would like to keep the freedom of the solver to choose any desired times later. What I'm interested in, however, is not on the solution y(t), but on u(t).*y(t), which is already calculated to compute yt
. If I get the solution as a struct sol
that then I can evaluate with deval
, I can easily compute y(t), but u(t) would have to be recalculated. I was wondering if there is a way to somewhat store the result of u.*y
while using the solver, so then I could call it as easily as I call deval(y,t)
. The closest alternative I have found, is to rely on deval also providing the time derivative, so then do:
[y,yt] = deval(sol,t); %t is a row vector
uy = A*y - yt; %uy = u.*y
Which is not terribly inefficient, but wastes some computation in operations that were already computed.
Any idea on how to do this?