Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help making a matlab function which meets these requirements. More on Matrices; Application Difficulty: Moderate ExErCISE5 (6 points) Theory: A vector with nonnegative

I need help making a matlab function which meets these requirements. image text in transcribed

More on Matrices; Application Difficulty: Moderate ExErCISE5 (6 points) 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 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 y **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 outputs in this case are S1, S2, and 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 the message "neither left nor right stochastic but can be scaled to stochastic" and 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. In each case, output the matrices S1,S2, and P our code. **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

Practical Oracle8I Building Efficient Databases

Authors: Jonathan Lewis

1st Edition

0201715848, 978-0201715842

More Books

Students also viewed these Databases questions

Question

What are the Five Phases of SDLC? Explain each briefly.

Answered: 1 week ago

Question

How can Change Control Procedures manage Project Creep?

Answered: 1 week ago