LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
ctmc_transient_sens.m
1function [dpi, pi, t] = ctmc_transient_sens(Q, dQ, pi0, t0, t1)
2% [DPI, PI, T] = CTMC_TRANSIENT_SENS(Q, DQ, PI0, T0, T1)
3%
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.
6%
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
9%
10% d/dt (dpi(t)/dtheta) = (dpi(t)/dtheta) Q + pi(t) (dQ/dtheta),
11% dpi(0)/dtheta = 0,
12%
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.
16%
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
21% @param t1 Final time
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
25%
26% Copyright (c) 2012-2026, Imperial College London
27% All rights reserved.
28
29n = size(Q, 1);
30if nargin == 3
31 t1 = pi0;
32 t0 = 0;
33 pi0 = [];
34end
35if nargin == 4
36 t1 = t0;
37 t0 = 0;
38end
39if isempty(pi0)
40 pi0 = ones(1, n) / n;
41end
42if any(size(dQ) ~= size(Q))
43 line_error(mfilename, 'dQ must have the same size as Q');
44end
45
46% Augmented state v = [pi, dpi], with dpi(0) = 0 since pi(0) does not depend
47% on theta
48v0 = [pi0(:); zeros(n, 1)];
49
50[t, v] = ode23(@augmentedode, [t0, t1], v0);
51
52pi = v(:, 1:n);
53dpi = v(:, (n+1):(2*n));
54
55 function dvdt = augmentedode(~, v)
56 % DVDT = AUGMENTEDODE(T, V)
57
58 p = v(1:n)';
59 s = v((n+1):(2*n))';
60 dpdt = p * Q;
61 dsdt = s * Q + p * dQ;
62 dvdt = [dpdt(:); dsdt(:)];
63 end
64
65end
Definition Station.m:245