1function [dpi, pi, t] = ctmc_transient_sens(Q, dQ, pi0, t0, t1)
2% [DPI, PI, T] = CTMC_TRANSIENT_SENS(Q, DQ, PI0, T0, T1)
4% Sensitivity of
the transient distribution of a CTMC to a scalar parameter
5% theta, given
the generator Q and its derivative DQ = dQ/dtheta.
7% Differentiating
the forward equations d pi(t)/dt = pi(t) Q with respect to
8% theta, and assuming
the initial vector does not depend on theta, gives
10% d/dt (dpi(t)/dtheta) = (dpi(t)/dtheta) Q + pi(t) (dQ/dtheta),
13% i.e. Trivedi and Bobbio (2017), Eq. (9.82). The state and its sensitivity
14% are integrated as one augmented system of size 2n, since
the sensitivity
15% equation
is driven by pi(t) and
the two cannot be advanced separately.
17% @param Q Generator matrix (n x n)
18% @param dQ Derivative of
the generator with respect to theta (n x n)
19% @param pi0 Initial distribution (1 x n); uniform
if empty
20% @param t0 Initial time; 0
if omitted
22% @
return dpi Sensitivity of
the distribution at each time point (length(T) x n)
23% @
return pi Distribution at each time point (length(T) x n)
24% @
return t Column vector of time points
26% Copyright (c) 2012-2026, Imperial College London
42if any(size(dQ) ~= size(Q))
43 line_error(mfilename,
'dQ must have the same size as Q');
46% Augmented state v = [pi, dpi], with dpi(0) = 0 since pi(0) does not depend
48v0 = [pi0(:); zeros(n, 1)];
50[t, v] = ode23(@augmentedode, [t0, t1], v0);
53dpi = v(:, (n+1):(2*n));
55 function dvdt = augmentedode(~, v)
56 % DVDT = AUGMENTEDODE(T, V)
61 dsdt = s * Q + p * dQ;
62 dvdt = [dpdt(:); dsdt(:)];