A Markov Matrix is a square matrix,which have two features:
- All elements great than or equal to $0$(But I hope all element great than or equal to $0.1$)
- All the columns add up to $1$
I have a custom function for this
MarkovMatrix[dim_] :=
Module[{m}, Label[start];
m = Transpose[
Append[#, 1 - Total[#]] & /@
RandomReal[1, {dim, dim - 1}, WorkingPrecision -> 2]];
If[AllTrue[m, # > .1 &, 2], m, Goto[start]]; m]
Usage:
For example to generate a 4*4 matrix
MatrixForm[m = MarkovMatrix[4]]
But my MarkovMatrix
is low efficiency function.Are there any better method can do this?
Transpose[Normalize[#, Total] & /@ RandomReal[1, {4, 4}]]
? Anyway: the more common term is stochastic matrix. $\endgroup$Goto
. $\endgroup$