Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Hey guys, I'm having a bit of trouble with a MATLAB function. I've attached a photo of the description. Theory: A vector with nonnegative entries
Hey guys, I'm having a bit of trouble with a MATLAB function. I've attached a photo of the description.
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 P stochastic(A) which accepts a square matrix A with nonnegative entries as an input. The output will be a stochastic matrix Pas defined below. You should use the row vectors Sl sum(A,1)and S2 (sum(A,2))' in your code along with the conditional "if statements. **First, the function has to check whether a matrix A contains both a zero column and azero 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. In each of the cases (1) (30, 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 the row vector si (or S2) of sums of the entries of A down each column (or across each row). Then use vector si (or S2) to modify A into P by scaling each of its columns by the reciprocal of the corresponding entry of S1 (or S2) to obtain a stochastic matrix. The output P will be the resulting matrix
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