Question: ***Please answer in MATLAB*** Theory: A vector with nonnegative entries that add up to 1 is called a probability vector. A stochastic matrix is a
***Please answer in MATLAB*** Theory: A vector with nonnegative entries that add up to 1 is called a probability vector. A stochastic matrix is a square matrix whose columns are probability vectors. A Markov chain is a sequence of probability vectors x0, x1, x2,..., together with a stochastic matrix P, such that x1 = Px0, x2 = Px1, x3 = Px2. In other words, a Markov chain is described by the first-order difference equation xK+1 = Pxk for k = 0,1,2,... The n entries of vectors xk list, respectively, a probability that the system is in one the n possible states. For this reason, xk is called a state vector. If P is a stochastic matrix, then a steady-state vector for P is a probability vector q such that Pq=q . A stochastic matrix P is called regular if some matrix power Pk contains only strictly positive entries. Theorem: If P is an nxn regular stochastic matrix, then P has a unique steady-state vector q. Further, if x0 is any initial state and xK+1 = Pxk for k =0,1,2 ,..., then the Markov chain {xk } converges to q as k . Exercise 6 : **Create a function in MATLAB function q=markov( P,x0) The function has to perform the following: 1) Check whether the given matrix P is stochastic. If P is stochastic, proceed to step 2. If P is not stochastic, the program displays a message P is not a stochastic matrix and returns q=empty_vector. 2) Find the steady-state vector q. Recall: the steady-state vector is the probability vector that is a solution of Pq=q, or, equivalently, (P-I)q=0 . A rational basis for the solution set of this system that contains one vector can be found as Q = null(P- eye(n), 'r'), where n is a number of rows (or, equivalently, columns) of P. To find the unique q, you will need to scale vector Q, that is q = (1/c) * Q , where c = sum(Q) (the sum of entries of the column vector Q). 3) Verify that the Markov chain { xk} converges to q by calculating consecutive x1= P*x0, x2 = P* x1, x3 = P*x2, ... until, for the first time, norm(xk-q)<10-7 . Output the number of iterations k and the vector xk itself. Hint: You can compute xk using while loop and reassigning x0= x1 after each iteration. Then you will need to return x1 (which will be your xk after the loop terminates) and the number of iteration k (which you can find by setting a counter for the number of iterations). ***Please answer in MATLAB****
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
