Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create the following function in MATLAB: Theory: A vector with nonnegative entries is called a probability vector if the sum of its entries is 1.

Create the following function in MATLAB:

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 if its rows are probability vectors; a square matrix is called left stochastic if its columns are probability vectors; and a square matrix is called doubly stochastic if both, the rows and the columns, are probability vectors.

image text in transcribed

More on Matrices; Application EXERCISE6 (5 points) Difficulty: Hard 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 if its rows are probability vectors; a square matrix is called left stochastic if its columns are probability vectors; and a square matrix is called doubly stochastic if both, the rows and the columns, are probability vectors. **Write a MATLAB function that begins with function [S1, S2, L,R] =stochastic (A) L=[]; R=[]; It accepts as the input a square matrix A with nonnegative entries. Outputs L and R will be the left stochastic and the right stochastic matrices generated according to the instructions given below (when it is possible). You will also calculate and display the vectors Sl=sum (A, 1) and S2-sum (A, 2) with the corresponding messages: fprintf('the vector of sums down each column is ') Sl=sum (A, 1) fprintf('the vector of sums across each row is ') S2=sum (A, 2) Then, you will use a conditional statement to proceed with the tasks outlined below. You may also find it helpful to employ a logical command all. **First, your function has to check whether A contains both a zero column and a zero row. If yes, output a message "A is neither left nor right stochastic and cannot be scaled to either of them". The outputs L and R will be empty matrices as assigned previously)-the empty outputs should be suppressed. **Then, the function checks whether A is: (1) doubly stochastic (assign: L=A; R=A); or (2) only left stochastic (assign: L-A; R will stay empty), or (3) only right stochastic (assign R=A; L will stay empty). In each of the cases, also output a message that comments on the type of the matrix A. **Finally, we consider a possibility that A is neither left nor right stochastic, but can be scaled to the left stochastic and/or to the right stochastic. You will output a message "A is neither left nor right stochastic but can be scaled to a stochastic matrix and proceed with the scaling in the ways outlined below: (1) If neither Si nor S2 has a zero entry, we are scaling* A to the left stochastic matrix L and the right stochastic matrix R. You will also check if it is the case that the matrices L and Rare equal - in this case, A has been scaled to a doubly stochastic matrix. (2) If S1 does not have a zero entry but S2 does, we scale A only to the left stochastic matrix L (R stays empty). (3) And, if S2 does not have a zero entry but Si does, we scale A only to the right stochastic matrix R (L stays empty). Notes: In each of the cases, the non-empty outputs have to be displayed with the corresponding messages. For the case of a doubly stochastic matrix, output the corresponding message and display either L or R. To determine if L=R, you may need to use closetozeroroundoff function with p=7. *Scaling: To scale A to the left stochastic matrix L, we use vector Sl and multiply each column of A by the reciprocal of the corresponding entry of Si. To scale A to the right stochastic matrix R, we use the vector S2 and multiply each row of A by the reciprocal of the corresponding entry of S2. **Run the function (S1, S2, L,R]=stochastic(A) on each of the matrices below (display the input matrices in your Live Script): (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) B-[1 2;34;5 6); A-B*B' (h) A-jord (4,3) (k)A-randi (10,5,5);A(:,1)=0;A(1,:)

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

Excel As Your Database

Authors: Paul Cornell

1st Edition

1590597516, 978-1590597514

More Books

Students also viewed these Databases questions