Question

In: Advanced Math

Theory: A vector with nonnegative entries is called a probability vector if the sum of its...

Theory: A vector with nonnegative entries is called a probability vector if the sum of its entries is 1. A square matrix is called right stochastic matrix if its rows are probability vectors; a square matrix is called a left stochastic matrix if its columns are probability vectors; and a square matrix is called a doubly stochastic matrix if both the rows and the columns are probability vectors.

**Write a MATLAB function

function [S1,S2,P]=stochastic(A)

which accepts a square matrix A with nonnegative entries as an input. An output P will be a stochastic matrix, when it can be created according to the instructions given below. You will also calculate and output the row vectors S1=sum(A,1) and S2=transpose(sum(A,2)) in your code, where the entries of the vectors sum(A,1) and sum(A,2) are the sums of the entries of A down each column and across each row, respectively You may also employ the conditional “if” statements and logical function all.

**First, the function has to check whether a matrix A contains both a zero column and a zero row. If yes, the output has to be a message “A is not stochastic and cannot be scaled to stochastic”. (Meaning: it is neither right- nor left-stochastic and cannot be scaled to either of them.) The output P in this case will be an empty matrix, P= [ ].

**Then, the function checks whether a matrix A is: (1) doubly stochastic, (2) only left stochastic, (3) only right stochastic, or (4) neither left nor right stochastic but can be scaled to stochastic.

In the cases (1)-(3), output the corresponding messages that comment on the types of the matrices and assign to the output P the matrix A itself.

**When you are working with the case (4), output a message “neither left nor right stochastic but can be scaled to stochastic”. If the vector S1 does not have any zero entry, use this vector to modify A into a left-stochastic matrix P by scaling each of its columns by the reciprocal of the corresponding entry of S1, and output a message that you are scaling A to a left-stochastic matrix P. If S1 has a zero entry, use the vector S2 to modify matrix A into a right-stochastic matrix P by scaling each of its rows by the reciprocal of the corresponding entry of S2, and output a message that you are scaling A to a right-stochastic matrix P. Output the matrix P.

**Type the function stochastic in your Live Script.

**Run the function [S1,S2,P]=stochastic(A) on each of the matrices below (display the matrices in your Live Script file):

(a)A=[0.5, 0, 0.5; 0, 0, 1; 0.5, 0, 0.5]

(b)A = transpose(A)

(c)A=[0.5, 0, 0.5; 0, 0, 1; 0, 0, 0.5]

(d)A=transpose(A)

(e)A=[0.5, 0, 0.5; 0, 0.5, 0.5; 0.5, 0.5, 0]

(f)A=magic(3)

(g)A=diag([1,2,3])

(h)A=[0, 0, 0; 0, 0.5, 0.5; 0, 0.5, 0.5]

(k)A=randi(10,5,5);A(:,1)=0;A(1,:)=0

NOTE: Make sure that you will verify that your outputs and the messages match the corresponding definitions of stochastic matrices. If they don’t, make corrections in your code!

Solutions

Expert Solution

MATLAB FUNCTION:

function P=stochastic(A)
S1=sum(A,1);
S2=(sum(A,2))';
if ~all(S1) && ~all(S2)
fprintf('A is not stochastic and cannot be scaled to either of them ')
P=[];
elseif sum(S1==1)==length(S1) && sum(S2==1)==length(1)
fprintf('A is a doubly stochastic matrix ')
P=A;
elseif sum(S2==1)==length(S1)
fprintf('A is a right stochastic matrix ')
P=A;
elseif sum(S1==1)==length(S2)
fprintf('A is a left stochastic matrix ')
P=A;  
else
fprintf('Neither left nor right stochastic but can be scaled to stochastic. ')
if all(S1)
A=A./S1;
P=A;
else
A=A./(S2)';
P=A;
end
end


Related Solutions

The sum of three nonnegative numbers is 36. One of the numbers is twice one of...
The sum of three nonnegative numbers is 36. One of the numbers is twice one of the other numbers. None of the numbers are greater than 12. What is the maximum value of the product of these three numbers? Use x, y, z as your variables
What is the sum of the probabilities in a probability distribution?
What is the sum of the probabilities in a probability distribution?
Four dice are tossed. Find the probability that (a) the sum is 10, (b) the sum...
Four dice are tossed. Find the probability that (a) the sum is 10, (b) the sum is 15, (c) two dice comes up 1 and two dice come up?
Choose your favorite unique vector b in R3 with no 0 entries. What is your vector...
Choose your favorite unique vector b in R3 with no 0 entries. What is your vector b? Based on the “Equivalent Conditions for a Non-Singular Matrix” on page 123 in our text, why must Ax = b have a unique solution in this situation? Solve the equation Ax = b the following three ways (you should get the same answer each way!) Recall – calculator OK, in fact suggested. (24 points – 8 points each) Solve the equation Ax =...
QUESTION 1 Vector Space Axioms Let V be a set on which two operations, called vector...
QUESTION 1 Vector Space Axioms Let V be a set on which two operations, called vector addition and vector scalar multiplication, have been defined. If u and v are in V , the sum of u and v is denoted by u + v , and if k is a scalar, the scalar multiple of u is denoted by ku . If the following axioms satisfied for all u , v and w in V and for all scalars k...
A pair of dice is cast. What is the probability that the sum of the two...
A pair of dice is cast. What is the probability that the sum of the two number landing uppermost is less than 5, if it is known that the sum of the numbers falling uppermost is less than 7?
Find the probability of rolling a sum of two dice that is a 7 or a...
Find the probability of rolling a sum of two dice that is a 7 or a 12. Round answer to 4 decimal places.
2. a) Find the true value of the probability that the sum of the numbers on...
2. a) Find the true value of the probability that the sum of the numbers on their faces will be at least 2 times 3 when a pair of dice is rolled 162 times b)Find the approximate value of the probability that the sum of the numbers on their face is at least 2 times 3 when a pair of dice is rolled 162 times
A pair of the die is rolled once. What is the probability that the sum of...
A pair of the die is rolled once. What is the probability that the sum of the value' on the two die  faces is not a 7?
Provide a description of Prospect Theory (the nature of its value function, the probability weighting function,...
Provide a description of Prospect Theory (the nature of its value function, the probability weighting function, the loss aversion parameter, main characteristics of the theory etc.). Explain how the observed four-fold pattern of risk attitudes can be authenticated using the probability weighting function and the functional forms (positive and negative domain) of the value function.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT