Question
***Please answer in MATLAB*** **Create a function in MATLAB function q = markov (P,X0) The function has to perform the following: Step 1: Check whether
***Please answer in MATLAB***
**Create a function in MATLAB
function q=markov(P,X0)
The function has to perform the following:
Step 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=[ ].
Step 2: Find the steady-state vector q.
Recall: the steady-state vector is the probability vector that is a solution of , or, equivalently, . A rational basis for the solution set of this system that contains one vector can be found as , where n is a number of rows (or, equivalently, columns) of P. To find the unique (probability vector) q, you need to scale vector Q, that is , where (the sum of entries of the column vector Q).
Step 3: Verify that the Markov chain 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 within the loop).
**Type the function markov in your diary file.
**Run the function q=markov(P,x0) on the following matrices P and vectors x0:
(a) P=[0.6 0.3;0.5 0.7] and x0 =[0.4;0.6],
(b) P=[0.5 0.3; 0.5 0.7] and x0 is the same as in part (a).
% Write a comment if xk is the same as vector q.
(c) P =[0.9 0.2; 0.1 0.8] is a migration matrix between two regions and the initial vector x0 = [0.12; 0.88].
(d) The migration matrix P is the same as in part (c) but ; x0=[0.14; 0.86]; x0=[0.86; 0.14].
% Compare the output vectors q for part (d) with the output q for part (c) and write a comment about whether the initial vector x0 has an effect on the steady-state vector q. What about the number of iterations k? Write a comment please.
(e) Car rental pick-up/return matrix P = [0.90 0.01 0.09; 0.1 0.90 0.01; 0.9 0.9 0.90] between the Airport, Downtown, and Metro, and x0=[0.5;0.3;0.2]
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started