Sale!

CSCI 2202 Lab 9 Matrices and Vectors I Solved

Original price was: $40.00.Current price is: $35.00. $29.75

Category:

Description

5/5 - (1 vote)

Ex.I Consider a model of population movement between cities and suburbs in the US (data from 2007). Estimate of the number of people living in cities (c) 82 million and suburbs (s) 163 million. The initial distribution can be represented as: x0=[82163]T�0=[82163]�

The proportion of city dwellers staying in a city in current year: P(c|c)=0.96�(�|�)=0.96  the proportion of city dwellers moving to a suburb is P(s|c)=0.04�(�|�)=0.04; The proportion of suburbanites moving to the city is: P(c|s)=0.01�(�|�)=0.01 and hence the proportion of suburbanites staying in the suburbs is P(s|s)=0.99�(�|�)=0.99.

  1. From this information, set up the transition matrix: P (see Lecture Notes 5 & 5B)
  2. Write a program that prints out the population distribution in 2008, 2009, 2010, 2011 & 2012. You may use the numpy functions for matrix/vector multiplication.

Ex.I Write a function transp(A). That takes a matrix A as input and returns the transpose of A (recall that the transpose of A interchanges the rows and column of a matrix. To do this, you can iterate over the rows of A and the columns of the row. For each element aij��� you access, you can make the assignment aji=aij���=���.

Ex.III Write a function (without using the numpy functions matmult, dot, @ etc. that takes two matrices as input parameters and computes the product of the two matrices. Write two versions of the function:

  1. mMult(X, Y) which returns the resultant matrix.
  2. mMult-noRet(X, Y, Z) where Z is a matrix of zeros, of dimensions equal to that of the matrix XY��created within the calling program. This function should not return anything. Instead, The matrix Z is created in the calling program, and passed as a parameter to your function mMult-noRet(X, Y, Z). Your function should compute the result in Z.
    1. Test your code by generating two random, integer matrices, of dimensions 5×55×5 with elements taken from the integers 0  9

    (See class notes (Lec 5B, avail. online)). Assume the matrices are compatible for multiplication in the order given in the function parameters. *i.e. mMult(X, Y) returns the matrix product XY��).*

    1. Verify your result using the numpy functions for multiplication of matrices.

Notes: (a) The result of the multiplication: C=AB�=�� is [cij]=n1j=0aijbjk[���]=∑�=0�−1������ (b) The number of rows of a matrix can be accessed by len(A) and the number of columns of A can be acessed as len(A[0])