# HG changeset patch # User Anoop Jacob Thomas # Date 1286781548 -19800 # Node ID d9507624eb8f14f894a0d2636824da2308e9177d # Parent 44f06ae0d957c2144869c6dd8f40fdb65b811d62 added questions for matrices. diff -r 44f06ae0d957 -r d9507624eb8f matrices/questions.rst --- a/matrices/questions.rst Mon Oct 11 11:40:43 2010 +0530 +++ b/matrices/questions.rst Mon Oct 11 12:49:08 2010 +0530 @@ -3,6 +3,82 @@ .. A mininum of 8 questions here (along with answers) +1. ``matrix(A) * matrix(B)`` and ``array(A) * array(B)`` are the same. + + a. True + #. False + +Answer: False + +2. ``matrix(A) * array(B)`` does, + + a. Element wise multiplication. + #. Matrix multiplication. + #. Cannot multiply a matrix object and array object. + #. Depends on the shape of A and B, if compatible matrix + multiplication will be done, otherwise element wise + multiplication. + +Answer: Matrix multiplication + +3. A and B are two matrix objects. Element wise multiplication in + matrices are done by, + + a. A * B + #. ``multiply(A, B)`` + #. ``dot(A, B)`` + #. ``element_multiply(A,B)`` + +Answer: multiply(A, B) + +4. ``norm(A)`` method determines the, + + a. Frobenius norm + #. Infinity norm + #. Induced norm + #. Schatten norm + +Answer: Frobenius norm + +5. ``eig(A)[1]`` and ``eigvals(A)`` are the same. + + a. True + #. False + +Answer: False + +6. The code snippet will work without an error, + :: + + A = matrix([[1, 2, 3, 4], [5, 6, 7, 8]]) + inv(A) + + a. True + #. False + +Answer: False + +7. What is the output of the following code, + :: + + x = matrix([[1, 2, 3], ['a', 2, 'c']]) + identity(x.shape) + + a. Will create an identity matrix of shape (2, 3). + #. ``identity()`` function takes an integer as argument and a tuple + is passed. + #. Will return, matrix([[1,0,1],[0,1,0]]) + #. Will return, matrix([[0,1,0],[0,1,0]]) + +Answer: ``identity()`` function takes an integer as argument and a + tuple is passed. + +8. ``norm(A,ord='fro')`` is the same as ``norm(A)`` + + a. True + #. False + +Answer: True Larger Questions ---------------- @@ -30,3 +106,11 @@ What will be the array after 22 such operations starting with [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] +2. Find the infinity norm and the determinant of the inverse of the + product of matrices A and B. + :: + + A = [[ 1, 2, 3, 4], B = [[16, 15, 14, 13], + [ 5, 6, 7, 8], [12, 11, 10, 9], + [ 9, 10, 11, 12], [ 8, 7, 6, 5], + [13, 14, 15, 16]] [ 4, 3, 2, 1]] diff -r 44f06ae0d957 -r d9507624eb8f matrices/script.rst --- a/matrices/script.rst Mon Oct 11 11:40:43 2010 +0530 +++ b/matrices/script.rst Mon Oct 11 12:49:08 2010 +0530 @@ -70,6 +70,8 @@ it does matrix subtraction, that is element by element subtraction. Now let us try, + +{{{ Switch to next slide, Matrix multiplication }}} :: m3 * m2 @@ -120,9 +122,9 @@ Matrix name dot capital T will give the transpose of a matrix -{{{ switch to next slide, Euclidean norm of inverse of matrix }}} +{{{ switch to next slide, Frobenius norm of inverse of matrix }}} -Now let us try to find out the Euclidean norm of inverse of a 4 by 4 +Now let us try to find out the Frobenius norm of inverse of a 4 by 4 matrix, the matrix being, :: @@ -131,17 +133,17 @@ The inverse of a matrix A, A raise to minus one is also called the reciprocal matrix such that A multiplied by A inverse will give 1. The -Euclidean norm or the Frobenius norm of a matrix is defined as square -root of sum of squares of elements in the matrix. Pause here and try -to solve the problem yourself, the inverse of a matrix can be found -using the function ``inv(A)``. +Frobenius norm of a matrix is defined as square root of sum of squares +of elements in the matrix. Pause here and try to solve the problem +yourself, the inverse of a matrix can be found using the function +``inv(A)``. And here is the solution, first let us find the inverse of matrix m5. :: im5 = inv(m5) -And the euclidean norm of the matrix ``im5`` can be found out as, +And the Frobenius norm of the matrix ``im5`` can be found out as, :: sum = 0 @@ -166,16 +168,18 @@ {{{ switch to slide the ``norm()`` method }}} -Well! to find the Euclidean norm and Infinity norm we have an even easier +Well! to find the Frobenius norm and Infinity norm we have an even easier method, and let us see that now. The norm of a matrix can be found out using the method -``norm()``. Inorder to find out the Euclidean norm of the matrix im5, +``norm()``. Inorder to find out the Frobenius norm of the matrix im5, we do, :: norm(im5) +Euclidean norm is also called Frobenius norm. + And to find out the Infinity norm of the matrix im5, we do, ::