diff options
author | kinitrupti | 2017-05-12 18:40:35 +0530 |
---|---|---|
committer | kinitrupti | 2017-05-12 18:40:35 +0530 |
commit | 64d949698432e05f2a372d9edc859c5b9df1f438 (patch) | |
tree | 012fd5b4ac9102cdcf5bc56305e49d6714fa5951 /Linear_Algebra_by_K._Hoffman_and_R._Kunze/Chapter6.ipynb | |
parent | 9c6ab8cbf3e1a84c780386abf4852d84cdd32d56 (diff) | |
download | Python-Textbook-Companions-64d949698432e05f2a372d9edc859c5b9df1f438.tar.gz Python-Textbook-Companions-64d949698432e05f2a372d9edc859c5b9df1f438.tar.bz2 Python-Textbook-Companions-64d949698432e05f2a372d9edc859c5b9df1f438.zip |
Revised list of TBCs
Diffstat (limited to 'Linear_Algebra_by_K._Hoffman_and_R._Kunze/Chapter6.ipynb')
-rw-r--r--[-rwxr-xr-x] | Linear_Algebra_by_K._Hoffman_and_R._Kunze/Chapter6.ipynb | 130 |
1 files changed, 65 insertions, 65 deletions
diff --git a/Linear_Algebra_by_K._Hoffman_and_R._Kunze/Chapter6.ipynb b/Linear_Algebra_by_K._Hoffman_and_R._Kunze/Chapter6.ipynb index 9ad1cbe2..5499419a 100755..100644 --- a/Linear_Algebra_by_K._Hoffman_and_R._Kunze/Chapter6.ipynb +++ b/Linear_Algebra_by_K._Hoffman_and_R._Kunze/Chapter6.ipynb @@ -16,7 +16,7 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 1, "metadata": { "collapsed": false }, @@ -34,13 +34,13 @@ } ], "source": [ - "import sympy as sp\n", + "from sympy import Symbol,Matrix,eye\n", "print 'Standard ordered matrix for Linear operator T on R**2 is:'\n", - "A = sp.Matrix(([0, -1],[1 ,0]))\n", + "A = Matrix(([0, -1],[1 ,0]))\n", "print 'A = \\n',A\n", "print 'The characteristic polynomial for T or A is:',\n", - "x = sp.Symbol(\"x\")\n", - "p = (x*sp.eye(2)-A)\n", + "x = Symbol(\"x\")\n", + "p = (x*eye(2)-A)\n", "print p\n", "print 'Since this polynomial has no real roots,T has no characteristic values.'" ] @@ -84,28 +84,28 @@ } ], "source": [ - "import sympy as sp\n", - "A = sp.Matrix(([3, 1, -1],[ 2, 2, -1],[2, 2, 0]))\n", + "from sympy import Symbol,Matrix,eye,solve\n", + "A = Matrix(([3, 1, -1],[ 2, 2, -1],[2, 2, 0]))\n", "print 'A = \\n',A\n", "print 'Characteristic polynomial for A is:',\n", - "x=sp.Symbol('x')\n", + "x=Symbol('x')\n", "p = A.charpoly(x)#\n", "print p.as_expr()\n", "print 'or'\n", "print '(x-1)(x-2)**2'\n", "\n", - "r = sp.solve(p.as_expr())#\n", + "r = solve(p.as_expr())#\n", "[m,n] = A.shape\n", "print 'The characteristic values of A are:'\n", "print r #print round(r)\n", - "B = A-sp.eye(m)\n", + "B = A-eye(m)\n", "print 'Now, A-I = \\n',B\n", "\n", "print 'rank of A - I= ',B.rank()\n", "print 'So, nullity of T-I = 1'\n", "a1 = [1 ,0 ,2]#\n", "print 'The vector that spans the null space of T-I = ',a1\n", - "B = A-2*sp.eye(m)\n", + "B = A-2*eye(m)\n", "print 'Now,A-2I = \\n',B\n", "print 'rank of A - 2I= ',B.rank()\n", "print 'T*alpha = 2*alpha if alpha is a scalar multiple of a2'\n", @@ -122,7 +122,7 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 1, "metadata": { "collapsed": false }, @@ -184,14 +184,14 @@ } ], "source": [ - "import sympy as sp\n", - "import numpy as np\n", + "from numpy import array,transpose,vstack,rank\n", + "from sympy import Symbol,Matrix,eye\n", "print 'Standard ordered matrix for Linear operator T on R**3 is:'\n", - "A = sp.Matrix(([5, -6, -6],[ -1, 4, 2],[ 3, -6, -4]))\n", + "A = Matrix(([5, -6, -6],[ -1, 4, 2],[ 3, -6, -4]))\n", "print 'A = \\n',A\n", "print 'xI - A = '\n", - "B = sp.eye(3)\n", - "x = sp.Symbol('x')\n", + "B = eye(3)\n", + "x = Symbol('x')\n", "P = x*B - A#\n", "print P\n", "\n", @@ -211,7 +211,7 @@ "print '=>'\n", "print ' * ', c\n", "print P\n", - "P = sp.Matrix(([P[0,0], P[0,2]],[P[2,0], P[2,2]]))\n", + "P = Matrix(([P[0,0], P[0,2]],[P[2,0], P[2,2]]))\n", "print '=>'\n", "print ' * ', c\n", "print P\n", @@ -222,24 +222,24 @@ "\n", "print 'Now, A - I = ',A-B\n", "print 'And, A- 2I = ',A-2*B\n", - "print 'rank(A-I) = ',np.rank(A-B)\n", + "print 'rank(A-I) = ',rank(A-B)\n", "\n", - "print 'rank(A-2I) = ',np.rank(A-2*B)\n", + "print 'rank(A-2I) = ',rank(A-2*B)\n", "print 'W1,W2 be the spaces of characteristic vectors associated with values 1,2'\n", "print 'So by theorem 2, T is diagonalizable'\n", - "a1 = np.array([[3, -1 ,3]])\n", - "a2 = np.array([[2, 1, 0]])\n", - "a3 = np.array([[2, 0, 1]])\n", + "a1 = array([[3, -1 ,3]])\n", + "a2 = array([[2, 1, 0]])\n", + "a3 = array([[2, 0, 1]])\n", "print 'Null space of (T- I) i.e basis of W1 is spanned by a1 = ',a1\n", "print 'Null space of (T- 2I) i.e. basis of W2 is spanned by vectors x1,x2,x3 such that x1 = 2x1 + 2x3'\n", "print 'One example :'\n", "print 'a2 = ',a2\n", "print 'a3 = ',a3\n", "print 'The diagonal matrix is:'\n", - "D = np.array([[1 ,0 ,0 ],[0, 2, 0],[0, 0, 2]])\n", + "D = array([[1 ,0 ,0 ],[0, 2, 0],[0, 0, 2]])\n", "print 'D = ',D\n", "print 'The standard basis matrix is denoted as:'\n", - "P = np.transpose(np.vstack([a1,a2,a3]))\n", + "P = transpose(vstack([a1,a2,a3]))\n", "print 'P = ',P\n", "print 'AP = ',A*P\n", "print 'PD = ',P*D\n", @@ -256,7 +256,7 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 2, "metadata": { "collapsed": false }, @@ -298,37 +298,37 @@ } ], "source": [ - "import numpy as np\n", - "import sympy as sp\n", + "from numpy import array,transpose,vstack,rank\n", + "from sympy import Symbol,Matrix,eye\n", "\n", - "x = sp.Symbol(\"x\")\n", - "A = np.array([[5, -6, -6],[ -1, 4 ,2],[ 3, -6, -4]]) #Matrix given in Example 3\n", + "x = Symbol(\"x\")\n", + "A = array([[5, -6, -6],[ -1, 4 ,2],[ 3, -6, -4]]) #Matrix given in Example 3\n", "print 'A = \\n',A\n", "f = (x-1)*(x-2)**2# \n", "print 'Characteristic polynomial of A is:'\n", "print 'f = (x-1)(x-2)**2'\n", "print 'i.e., f = ',f\n", "p = (x-1)*(x-2)#\n", - "print '(A-I)(A-2I) = ',(A-sp.eye(3))*(A-2 * sp.eye(3))\n", + "print '(A-I)(A-2I) = ',(A-eye(3))*(A-2 * eye(3))\n", "print 'Since, (A-I)(A-2I) = 0. So, Minimal polynomial for above is:'\n", "print 'p = ',p\n", "print '---------------------------------------'\n", "\n", - "A = np.array([[3, 1 ,-1],[ 2, 2 ,-1],[2, 2, 0]]) #Matrix given in Example 2\n", + "A = array([[3, 1 ,-1],[ 2, 2 ,-1],[2, 2, 0]]) #Matrix given in Example 2\n", "print 'A = \\n',A\n", "f = (x-1)*(x-2)**2# \n", "print 'Characteristic polynomial of A is:'\n", "print 'f = (x-1)(x-2)**2'\n", "print 'i.e., f = ',f\n", - "print '(A-I)(A-2I) = ',(A-sp.eye(3))*(A-2 * sp.eye(3))\n", + "print '(A-I)(A-2I) = ',(A-eye(3))*(A-2 * eye(3))\n", "print 'Since, (A-I)(A-2I) is not equal to 0. T is not diagonalizable. So, Minimal polynomial cannot be p.'\n", "print '---------------------------------------'\n", - "A = np.array([[0, -1],[1, 0]])\n", + "A = array([[0, -1],[1, 0]])\n", "print 'A = \\n',A\n", "f = x**2 + 1#\n", "print 'Characteristic polynomial of A is:'\n", "print 'f = ',f\n", - "print 'A**2 + I = ',A**2 + sp.eye(2)\n", + "print 'A**2 + I = ',A**2 + eye(2)\n", "print 'Since, A**2 + I = 0, so minimal polynomial is'\n", "p = x**2 + 1\n", "print 'p = ',p" @@ -343,7 +343,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 4, "metadata": { "collapsed": false }, @@ -352,7 +352,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "A = \n", + " A = \n", "[[0 1 0 1]\n", " [1 0 1 0]\n", " [0 1 0 1]\n", @@ -381,9 +381,9 @@ } ], "source": [ - "import numpy as np\n", - "import sympy as sp\n", - "A = np.array([[0, 1, 0, 1],[1, 0 ,1 ,0],[0, 1, 0, 1],[1, 0, 1, 0]])\n", + "from numpy import array,transpose,vstack,rank\n", + "from sympy import Symbol,Matrix,eye,solve\n", + "A = array([[0, 1, 0, 1],[1, 0 ,1 ,0],[0, 1, 0, 1],[1, 0, 1, 0]])\n", "print 'A = \\n',A\n", "print 'Computing powers on A:'\n", "print 'A**2 = \\n',A*A\n", @@ -393,12 +393,12 @@ " return pp\n", "print 'if p = x**3 - 4x, then'\n", "print 'p(A) = ',p(A)\n", - "x = sp.Symbol(\"x\")\n", + "x = Symbol(\"x\")\n", "f = x**3 - 4*x\n", "print 'Minimal polynomial for A is: ',f\n", - "print 'Characteristic values for A are:',sp.solve(f,x)\n", - "print 'Rank(A) = ',np.rank(A)\n", - "print 'So, from theorem 2, characteristic polynomial for A is:',sp.Matrix(A).charpoly(x).as_expr()" + "print 'Characteristic values for A are:',solve(f,x)\n", + "print 'Rank(A) = ',rank(A)\n", + "print 'So, from theorem 2, characteristic polynomial for A is:',Matrix(A).charpoly(x).as_expr()" ] }, { @@ -410,7 +410,7 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 2, "metadata": { "collapsed": false }, @@ -420,51 +420,51 @@ "output_type": "stream", "text": [ "A = \n", - "[[ 9. 1. 3.]\n", - " [ 10. 1. 3.]\n", - " [ 10. 5. 1.]]\n", + "[[ 9. 3. 3.]\n", + " [ 7. 4. 4.]\n", + " [ 1. 1. 2.]]\n", "A transpose is:\n", "A' = \n", - "[[ 9. 10. 10.]\n", - " [ 1. 1. 5.]\n", - " [ 3. 3. 1.]]\n", + "[[ 9. 7. 1.]\n", + " [ 3. 4. 1.]\n", + " [ 3. 4. 2.]]\n", "Since, A' is not equal to A, A is not a symmetric matrix.\n", "Since, A' is not equal to -A, A is not a skew-symmetric matrix.\n", "A can be expressed as sum of A1 and A2\n", "i.e., A = A1 + A2\n", "A1 = \n", - "[[ 9. 5.5 6.5]\n", - " [ 5.5 1. 4. ]\n", - " [ 6.5 4. 1. ]]\n", + "[[ 9. 5. 2. ]\n", + " [ 5. 4. 2.5]\n", + " [ 2. 2.5 2. ]]\n", "A2 = \n", - "[[ 0. -4.5 -3.5]\n", - " [ 4.5 0. -1. ]\n", - " [ 3.5 1. 0. ]]\n", + "[[ 0. -2. 1. ]\n", + " [ 2. 0. 1.5]\n", + " [-1. -1.5 0. ]]\n", "A1 + A2 = \n", - "[[ 9. 1. 3.]\n", - " [ 10. 1. 3.]\n", - " [ 10. 5. 1.]]\n" + "[[ 9. 3. 3.]\n", + " [ 7. 4. 4.]\n", + " [ 1. 1. 2.]]\n" ] } ], "source": [ - "import numpy as np\n", + "from numpy import array,transpose,random,equal\n", "\n", - "A = np.random.rand(3,3)\n", + "A = random.rand(3,3)\n", "for i in range(0,3):\n", " for j in range(0,3):\n", " A[i,j]=round(A[i,j]*10)\n", " \n", "print 'A = \\n',A\n", "print 'A transpose is:\\n',\n", - "Adash=np.transpose(A)\n", + "Adash=transpose(A)\n", "print \"A' = \\n\",Adash\n", - "if np.equal(Adash,A).all():\n", + "if equal(Adash,A).all():\n", " print \"Since, A' = A, A is a symmetric matrix.\"\n", "else:\n", " print \"Since, A' is not equal to A, A is not a symmetric matrix.\"\n", "\n", - "if np.equal(Adash,-A).all():\n", + "if equal(Adash,-A).all():\n", " print \"Since, A' = -A, A is a skew-symmetric matrix.\"\n", "else:\n", " print \"Since, A' is not equal to -A, A is not a skew-symmetric matrix.\"\n", |