1%{ @file ctmc_transient.m
2 % @brief Transient analysis of a continuous-time Markov chain
using ODE solvers
4 % @author LINE Development Team
8 % @brief Transient analysis of a continuous-time Markov chain
using ODE solvers
11 % Computes the transient state probabilities
using ODE solvers.
15 % [pi, t] = ctmc_transient(Q, pi0)
16 % [pi, t] = ctmc_transient(Q, pi0, t0, t1)
17 % [pi, t] = ctmc_transient(Q, pi0, t0, t1, useStiff, reltol, timestep)
22 % <tr><th>Name<th>Description
23 % <tr><td>Q<td>Infinitesimal generator matrix
24 % <tr><td>pi0<td>Initial probability distribution vector
25 % <tr><td>t0<td>(Optional) Start time
26 % <tr><td>t1<td>(Optional) End time
27 % <tr><td>useStiff<td>(Optional) Boolean to use stiff ODE solver (ode15s) instead of ode23. Default:
false
28 % <tr><td>reltol<td>(Optional) Relative tolerance
for the ODE solver. Default: 1e-3
29 % <tr><td>timestep<td>(Optional) Fixed time step for the output
34 % <tr><th>Name<th>Description
35 % <tr><td>pi<td>State probability vectors at each time point
36 % <tr><td>t<td>Time points corresponding to the probabilities
39function [pi,t]=ctmc_transient(Q,pi0,t0,t1,useStiff,reltol,timestep)
40if ~exist('useStiff','var')
43if ~exist(
'reltol',
'var')
46if ~exist('timestep','var')
52 pi0=ones(1,length(Q));pi0=pi0/sum(pi0);
59odeoptions = odeset('RelTol', reltol);
61% Use fixed intervals if timestep parameter
is specified
62if ~isempty(timestep) && timestep > 0
65 t = [t, t1]; % Ensure t1
is included
68 [t,pi]=ode15s(@ctmc_transientode, t, pi0, odeoptions);
70 [t,pi]=ode23(@ctmc_transientode, t, pi0, odeoptions);
73 % Original adaptive stepping behavior
75 nonZeroRates = abs(Q(Q~=0));
76 nonZeroRates = nonZeroRates( nonZeroRates >0 );
77 T = abs(100/min(nonZeroRates)); % solve ode until T = 100 events with the slowest rate
79 [t,pi]=ode15s(@ctmc_transientode, [t0,T], pi0, odeoptions);
81 [t,pi]=ode23(@ctmc_transientode, [t0,T], pi0, odeoptions);
85 [t,pi]=ode15s(@ctmc_transientode, [t0,t1], pi0, odeoptions);
87 [t,pi]=ode23(@ctmc_transientode, [t0,t1], pi0, odeoptions);
91%[t,pi]=ode113(@ctmc_transientode,[t0,t1],pi0);
93function dpidt=ctmc_transientode(t,pi)