Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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 P = stochastic(A) which accepts a square matrix A with nonnegative entries as an input. The output will be a stochastic matrix P as defined below. You should use the row vectors S1 = sum(A, 1) and S2 = (sum(A, 2))' in your code along with the conditional "if" statements. You could also employ a logical function all in your code. **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 matrix in this case is 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 each of the cases (1)-(3), output the corresponding message that comments on the type of the matrix and assign the matrix A itself to the output P. **When you are working with the case (4), code in your function to output both the row vector S1 of the sums of the entries of A down each column and the column vector S2 of the sums of the entries across each row. 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. If S1 has a zero entry, use the vector S2 to modify A into a right-stochastic matrix P by scaling each of its rows by the reciprocal of the corresponding entry of S2. Output the matrix P. **Type the function stochastic in your diary file. **Run the function P=stochastic(A) on each of the matrices below (display the matrices in your diary file): (a) A=[0.5, 0, 0.5; 0, 0, 1; 0.5, 0, 0.5] (b) A = A' (c) A = [0.5, 0, 0.5; 0, 0, 1;0, 0, 0.5] (d) A = 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]

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Main Memory Database Systems

Authors: Frans Faerber, Alfons Kemper, Per-Åke Alfons

1st Edition

1680833243, 978-1680833249

More Books

Students also viewed these Databases questions

Question

Explain the functions of financial management.

Answered: 1 week ago

Question

HOW MANY TOTAL WORLD WAR?

Answered: 1 week ago

Question

Discuss the scope of financial management.

Answered: 1 week ago

Question

Discuss the goals of financial management.

Answered: 1 week ago