Home > matpower7.1 > extras > syngrid > lib > nsw_markov.m

nsw_markov

PURPOSE ^

PURPOSE: run Markov flips for "n" times, get a chain of "0/1" states.

SYNOPSIS ^

function yout = nsw_markov(alph,bta,n,start)

DESCRIPTION ^

 PURPOSE: run Markov flips for "n" times, get a chain of "0/1" states.
 USAGE:  nsw_markov(alph,bta,n); nsw_markov(alph,bta,n,start);
 INPUT:
       alph: 0-->1 transition prob
       bta:  1-->0 transition prob
         n:  total times
       start: inital state 0/1
 OUTPUT:
       yout: 1 by n binary vector (0/1)
 wzf, 2008

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function yout = nsw_markov(alph,bta,n,start)
0002 % PURPOSE: run Markov flips for "n" times, get a chain of "0/1" states.
0003 % USAGE:  nsw_markov(alph,bta,n); nsw_markov(alph,bta,n,start);
0004 % INPUT:
0005 %       alph: 0-->1 transition prob
0006 %       bta:  1-->0 transition prob
0007 %         n:  total times
0008 %       start: inital state 0/1
0009 % OUTPUT:
0010 %       yout: 1 by n binary vector (0/1)
0011 % wzf, 2008
0012 
0013 %   SynGrid
0014 %   Copyright (c) 2008, 2017, Electric Power and Energy Systems (EPES) Research Lab
0015 %   by Zhifang Wang, Virginia Commonwealth University
0016 %
0017 %   This file is part of SynGrid.
0018 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0019 
0020 % steady distribution of state 0 and 1
0021 p0 = bta/(alph+bta); p1 = 1-p0;
0022 
0023 if(nargin == 3) % decide "start" state
0024     if(rand<=p0)
0025         start = 0;
0026     else
0027         start =1;
0028     end
0029 end
0030 
0031 yout = zeros(1,n);
0032 yout(1) = start; % get yout
0033 for k = 2:n
0034     if(yout(k-1) == 0)
0035         yout(k) = flip(alph,0);
0036     else
0037         yout(k) = flip(bta,1);
0038     end
0039 end
0040 
0041 
0042 %----------------------- Subfunction --------------------------------------
0043 %--------------------------------------------------------------------------
0044 function next = flip(prob,curr)
0045 % by probability of "prob", flip current state "curr"
0046 
0047 if(rand > prob)
0048     next = curr;
0049 else
0050     next = ~curr;
0051 end

Generated on Fri 09-Oct-2020 11:21:31 by m2html © 2005