summaryrefslogtreecommitdiff
path: root/Linear_Algebra_by_K._Hoffman_and_R._Kunze
diff options
context:
space:
mode:
Diffstat (limited to 'Linear_Algebra_by_K._Hoffman_and_R._Kunze')
-rw-r--r--Linear_Algebra_by_K._Hoffman_and_R._Kunze/Chapter10_1.ipynb128
-rw-r--r--Linear_Algebra_by_K._Hoffman_and_R._Kunze/Chapter1_1.ipynb754
-rw-r--r--Linear_Algebra_by_K._Hoffman_and_R._Kunze/Chapter2_1.ipynb822
-rw-r--r--Linear_Algebra_by_K._Hoffman_and_R._Kunze/Chapter3_1.ipynb637
-rw-r--r--Linear_Algebra_by_K._Hoffman_and_R._Kunze/Chapter4_1.ipynb328
-rw-r--r--Linear_Algebra_by_K._Hoffman_and_R._Kunze/Chapter5_1.ipynb358
-rw-r--r--Linear_Algebra_by_K._Hoffman_and_R._Kunze/Chapter6_1.ipynb503
-rw-r--r--Linear_Algebra_by_K._Hoffman_and_R._Kunze/Chapter7_1.ipynb239
-rw-r--r--Linear_Algebra_by_K._Hoffman_and_R._Kunze/Chapter8_1.ipynb561
-rw-r--r--Linear_Algebra_by_K._Hoffman_and_R._Kunze/screenshots/InverseMatrix_1.pngbin0 -> 38657 bytes
-rw-r--r--Linear_Algebra_by_K._Hoffman_and_R._Kunze/screenshots/determinant_1.pngbin0 -> 52303 bytes
-rw-r--r--Linear_Algebra_by_K._Hoffman_and_R._Kunze/screenshots/scalorpolynomial_1.pngbin0 -> 42440 bytes
12 files changed, 4330 insertions, 0 deletions
diff --git a/Linear_Algebra_by_K._Hoffman_and_R._Kunze/Chapter10_1.ipynb b/Linear_Algebra_by_K._Hoffman_and_R._Kunze/Chapter10_1.ipynb
new file mode 100644
index 00000000..1c137a08
--- /dev/null
+++ b/Linear_Algebra_by_K._Hoffman_and_R._Kunze/Chapter10_1.ipynb
@@ -0,0 +1,128 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 10 - Bilinear forms"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Page 363 Example 10.4"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "a = [x1 x2]\n",
+ "b = [y1 y2]\n",
+ "f(a,b) = x1*y1 + x1*y2 + x2*y1 + x2*y2\n",
+ "so, f(a,b) = \n",
+ "[x1 x2] * |1 1| * |y1|\n",
+ " |1 1| |y2|\n",
+ "So the matrix of f in standard order basis B = {e1,e2} is:\n",
+ "[f]B = \n",
+ "[[1 1]\n",
+ " [1 1]]\n",
+ "P = \n",
+ "[[ 1 1]\n",
+ " [-1 1]]\n",
+ "Thus, [f]B = P*[f]B*P\n",
+ "[f]B = \n",
+ "[[ 1 -1]\n",
+ " [-1 1]]\n"
+ ]
+ }
+ ],
+ "source": [
+ "import numpy as np\n",
+ "print 'a = [x1 x2]'\n",
+ "print 'b = [y1 y2]'\n",
+ "print 'f(a,b) = x1*y1 + x1*y2 + x2*y1 + x2*y2'\n",
+ "print 'so, f(a,b) = '\n",
+ "print '[x1 x2] * |1 1| * |y1|'\n",
+ "print ' |1 1| |y2|'\n",
+ "print 'So the matrix of f in standard order basis B = {e1,e2} is:'\n",
+ "fb = np.array([[1, 1],[1, 1]])\n",
+ "print '[f]B = \\n',fb\n",
+ "P = np.array([[1 ,1],[-1, 1]])\n",
+ "print 'P = \\n',P\n",
+ "print 'Thus, [f]B'' = P''*[f]B*P'\n",
+ "fb1 = np.transpose(P) * fb * P\n",
+ "print '[f]B'' = \\n',fb1"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Page 365 Example 10.5"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "n = 56.0\n",
+ "a = 410.0\n",
+ "b = 70.0\n",
+ "f(a,b) = 28700.0\n",
+ "f is non-degenerate billinear form on R**n.\n"
+ ]
+ }
+ ],
+ "source": [
+ "import numpy as np\n",
+ "n = round(np.random.randint(2,90))\n",
+ "a = round(np.random.randint(1,n) * 10)#\n",
+ "b = round(np.random.randint(1,n) * 10)#\n",
+ "print 'n = ',n\n",
+ "print 'a = ',a\n",
+ "print 'b = ',b\n",
+ "f = a * np.transpose(b)\n",
+ "print 'f(a,b) = ',f\n",
+ "print 'f is non-degenerate billinear form on R**n.'\n",
+ "#end"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/Linear_Algebra_by_K._Hoffman_and_R._Kunze/Chapter1_1.ipynb b/Linear_Algebra_by_K._Hoffman_and_R._Kunze/Chapter1_1.ipynb
new file mode 100644
index 00000000..b45b10cf
--- /dev/null
+++ b/Linear_Algebra_by_K._Hoffman_and_R._Kunze/Chapter1_1.ipynb
@@ -0,0 +1,754 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 1 - Linear Equations"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Page 8 Example 1.5"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "a=\n",
+ "[[ 2 -1 3 2]\n",
+ " [ 1 4 0 -1]\n",
+ " [ 2 6 -1 5]]\n",
+ "Applying row transformations:\n",
+ "R1 = R1-2*R2\n",
+ "a = \n",
+ "[[ 0 -9 3 4]\n",
+ " [ 1 4 0 -1]\n",
+ " [ 2 6 -1 5]]\n",
+ "R3 = R3-2*R2\n",
+ "a = \n",
+ "[[ 0 -9 3 4]\n",
+ " [ 1 4 0 -1]\n",
+ " [ 0 -2 -1 7]]\n",
+ "R3 = R3/-2\n",
+ "a = \n",
+ "[[ 0 -9 3 4]\n",
+ " [ 1 4 0 -1]\n",
+ " [ 0 1 0 -3]]\n",
+ "R2 = R2-4*R3\n",
+ "a = \n",
+ "[[ 0 -9 3 4]\n",
+ " [ 1 0 0 11]\n",
+ " [ 0 1 0 -3]]\n",
+ "R1 = R1+9*R3\n",
+ "a = \n",
+ "[[ 0 0 3 -23]\n",
+ " [ 1 0 0 11]\n",
+ " [ 0 1 0 -3]]\n",
+ "R1 = R1*2/15\n",
+ "a = \n",
+ "[[ 0 0 0 -4]\n",
+ " [ 1 0 0 11]\n",
+ " [ 0 1 0 -3]]\n",
+ "R2 = R2+2*R1\n",
+ "a = \n",
+ "[[ 0 0 0 -4]\n",
+ " [ 1 0 0 3]\n",
+ " [ 0 1 0 -3]]\n",
+ "R3 = R3-R1/2\n",
+ "a = \n",
+ "[[ 0 0 0 -4]\n",
+ " [ 1 0 0 3]\n",
+ " [ 0 1 0 -1]]\n",
+ "We get the system of equations as:\n",
+ "2*x1 - x2 + 3*x3 + 2*x4 = 0\n",
+ "x1 + 4*x2 - x4 = 0\n",
+ "2*x1 + 6* x2 - x3 + 5*x4 = 0\n",
+ "and\n",
+ "x2 - 5/3*x4 = 0 x1 + 17/3*x4 = 0 x3 - 11/3*x4 = 0\n",
+ "now by assigning any rational value c to x4 in system second, the solution is evaluated as:\n",
+ "(-17/3*c,5/3,11/3*c,c)\n"
+ ]
+ }
+ ],
+ "source": [
+ "import numpy as np\n",
+ "a = np.array([[2, -1, 3, 2],[1, 4, 0 ,-1],[2, 6, -1, 5]])\n",
+ "print 'a=\\n',a\n",
+ "print 'Applying row transformations:'\n",
+ "print 'R1 = R1-2*R2'\n",
+ "a[0,:] = a[0,:] - 2*a[1,:]#\n",
+ "print 'a = \\n',a\n",
+ "print 'R3 = R3-2*R2'\n",
+ "a[2,:] = a[2,:] - 2*a[1,:]\n",
+ "print 'a = \\n',a\n",
+ "print 'R3 = R3/-2'\n",
+ "a[2,:] = -1.0/2*a[2,:]#\n",
+ "print 'a = \\n',a\n",
+ "print 'R2 = R2-4*R3'\n",
+ "a[1,:] = a[1,:] - 4*a[2,:]\n",
+ "print 'a = \\n',a\n",
+ "print 'R1 = R1+9*R3'\n",
+ "a[0,:] = a[0,:] + 9*a[2,:]#\n",
+ "print 'a = \\n',a\n",
+ "print 'R1 = R1*2/15'\n",
+ "a[0,:] = a[0,:] * 2/15\n",
+ "print 'a = \\n',a\n",
+ "print 'R2 = R2+2*R1'\n",
+ "a[1,:] = a[1,:] + 2*a[0,:]\n",
+ "print 'a = \\n',a\n",
+ "print 'R3 = R3-R1/2'\n",
+ "a[2,:] = a[2,:] - 1.0/2*a[0,:]\n",
+ "print 'a = \\n',a\n",
+ "print 'We get the system of equations as:'\n",
+ "print '2*x1 - x2 + 3*x3 + 2*x4 = 0'\n",
+ "print 'x1 + 4*x2 - x4 = 0'\n",
+ "print '2*x1 + 6* x2 - x3 + 5*x4 = 0'\n",
+ "print 'and'\n",
+ "print 'x2 - 5/3*x4 = 0','x1 + 17/3*x4 = 0','x3 - 11/3*x4 = 0'\n",
+ "print 'now by assigning any rational value c to x4 in system second, the solution is evaluated as:'\n",
+ "print '(-17/3*c,5/3,11/3*c,c)'"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Page 9 Example 1.6"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "a = \n",
+ "[[-1.+0.j 0.+1.j]\n",
+ " [ 0.-1.j 3.+0.j]\n",
+ " [ 1.+0.j 2.+0.j]]\n",
+ "Applying row transformations:\n",
+ "R1 = R1+R3 and R2 = R2 + i *R3\n",
+ "a = \n",
+ "[[ 0.+0.j 2.+1.j]\n",
+ " [ 0.+0.j 3.+2.j]\n",
+ " [ 1.+0.j 2.+0.j]]\n",
+ "R1 = R1 * (1/2+i)\n",
+ "a = \n",
+ "[[ 0.+0.j 1.+0.j]\n",
+ " [ 0.+0.j 3.+2.j]\n",
+ " [ 1.+0.j 2.+0.j]]\n",
+ "R2 = R2-R1*(3+2i) and R3 = R3 - 2 *R1\n",
+ "a = \n",
+ "[[ 0.+0.j 1.+0.j]\n",
+ " [ 0.+0.j 0.+0.j]\n",
+ " [ 1.+0.j 0.+0.j]]\n",
+ "Thus the system of equations is:\n",
+ "x1 + 2*x2 = 0 -i*x1 + 3*x2 = 0 -x1+i*x2 = 0\n",
+ "It has only trivial solution x1 = x2 = 0\n"
+ ]
+ }
+ ],
+ "source": [
+ "import numpy as np\n",
+ "a=np.array([[-1, 1J],[-1J, 3],[1 ,2]])\n",
+ "print 'a = \\n',a\n",
+ "print 'Applying row transformations:'\n",
+ "print 'R1 = R1+R3 and R2 = R2 + i *R3'\n",
+ "a[0,:] = a[0,:] +a[2,:]\n",
+ "a[1,:] = a[1,:] + 1J * a[2,:]\n",
+ "print 'a = \\n',a\n",
+ "print 'R1 = R1 * (1/2+i)'\n",
+ "a[0,:] = 1.0/(2 + 1J) * a[0,:]\n",
+ "print 'a = \\n',a\n",
+ "print 'R2 = R2-R1*(3+2i) and R3 = R3 - 2 *R1'\n",
+ "a[1,:] = (a[1,:] - (3 + 2 * 1J) * a[0,:])\n",
+ "a[2,:] = (a[2,:] - 2 * a[0,:])\n",
+ "print 'a = \\n',a\n",
+ "print 'Thus the system of equations is:'\n",
+ "print 'x1 + 2*x2 = 0','-i*x1 + 3*x2 = 0','-x1+i*x2 = 0'\n",
+ "print 'It has only trivial solution x1 = x2 = 0'"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Page 9 Example 1.7"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "[[ 1. 0. 0. 0. 0. 0. 0. 0.]\n",
+ " [ 0. 1. 0. 0. 0. 0. 0. 0.]\n",
+ " [ 0. 0. 1. 0. 0. 0. 0. 0.]\n",
+ " [ 0. 0. 0. 1. 0. 0. 0. 0.]\n",
+ " [ 0. 0. 0. 0. 1. 0. 0. 0.]\n",
+ " [ 0. 0. 0. 0. 0. 1. 0. 0.]\n",
+ " [ 0. 0. 0. 0. 0. 0. 1. 0.]\n",
+ " [ 0. 0. 0. 0. 0. 0. 0. 1.]]\n",
+ "This is an Identity matrix of order 8 * 8\n",
+ "And It is a row reduced matrix.\n"
+ ]
+ }
+ ],
+ "source": [
+ "import numpy as np\n",
+ "n = np.random.randint(9)\n",
+ "print np.identity(n)\n",
+ "print 'This is an Identity matrix of order %d * %d'%(n,n)\n",
+ "print 'And It is a row reduced matrix.'"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Page 12 Example 1.8"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "[[ 1. 0. 0. 0. 0. 0.]\n",
+ " [ 0. 1. 0. 0. 0. 0.]\n",
+ " [ 0. 0. 1. 0. 0. 0.]\n",
+ " [ 0. 0. 0. 1. 0. 0.]\n",
+ " [ 0. 0. 0. 0. 1. 0.]\n",
+ " [ 0. 0. 0. 0. 0. 1.]]\n",
+ "This is an Identity matrix of order 6 * 6\n",
+ "And It is a row reduced matrix.\n",
+ "[[ 0. 0. 0. 0. 0.]]\n",
+ "This is an Zero matrix of order 1 * 5\n",
+ "And It is also a row reduced matrix.\n",
+ "a = \n",
+ "[[ 0. 1. -3. 0. 0.5]\n",
+ " [ 0. 0. 0. 1. 2. ]\n",
+ " [ 0. 0. 0. 0. 0. ]]\n",
+ "This is a non-trivial row reduced matrix.\n"
+ ]
+ }
+ ],
+ "source": [
+ "import numpy as np\n",
+ "n = np.random.randint(9)\n",
+ "print np.identity(n)\n",
+ "print 'This is an Identity matrix of order %d * %d'%(n,n)\n",
+ "print 'And It is a row reduced matrix.'\n",
+ "m = np.random.randint(0,9)\n",
+ "n = np.random.randint(9)\n",
+ "print np.zeros([m,n])\n",
+ "print 'This is an Zero matrix of order %d * %d'%(m,n)\n",
+ "print 'And It is also a row reduced matrix.'\n",
+ "a = np.array([[0, 1, -3, 0, 1.0/2],[0, 0, 0, 1, 2],[0, 0 ,0 ,0 ,0]])\n",
+ "print 'a = \\n',a\n",
+ "print 'This is a non-trivial row reduced matrix.'\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Page 14 Example 1.9"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "A = \n",
+ "[[ 1 -2 1]\n",
+ " [ 2 1 1]\n",
+ " [ 0 5 -1]]\n",
+ "Applying row transformations:\n",
+ "R2 = R2 - 2*R1\n",
+ "A = \n",
+ "[[ 1 -2 1]\n",
+ " [ 0 5 -1]\n",
+ " [ 0 5 -1]]\n",
+ "R3 = R3 - R2\n",
+ "A = \n",
+ "[[ 1 -2 1]\n",
+ " [ 0 5 -1]\n",
+ " [ 0 0 0]]\n",
+ "R2 = 1/5*R2\n",
+ "A = \n",
+ "[[ 1 -2 1]\n",
+ " [ 0 1 0]\n",
+ " [ 0 0 0]]\n",
+ "R1 = R1 - 2*R2\n",
+ "A = \n",
+ "[[1 0 1]\n",
+ " [0 1 0]\n",
+ " [0 0 0]]\n",
+ "The condition that the system have a solution is:\n",
+ "2*y1 - y2 + y3 = 0\n",
+ "where, y1,y2,y3 are some scalars\n",
+ "If the condition is satisfied then solutions are obtained by assigning a value c to x3\n",
+ "Solutions are:\n",
+ "x2 = 1/5*c + 1/5*(y2 - 2*y1) x1 = -3/5*c + 1/5*(y1 + 2*y2)\n"
+ ]
+ }
+ ],
+ "source": [
+ "import numpy as np\n",
+ "A = np.array([[1, -2, 1],[2, 1, 1],[0, 5, -1]])\n",
+ "print 'A = \\n',A\n",
+ "print 'Applying row transformations:'\n",
+ "print 'R2 = R2 - 2*R1'\n",
+ "A[1,:] = A[1,:] - 2*A[0,:]\n",
+ "print 'A = \\n',A\n",
+ "print 'R3 = R3 - R2'\n",
+ "A[2,:] = A[2,:] - A[1,:]\n",
+ "print 'A = \\n',A\n",
+ "print 'R2 = 1/5*R2'\n",
+ "A[1,:] = 1.0/5*A[1,:]\n",
+ "print 'A = \\n',A\n",
+ "print 'R1 = R1 - 2*R2'\n",
+ "A[0,:] = A[0,:] + 2*A[1,:]\n",
+ "print 'A = \\n',A\n",
+ "print 'The condition that the system have a solution is:'\n",
+ "print '2*y1 - y2 + y3 = 0'\n",
+ "print 'where, y1,y2,y3 are some scalars'\n",
+ "print 'If the condition is satisfied then solutions are obtained by assigning a value c to x3'\n",
+ "print 'Solutions are:'\n",
+ "print 'x2 = 1/5*c + 1/5*(y2 - 2*y1)','x1 = -3/5*c + 1/5*(y1 + 2*y2)'"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Page 17 Example 1.10"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 6,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "a=\n",
+ "[[ 1 0]\n",
+ " [-3 1]]\n",
+ "b=\n",
+ "[[ 5 -1 2]\n",
+ " [15 4 8]]\n",
+ "ab = \n",
+ "[[ 5 -1 2]\n",
+ " [ 0 7 2]]\n",
+ "-----------------------------------------------------------------\n",
+ "a=\n",
+ "[[ 1 0]\n",
+ " [-2 3]\n",
+ " [ 5 4]\n",
+ " [ 0 1]]\n",
+ "b=\n",
+ "[[ 0 6 1]\n",
+ " [ 3 8 -2]]\n",
+ "ab = \n",
+ "[[ 0 6 1]\n",
+ " [ 9 12 -8]\n",
+ " [12 62 -3]\n",
+ " [ 3 8 -2]]\n",
+ "-----------------------------------------------------------------\n",
+ "a=\n",
+ "[[2 1]\n",
+ " [5 4]]\n",
+ "b=\n",
+ "[[1]\n",
+ " [6]]\n",
+ "ab = \n",
+ "[[ 8]\n",
+ " [29]]\n",
+ "-----------------------------------------------------------------\n",
+ "a=\n",
+ "[[-1]\n",
+ " [ 3]]\n",
+ "b=\n",
+ "[[2 4]]\n",
+ "ab = \n",
+ "[[-2 -4]\n",
+ " [ 6 12]]\n",
+ "-----------------------------------------------------------------\n",
+ "a=\n",
+ "[[2 4]]\n",
+ "b=\n",
+ "[[-1]\n",
+ " [ 3]]\n",
+ "ab = \n",
+ "[[10]]\n",
+ "-----------------------------------------------------------------\n",
+ "a=\n",
+ "[[0 1 0]\n",
+ " [0 0 0]\n",
+ " [0 0 0]]\n",
+ "b=\n",
+ "[[ 1 -5 2]\n",
+ " [ 2 3 4]\n",
+ " [ 9 -1 3]]\n",
+ "ab = \n",
+ "[[2 3 4]\n",
+ " [0 0 0]\n",
+ " [0 0 0]]\n",
+ "-----------------------------------------------------------------\n",
+ "a=\n",
+ "[[ 1 -5 2]\n",
+ " [ 2 3 4]\n",
+ " [ 9 -1 3]]\n",
+ "b=\n",
+ "[[0 1 0]\n",
+ " [0 0 0]\n",
+ " [0 0 0]]\n",
+ "ab = \n",
+ "[[0 1 0]\n",
+ " [0 2 0]\n",
+ " [0 9 0]]\n"
+ ]
+ }
+ ],
+ "source": [
+ "import numpy as np\n",
+ "#Part a\n",
+ "a = np.array([[1, 0],[-3, 1]])\n",
+ "b = np.array([[5, -1, 2],[15, 4, 8]])\n",
+ "print 'a=\\n',a\n",
+ "print 'b=\\n',b\n",
+ "print 'ab = \\n',a.dot(b)\n",
+ "\n",
+ "print '-----------------------------------------------------------------'\n",
+ "#Part b\n",
+ "a = np.array([[1, 0],[-2, 3],[5 ,4],[0, 1]])\n",
+ "b = np.array([[0, 6, 1],[3 ,8 ,-2]])\n",
+ "print 'a=\\n',a\n",
+ "print 'b=\\n',b\n",
+ "print 'ab = \\n',a.dot(b)\n",
+ "print '-----------------------------------------------------------------'\n",
+ "#Part c\n",
+ "a = np.array([[2, 1],[5, 4]])\n",
+ "b = np.array([[1],[6]])\n",
+ "print 'a=\\n',a\n",
+ "print 'b=\\n',b\n",
+ "print 'ab = \\n',a.dot(b)\n",
+ "print '-----------------------------------------------------------------'\n",
+ "#Part d\n",
+ "a = np.array([[-1],[3]])\n",
+ "b = np.array([[2, 4]])\n",
+ "print 'a=\\n',a\n",
+ "print 'b=\\n',b\n",
+ "print 'ab = \\n',a.dot(b)\n",
+ "print '-----------------------------------------------------------------'\n",
+ "#Part e\n",
+ "a = np.array([[2, 4]])\n",
+ "b = np.array([[-1],[3]])\n",
+ "print 'a=\\n',a\n",
+ "print 'b=\\n',b\n",
+ "print 'ab = \\n',a.dot(b)\n",
+ "print '-----------------------------------------------------------------'\n",
+ "#Part f\n",
+ "a = np.array([[0, 1 ,0],[0, 0, 0],[0, 0, 0]])\n",
+ "b = np.array([[1, -5, 2],[2, 3, 4],[9 ,-1, 3]])\n",
+ "print 'a=\\n',a\n",
+ "print 'b=\\n',b\n",
+ "print 'ab = \\n',a.dot(b)\n",
+ "print '-----------------------------------------------------------------'\n",
+ "#Part g\n",
+ "a = np.array([[1, -5, 2],[2, 3, 4],[9, -1, 3]])\n",
+ "b = np.array([[0, 1, 0],[0 ,0 ,0],[0, 0, 0]])\n",
+ "print 'a=\\n',a\n",
+ "print 'b=\\n',b\n",
+ "print 'ab = \\n',a.dot(b)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Page 22 Example 1.14"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 7,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "a = \n",
+ "[[0 1]\n",
+ " [1 0]]\n",
+ "inverse a = \n",
+ "[[ 0. 1.]\n",
+ " [ 1. 0.]]\n"
+ ]
+ }
+ ],
+ "source": [
+ "import numpy as np\n",
+ "a = np.array([[0, 1],[1, 0]])\n",
+ "print 'a = \\n',a\n",
+ "print 'inverse a = \\n',np.linalg.inv(a)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Page 25 Example 1.15"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 25,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "a = \n",
+ "[[ 2 -1]\n",
+ " [ 1 3]]\n",
+ "Applying row tranformations\n",
+ "Interchange R1 and R2\n",
+ "a = \n",
+ "[[ 1 3]\n",
+ " [ 2 -1]]\n",
+ "R2 = R2 - 2 * R1\n",
+ "a =\n",
+ " [[ 1 3]\n",
+ " [ 0 -7]]\n",
+ "R2 = R2 *1/(-7)\n",
+ "a = \n",
+ "[[1 3]\n",
+ " [0 1]]\n",
+ "R1 = R1 - 3 * R2\n",
+ "a = \n",
+ "[[1 0]\n",
+ " [0 1]]\n",
+ "Since a has become an identity matrix. So, a is invertible\n",
+ "inverse of a = \n",
+ "[[ 0.42857143 0.14285714]\n",
+ " [-0.14285714 0.28571429]]\n"
+ ]
+ }
+ ],
+ "source": [
+ "import numpy as np\n",
+ "a = np.array([[2, -1],[1 ,3]])\n",
+ "b = np.array([[2, -1],[1 ,3]]) #Temporary variable to store a\n",
+ "print 'a = \\n',a\n",
+ "print 'Applying row tranformations'\n",
+ "print 'Interchange R1 and R2'\n",
+ "a[0,:] = a[1,:]\n",
+ "a[1,:] = b[0,:]\n",
+ "print 'a = \\n',a\n",
+ "print 'R2 = R2 - 2 * R1'\n",
+ "a[1,:] = a[1,:] - 2 * a[0,:]\n",
+ "print 'a =\\n ',a\n",
+ "print 'R2 = R2 *1/(-7)'\n",
+ "a[1,:] = (-1.0/7) * a[1,:]\n",
+ "print 'a = \\n',a\n",
+ "print 'R1 = R1 - 3 * R2'\n",
+ "a[0,:] = a[0,:] - 3 * a[1,:]\n",
+ "print 'a = \\n',a\n",
+ "print 'Since a has become an identity matrix. So, a is invertible'\n",
+ "print 'inverse of a = '\n",
+ "print np.linalg.inv(b)# #a was stored in b"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Page 25 Example 1.16"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 26,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "a = \n",
+ "[[ 1. 0.5 0.33333333]\n",
+ " [ 0.5 0.33333333 0.25 ]\n",
+ " [ 0.33333333 0.25 0.2 ]]\n",
+ "b = \n",
+ "[[ 1. 0. 0.]\n",
+ " [ 0. 1. 0.]\n",
+ " [ 0. 0. 1.]]\n",
+ "Applying row transformations on a and b simultaneously,\n",
+ "R2 = R2 - 1/2 * R1 and R3 = R3 - 1/3*R1\n",
+ "a = \n",
+ "[[ 1. 0.5 0.33333333]\n",
+ " [ 0. 0.08333333 0.08333333]\n",
+ " [ 0. 0.08333333 0.08888889]]\n",
+ "b = \n",
+ "[[ 1. 0. 0. ]\n",
+ " [-0.5 1. 0. ]\n",
+ " [-0.33333333 0. 1. ]]\n",
+ "R3 = R3 - R2\n",
+ "a = \n",
+ "[[ 1.00000000e+00 5.00000000e-01 3.33333333e-01]\n",
+ " [ 0.00000000e+00 8.33333333e-02 8.33333333e-02]\n",
+ " [ 0.00000000e+00 2.77555756e-17 5.55555556e-03]]\n",
+ "b = \n",
+ "[[ 1. 0. 0. ]\n",
+ " [-0.5 1. 0. ]\n",
+ " [ 0.16666667 -1. 1. ]]\n",
+ "R2 = R2 * 12 and R3 = R3 * 180\n",
+ "a = \n",
+ "[[ 1.00000000e+00 5.00000000e-01 3.33333333e-01]\n",
+ " [ 0.00000000e+00 1.00000000e+00 1.00000000e+00]\n",
+ " [ 0.00000000e+00 4.99600361e-15 1.00000000e+00]]\n",
+ "b = \n",
+ "[[ 1. 0. 0.]\n",
+ " [ -6. 12. 0.]\n",
+ " [ 30. -180. 180.]]\n",
+ "R2 = R2 - R3 and R1 = R1 - 1/3*R3\n",
+ "a = \n",
+ "[[ 1.00000000e+00 5.00000000e-01 -4.44089210e-16]\n",
+ " [ 0.00000000e+00 1.00000000e+00 -1.33226763e-15]\n",
+ " [ 0.00000000e+00 4.99600361e-15 1.00000000e+00]]\n",
+ "b = \n",
+ "[[ -9. 60. -60.]\n",
+ " [ -36. 192. -180.]\n",
+ " [ 30. -180. 180.]]\n",
+ "R1 = R1 - 1/2 * R2\n",
+ "a = \n",
+ "[[ 1. 0. 0.]\n",
+ " [ 0. 1. -0.]\n",
+ " [ 0. 0. 1.]]\n",
+ "b = \n",
+ "[[ 9. -36. 30.]\n",
+ " [ -36. 192. -180.]\n",
+ " [ 30. -180. 180.]]\n",
+ "Since, a = identity matrix of order 3*3. So, b is inverse of a\n",
+ "inverse(a) = \n",
+ "[[ 9. -36. 30.]\n",
+ " [ -36. 192. -180.]\n",
+ " [ 30. -180. 180.]]\n"
+ ]
+ }
+ ],
+ "source": [
+ "import numpy as np\n",
+ "a = np.array([[1 ,1./2, 1.0/3],[1.0/2 ,1.0/3, 1.0/4],[1.0/3, 1.0/4, 1.0/5]])\n",
+ "print 'a = \\n',a\n",
+ "b = np.identity(3)\n",
+ "print 'b = \\n',b\n",
+ "print 'Applying row transformations on a and b simultaneously,'\n",
+ "print 'R2 = R2 - 1/2 * R1 and R3 = R3 - 1/3*R1'\n",
+ "a[1,:] = a[1,:] - 1.0/2 * a[0,:]\n",
+ "a[2,:] = a[2,:] - 1.0/3 * a[0,:]\n",
+ "b[1,:] = b[1,:] - 1.0/2 * b[0,:]\n",
+ "b[2,:] = b[2,:] - 1.0/3 * b[0,:]\n",
+ "print 'a = \\n',a\n",
+ "print 'b = \\n',b\n",
+ "print 'R3 = R3 - R2'\n",
+ "a[2,:] = a[2,:] - a[1,:]#\n",
+ "b[2,:] = b[2,:] - b[1,:]\n",
+ "print 'a = \\n',a\n",
+ "print 'b = \\n',b\n",
+ "print 'R2 = R2 * 12 and R3 = R3 * 180'\n",
+ "a[1,:] = a[1,:] *12#\n",
+ "a[2,:] = a[2,:] * 180#\n",
+ "b[1,:] = b[1,:] * 12#\n",
+ "b[2,:] = b[2,:] * 180#\n",
+ "print 'a = \\n',a\n",
+ "print 'b = \\n',b\n",
+ "print 'R2 = R2 - R3 and R1 = R1 - 1/3*R3'\n",
+ "a[1,:] = a[1,:] - a[2,:]#\n",
+ "a[0,:] = a[0,:] - 1./3 * a[2,:]#\n",
+ "b[1,:] = b[1,:] - b[2,:]#\n",
+ "b[0,:] = b[0,:] - 1./3 * b[2,:]#\n",
+ "print 'a = \\n',a\n",
+ "print 'b = \\n',b\n",
+ "print 'R1 = R1 - 1/2 * R2'\n",
+ "a[0,:] = a[0,:] - 1./2 * a[1,:]#\n",
+ "b[0,:] = b[0,:] - 1./2 * b[1,:]#\n",
+ "print 'a = \\n',np.matrix.round(a)\n",
+ "print 'b = \\n',b\n",
+ "print 'Since, a = identity matrix of order 3*3. So, b is inverse of a'\n",
+ "print 'inverse(a) = \\n',b"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/Linear_Algebra_by_K._Hoffman_and_R._Kunze/Chapter2_1.ipynb b/Linear_Algebra_by_K._Hoffman_and_R._Kunze/Chapter2_1.ipynb
new file mode 100644
index 00000000..cac42c12
--- /dev/null
+++ b/Linear_Algebra_by_K._Hoffman_and_R._Kunze/Chapter2_1.ipynb
@@ -0,0 +1,822 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 2 - Vector spaces"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Page 37 Example 2.8"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "a1 = [1, 2, 0, 3, 0]\n",
+ "a2 = [0, 0, 1, 4, 0]\n",
+ "a3 = [0, 0, 0, 0, 1]\n",
+ "By theorem 3, vector a is in subspace W of F**5 spanned by a1, a2, a3\n",
+ "if and only if there exist scalars c1, c2, c3 such that\n",
+ "a= c1a1 + c2a2 + c3a3\n",
+ "So, a = (c1,2*c1,c2,3c1+4c2,c3)\n",
+ "c1 = -3\n",
+ "c2 = 1\n",
+ "c3 = 2\n",
+ "Therefore, a = [0, 0, 1, 4, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]\n",
+ "This shows, a is in W\n",
+ "And (2,4,6,7,8) is not in W as there is no value of c1 c2 c3 that satisfies the equation\n"
+ ]
+ }
+ ],
+ "source": [
+ "\n",
+ "a1 = [1, 2 ,0 ,3, 0]#\n",
+ "a2 =[0, 0 ,1 ,4 ,0]#\n",
+ "a3 = [0 ,0 ,0 ,0, 1]#\n",
+ "print 'a1 = ',a1\n",
+ "print 'a2 = ',a2\n",
+ "print 'a3 = ',a3\n",
+ "print 'By theorem 3, vector a is in subspace W of F**5 spanned by a1, a2, a3'\n",
+ "print 'if and only if there exist scalars c1, c2, c3 such that'\n",
+ "print 'a= c1a1 + c2a2 + c3a3'\n",
+ "print 'So, a = (c1,2*c1,c2,3c1+4c2,c3)'\n",
+ "c1 = -3#\n",
+ "c2 = 1#\n",
+ "c3 = 2#\n",
+ "a = c1*a1 + c2*a2 + c3*a3#\n",
+ "print 'c1 = ',c1\n",
+ "print 'c2 = ',c2\n",
+ "print 'c3 = ',c3\n",
+ "print 'Therefore, a = ',a\n",
+ "print 'This shows, a is in W'\n",
+ "print 'And (2,4,6,7,8) is not in W as there is no value of c1 c2 c3 that satisfies the equation'"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Page 38 Example 2.10"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "A = \n",
+ "[[1 2 0 3 0]\n",
+ " [0 0 1 4 0]\n",
+ " [0 0 0 0 1]]\n",
+ "The subspace of F**5 spanned by a1 a2 a3(row vectors of A) is called row space of A.\n",
+ "a1 = [1 2 0 3 0]\n",
+ "a2 = [0 0 1 4 0]\n",
+ "a3 = [0 0 0 0 1]\n",
+ "And, it is also the row space of B.\n",
+ "B = \n",
+ "[[ 1 2 0 3 0]\n",
+ " [ 0 0 1 4 0]\n",
+ " [ 0 0 0 0 1]\n",
+ " [-4 -8 1 -8 0]]\n"
+ ]
+ }
+ ],
+ "source": [
+ "import numpy as np\n",
+ "\n",
+ "A = np.array([[1, 2, 0 ,3 ,0],[0, 0, 1, 4, 0],[0, 0, 0, 0, 1]])\n",
+ "print 'A = \\n',A\n",
+ "print 'The subspace of F**5 spanned by a1 a2 a3(row vectors of A) is called row space of A.'\n",
+ "a1 = A[0,:]\n",
+ "a2 = A[1,:]\n",
+ "a3 = A[2,:]\n",
+ "print 'a1 = ',a1\n",
+ "print 'a2 = ',a2\n",
+ "print 'a3 = ',a3\n",
+ "print 'And, it is also the row space of B.'\n",
+ "B = np.array([[1, 2, 0, 3, 0],[0, 0, 1, 4, 0],[0, 0, 0, 0, 1],[-4, -8, 1 ,-8, 0]])\n",
+ "print 'B = \\n',B"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Page 39 Example 2.11"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "V is the space of all polynomial functions over F.\n",
+ "S contains the functions as:\n",
+ "n = 17\n",
+ "f0(x) = 1\n",
+ "f1(x) = x\n",
+ "f2(x) = x**2\n",
+ "f3(x) = x**3\n",
+ "f4(x) = x**4\n",
+ "f5(x) = x**5\n",
+ "f6(x) = x**6\n",
+ "f7(x) = x**7\n",
+ "f8(x) = x**8\n",
+ "f9(x) = x**9\n",
+ "f10(x) = x**10\n",
+ "f11(x) = x**11\n",
+ "f12(x) = x**12\n",
+ "f13(x) = x**13\n",
+ "f14(x) = x**14\n",
+ "f15(x) = x**15\n",
+ "f16(x) = x**16\n",
+ "Then, V is the subspace spanned by set S.\n"
+ ]
+ }
+ ],
+ "source": [
+ "import sympy as sp\n",
+ "import numpy as np\n",
+ "print 'V is the space of all polynomial functions over F.'\n",
+ "print 'S contains the functions as:'\n",
+ "x = sp.Symbol(\"x\")\n",
+ "#n = round(rand()*10)#\n",
+ "n=np.random.randint(0,19)\n",
+ "print 'n = ',n\n",
+ "for i in range (0,n):\n",
+ " f = x**i#\n",
+ " print 'f%d(x) = '%(i,),f\n",
+ " \n",
+ "\n",
+ "print 'Then, V is the subspace spanned by set S.'"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Page 41 Example 2.12"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "a1 = [ 3 0 -3]\n",
+ "a2 = [-1 1 2]\n",
+ "a3 = [ 4 2 -2]\n",
+ "a4 = [2 1 1]\n",
+ " Since, 2 * a1 + 2 * a2 - a3 + 0 * a4 = [0 0 0] = 0\n",
+ "a1,a2,a3,a4 are linearly independent\n",
+ "Now, e1 = [1, 0, 0]\n",
+ "e2 = [0, 1, 0]\n",
+ "e3 = [0, 0, 1]\n",
+ "Also, e1,e2,e3 are linearly independent.\n"
+ ]
+ }
+ ],
+ "source": [
+ "import numpy as np\n",
+ "a1 = np.array([3 ,0, -3])\n",
+ "a2 = np.array([-1 ,1 ,2])\n",
+ "a3 = np.array([4 ,2, -2])\n",
+ "a4 = np.array([2 ,1, 1])\n",
+ "print 'a1 = ',a1\n",
+ "print 'a2 = ',a2\n",
+ "print 'a3 = ',a3\n",
+ "print 'a4 = ',a4\n",
+ "t = 2 * a1 + 2 * a2 - a3 + 0 * a4\n",
+ "print ' Since, 2 * a1 + 2 * a2 - a3 + 0 * a4 = ',t,'= 0'\n",
+ "print 'a1,a2,a3,a4 are linearly independent'\n",
+ "e1 = [1, 0, 0]#\n",
+ "e2 = [0 ,1 ,0]#\n",
+ "e3 = [0 ,0, 1]#\n",
+ "print 'Now, e1 = ',e1\n",
+ "print 'e2 = ',e2\n",
+ "print 'e3 = ',e3\n",
+ "print 'Also, e1,e2,e3 are linearly independent.'"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Page 41 Example 2.13"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "S is the subset of F**n consisting of n vectors.\n",
+ "n = 10\n",
+ "e1 = \n",
+ "[ 1. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n",
+ "e2 = \n",
+ "[ 0. 1. 0. 0. 0. 0. 0. 0. 0. 0.]\n",
+ "e3 = \n",
+ "[ 0. 0. 1. 0. 0. 0. 0. 0. 0. 0.]\n",
+ "e4 = \n",
+ "[ 0. 0. 0. 1. 0. 0. 0. 0. 0. 0.]\n",
+ "e5 = \n",
+ "[ 0. 0. 0. 0. 1. 0. 0. 0. 0. 0.]\n",
+ "e6 = \n",
+ "[ 0. 0. 0. 0. 0. 1. 0. 0. 0. 0.]\n",
+ "e7 = \n",
+ "[ 0. 0. 0. 0. 0. 0. 1. 0. 0. 0.]\n",
+ "e8 = \n",
+ "[ 0. 0. 0. 0. 0. 0. 0. 1. 0. 0.]\n",
+ "e9 = \n",
+ "[ 0. 0. 0. 0. 0. 0. 0. 0. 1. 0.]\n",
+ "e10 = \n",
+ "[ 0. 0. 0. 0. 0. 0. 0. 0. 0. 1.]\n",
+ "x1,x2,x3...xn are the scalars in F\n",
+ "Putting a = x1*e1 + x2*e2 + x3*e3 + .... + xn*en\n",
+ "So, a = (x1,x2,x3,...,xn)\n",
+ "Therefore, e1,e2..,en span F**n\n",
+ "a = 0 if x1 = x2 = x3 = .. = xn = 0\n",
+ "So,e1,e2,e3,..,en are linearly independent.\n",
+ "The set S = {e1,e2,..,en} is called standard basis of F**n\n"
+ ]
+ }
+ ],
+ "source": [
+ "import numpy as np\n",
+ "print 'S is the subset of F**n consisting of n vectors.'\n",
+ "#n = round(rand() *10 + 1)#\\\n",
+ "n=np.random.randint(0,19)\n",
+ "print 'n = ',n\n",
+ "I = np.identity(n)\n",
+ "for i in range(0,n):\n",
+ " e = I[i,:]\n",
+ " print 'e%d = '%(i+1)\n",
+ " print e\n",
+ "\n",
+ "print 'x1,x2,x3...xn are the scalars in F'\n",
+ "print 'Putting a = x1*e1 + x2*e2 + x3*e3 + .... + xn*en'\n",
+ "print 'So, a = (x1,x2,x3,...,xn)'\n",
+ "print 'Therefore, e1,e2..,en span F**n'\n",
+ "print 'a = 0 if x1 = x2 = x3 = .. = xn = 0'\n",
+ "print 'So,e1,e2,e3,..,en are linearly independent.'\n",
+ "print 'The set S = {e1,e2,..,en} is called standard basis of F**n'"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Page 54 Example 2.20"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 6,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "P = \n",
+ "[[-1 4 5]\n",
+ " [ 0 2 -3]\n",
+ " [ 0 0 8]]\n",
+ "\n",
+ "inverse(P) = \n",
+ "[[-1. 2. 1.375 ]\n",
+ " [ 0. 0.5 0.1875]\n",
+ " [ 0. 0. 0.125 ]]\n",
+ "The vectors forming basis of F**3 are a1, a2, a3\n",
+ "a1' = \n",
+ "[-1 0 0]\n",
+ "\n",
+ "a2' = \n",
+ "[4 2 0]\n",
+ "\n",
+ "a3' = \n",
+ "[ 5 -3 8]\n",
+ "The coordinates x1,x2,x3 of vector a = [x1,x2,x3] is given by inverse(P)*[x1# x2# x3]\n",
+ "And, -10*a1 - 1/2*a2 - a3 = [ 3. 2. -8.]\n"
+ ]
+ }
+ ],
+ "source": [
+ "import numpy as np\n",
+ "P = np.array([[-1, 4, 5],[ 0, 2, -3],[ 0, 0, 8]])\n",
+ "print 'P = \\n',P\n",
+ "print '\\ninverse(P) = \\n',np.linalg.inv(P)\n",
+ "a1 = P[:,0]\n",
+ "a2 = P[:,1]\n",
+ "a3 = P[:,2]\n",
+ "print 'The vectors forming basis of F**3 are a1'', a2'', a3'''\n",
+ "print \"a1' = \\n\",np.transpose(a1)\n",
+ "print \"\\na2' = \\n\",np.transpose(a2)\n",
+ "print \"\\na3' = \\n\",np.transpose(a3)\n",
+ "print 'The coordinates x1'',x2'',x3'' of vector a = [x1,x2,x3] is given by inverse(P)*[x1# x2# x3]'\n",
+ "t = -10*a1 - 1./2*a2 - a3#\n",
+ "print 'And, -10*a1'' - 1/2*a2'' - a3'' = ',t"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Page 60 Example 2.21"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 7,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Given row vectors are:\n",
+ "a1 = [1, 2, 2, 1]\n",
+ "a2 = [0, 2, 0, 1]\n",
+ "a3 = [-2, 0, -4, 3]\n",
+ "The matrix A from these vectors will be:\n",
+ "A = \n",
+ "[[ 1 2 2 1]\n",
+ " [ 0 2 0 1]\n",
+ " [-2 0 -4 3]]\n",
+ "Finding Row reduced echelon matrix of A that is given by R\n",
+ "And applying same operations on identity matrix Q such that R = QA\n",
+ "Q = \n",
+ "[[ 1. 0. 0.]\n",
+ " [ 0. 1. 0.]\n",
+ " [ 0. 0. 1.]]\n",
+ "Applying row transformations on A and Q,we get\n",
+ "R1 = R1-R2\n",
+ "A = \n",
+ "[[ 1 0 2 0]\n",
+ " [ 0 2 0 1]\n",
+ " [-2 0 -4 3]]\n",
+ "Q = \n",
+ "[[ 1. -1. 0.]\n",
+ " [ 0. 1. 0.]\n",
+ " [ 0. 0. 1.]]\n",
+ "R3 = R3 + 2*R1\n",
+ "A = \n",
+ "[[1 0 2 0]\n",
+ " [0 2 0 1]\n",
+ " [0 0 0 3]]\n",
+ "Q = \n",
+ "[[ 1. -1. 0.]\n",
+ " [ 0. 1. 0.]\n",
+ " [ 2. -2. 1.]]\n",
+ "R3 = R3/3\n",
+ "A = \n",
+ "[[1 0 2 0]\n",
+ " [0 2 0 1]\n",
+ " [0 0 0 1]]\n",
+ "Q = \n",
+ "[[ 1. -1. 0. ]\n",
+ " [ 0. 1. 0. ]\n",
+ " [ 0.66666667 -0.66666667 0.33333333]]\n",
+ "R2 = R2/2\n",
+ "A = \n",
+ "[[1 0 2 0]\n",
+ " [0 1 0 0]\n",
+ " [0 0 0 1]]\n",
+ "Q = \n",
+ "[[ 1. -1. 0. ]\n",
+ " [ 0. 5. 0. ]\n",
+ " [ 0.66666667 -0.66666667 0.33333333]]\n",
+ "R2 = R2 - 1/2*R3\n",
+ "A = \n",
+ "[[1 0 2 0]\n",
+ " [0 1 0 0]\n",
+ " [0 0 0 1]]\n",
+ "Q = \n",
+ "[[ 1. -1. 0. ]\n",
+ " [-0.33333333 5.33333333 -0.16666667]\n",
+ " [ 0.66666667 -0.66666667 0.33333333]]\n",
+ "Row reduced echelon matrix:\n",
+ "A = \n",
+ "[[1 0 2 0]\n",
+ " [0 1 0 0]\n",
+ " [0 0 0 1]]\n",
+ "Q = \n",
+ "[[ 1. -1. 0. ]\n",
+ " [-0.33333333 5.33333333 -0.16666667]\n",
+ " [ 0.66666667 -0.66666667 0.33333333]]\n",
+ "rank of R = 2\n",
+ "Since, Rank of R is 3, so a1, a2, a3 are independent\n",
+ "Now, basis for W can be given by row vectors of R i.e. p1,p2,p3\n",
+ "b is any vector in W. b = [b1 b2 b3 b4]\n",
+ "Span of vectors p1,p2,p3 consist of vector b with b3 = 2*b1\n",
+ "So,b = b1p1 + b2p2 + b4p3\n",
+ "And,[p1 p2 p3] = R = Q*A\n",
+ "So, b = [b1 b2 b3]* Q * A\n",
+ "hence, b = x1a1 + x2a2 + x3a3 where x1 = [b1 b2 b4] * Q(1) and so on\n",
+ "Now, given 3 vectors a1 a2 a3:\n",
+ "a1 = [1, 0, 2, 0]\n",
+ "a2 = [0, 2, 0, 1]\n",
+ "a3 = [0, 0, 0, 3]\n",
+ "Since a1 a2 a3 are all of the form (y1 y2 y3 y4) with y3 = 2*y1, hence they are in W.\n",
+ "So, they are independent.\n",
+ "Required matrix P such that X = PX is:\n",
+ "P = \n",
+ "[[ 0. -0. 2.]\n",
+ " [-0. 0. -2.]\n",
+ " [ 0. -0. 1.]]\n"
+ ]
+ }
+ ],
+ "source": [
+ "import numpy as np\n",
+ "a1 = [1 ,2 ,2, 1]#\n",
+ "a2 = [0 ,2 ,0 ,1]#\n",
+ "a3 = [-2, 0, -4, 3]#\n",
+ "print 'Given row vectors are:'\n",
+ "print 'a1 = ',a1\n",
+ "print 'a2 = ',a2\n",
+ "print 'a3 = ',a3\n",
+ "print 'The matrix A from these vectors will be:'\n",
+ "#A = [a1],[a2], [a3]]\n",
+ "A=np.array([a1,a2,a3])\n",
+ "print 'A = \\n',A\n",
+ "\n",
+ "print 'Finding Row reduced echelon matrix of A that is given by R'\n",
+ "print 'And applying same operations on identity matrix Q such that R = QA'\n",
+ "Q = np.identity(3)\n",
+ "print 'Q = \\n',Q\n",
+ "T = A# #Temporary matrix to store A\n",
+ "print 'Applying row transformations on A and Q,we get'\n",
+ "print 'R1 = R1-R2'\n",
+ "A[0,:] = A[0,:] - A[1,:]\n",
+ "Q[0,:] = Q[0,:] - Q[1,:]\n",
+ "print 'A = \\n',A\n",
+ "print 'Q = \\n',Q\n",
+ "print 'R3 = R3 + 2*R1'\n",
+ "A[2,:] = A[2,:] + 2*A[0,:]\n",
+ "Q[2,:] = Q[2,:] + 2*Q[0,:]\n",
+ "print 'A = \\n',A\n",
+ "print 'Q = \\n',Q\n",
+ "print 'R3 = R3/3'\n",
+ "A[2,:] = 1./3*A[2,:]\n",
+ "Q[2,:] = 1./3*Q[2,:]\n",
+ "print 'A = \\n',A\n",
+ "print 'Q = \\n',Q\n",
+ "print 'R2 = R2/2'\n",
+ "A[1,:] = 1./2*A[1,:]\n",
+ "Q[1,:] = 10/2*Q[1,:]\n",
+ "print 'A = \\n',A\n",
+ "print 'Q = \\n',Q\n",
+ "print 'R2 = R2 - 1/2*R3'\n",
+ "A[1,:] = A[1,:] - 1./2*A[2,:]\n",
+ "Q[1,:] = Q[1,:] - 1./2*Q[2,:]\n",
+ "print 'A = \\n',A\n",
+ "print 'Q = \\n',Q\n",
+ "R = A#\n",
+ "A = T#\n",
+ "print 'Row reduced echelon matrix:'\n",
+ "print 'A = \\n',A\n",
+ "print 'Q = \\n',Q\n",
+ "#part a\n",
+ "print 'rank of R = ',np.rank(R)\n",
+ "\n",
+ "print 'Since, Rank of R is 3, so a1, a2, a3 are independent'\n",
+ "#part b\n",
+ "print 'Now, basis for W can be given by row vectors of R i.e. p1,p2,p3'\n",
+ "print 'b is any vector in W. b = [b1 b2 b3 b4]'\n",
+ "print 'Span of vectors p1,p2,p3 consist of vector b with b3 = 2*b1'\n",
+ "print 'So,b = b1p1 + b2p2 + b4p3'\n",
+ "print 'And,[p1 p2 p3] = R = Q*A'\n",
+ "print 'So, b = [b1 b2 b3]* Q * A'\n",
+ "print 'hence, b = x1a1 + x2a2 + x3a3 where x1 = [b1 b2 b4] * Q(1) and so on' # #Equation 1\n",
+ "#part c\n",
+ "print 'Now, given 3 vectors a1'' a2'' a3'':'\n",
+ "c1 = [1, 0, 2, 0]#\n",
+ "c2 = [0 ,2 ,0, 1]#\n",
+ "c3 = [0 ,0 ,0 ,3]#\n",
+ "print 'a1'' = ',c1\n",
+ "print 'a2'' = ',c2\n",
+ "print 'a3'' = ',c3\n",
+ "print 'Since a1'' a2'' a3'' are all of the form (y1 y2 y3 y4) with y3 = 2*y1, hence they are in W.'\n",
+ "print 'So, they are independent.'\n",
+ "#part d\n",
+ "c = np.array([c1,c2,c3])\n",
+ "P = np.identity(3)\n",
+ "for i in range(0,3):\n",
+ " b1 = c[i,0]\n",
+ " b2 = c[i,1]\n",
+ " b4 = c[i,3]\n",
+ " x1 = np.array([b1, b2, b4]) * Q[:,0]\n",
+ " x2 = np.array([b1, b2, b4])*Q[:,1]\n",
+ " x3 = np.array([b1, b2, b4])*Q[:,2]\n",
+ " \n",
+ "\n",
+ "print 'Required matrix P such that X = PX'' is:'\n",
+ "P=np.vstack([x1,x2,x3])\n",
+ "print 'P = \\n',P\n",
+ "#print x1"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Page 63 Example 2.22"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 8,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "A = \n",
+ "[[ 1 2 0 3 0]\n",
+ " [ 1 2 -1 -1 0]\n",
+ " [ 0 0 1 4 0]\n",
+ " [ 2 4 1 10 1]\n",
+ " [ 0 0 0 0 1]]\n",
+ "Taking an identity matrix P:\n",
+ "P = \n",
+ "[[ 1. 0. 0. 0. 0.]\n",
+ " [ 0. 1. 0. 0. 0.]\n",
+ " [ 0. 0. 1. 0. 0.]\n",
+ " [ 0. 0. 0. 1. 0.]\n",
+ " [ 0. 0. 0. 0. 1.]]\n",
+ "Applying row transformations on P and A to get a row reduced echelon matrix R:\n",
+ "R2 = R2 - R1 and R4 = R4 - 2* R1\n",
+ "A = \n",
+ "[[ 1 2 0 3 0]\n",
+ " [ 0 0 -1 -4 0]\n",
+ " [ 0 0 1 4 0]\n",
+ " [ 0 0 1 4 1]\n",
+ " [ 0 0 0 0 1]]\n",
+ "P = \n",
+ "[[ 1. 0. 0. 0. 0.]\n",
+ " [-1. 1. 0. 0. 0.]\n",
+ " [ 0. 0. 1. 0. 0.]\n",
+ " [-2. 0. 0. 1. 0.]\n",
+ " [ 0. 0. 0. 0. 1.]]\n",
+ "R2 = -R2 , R3 = R3 - R1 + R2 and R4 = R4 - R1 + R2\n",
+ "A = \n",
+ "[[1 2 0 3 0]\n",
+ " [0 0 1 4 0]\n",
+ " [0 0 0 0 0]\n",
+ " [0 0 0 0 1]\n",
+ " [0 0 0 0 1]]\n",
+ "P = \n",
+ "[[ 1. 0. 0. 0. 0.]\n",
+ " [ 1. -1. -0. -0. -0.]\n",
+ " [-1. 1. 1. 0. 0.]\n",
+ " [-3. 1. 0. 1. 0.]\n",
+ " [-3. 1. 0. 1. 0.]]\n",
+ "Mutually interchanging R3, R4 and R5\n",
+ "Row reduced echelon matrix R = \n",
+ "[[1 2 0 3 0]\n",
+ " [0 0 1 4 0]\n",
+ " [0 0 0 0 1]\n",
+ " [0 0 0 0 1]\n",
+ " [0 0 0 0 0]]\n",
+ "Invertible Matrix P = \n",
+ "[[ 1. 0. 0. 0. 0.]\n",
+ " [ 1. -1. -0. -0. -0.]\n",
+ " [-3. 1. 0. 1. 0.]\n",
+ " [-3. 1. 0. 1. 0.]\n",
+ " [ 0. 0. 0. 0. 0.]]\n",
+ "Invertible matrix P is not unique. There can be many that depends on operations used to reduce A\n",
+ "-----------------------------------------\n",
+ "For the basis of row space W of A, we can take the non-zero rows of R\n",
+ "It can be given by p1, p2, p3\n",
+ "p1 = [1 2 0 3 0]\n",
+ "p2 = [0 0 1 4 0]\n",
+ "p3 = [0 0 0 0 1]\n",
+ "-----------------------------------------\n",
+ "The row space W consists of vectors of the form:\n",
+ "b = c1p1 + c2p2 + c3p3\n",
+ "i.e. b = (c1,2*c1,c2,3*c1+4*c2,c3) where, c1 c2 c3 are scalars.\n",
+ "So, if b2 = 2*b1 and b4 = 3*b1 + 4*b3 => (b1,b2,b3,b4,b5) = b1p1 + b3p2 + b5p3\n",
+ "then,(b1,b2,b3,b4,b5) is in W\n",
+ "-----------------------------------------\n",
+ "The coordinate matrix of the vector (b1,2*b1,b2,3*b1+4*b2,b3) in the basis (p1,p2,p3) is column matrix of b1,b2,b3 such that:\n",
+ " b1\n",
+ " b2\n",
+ " b3\n",
+ "-----------------------------------------\n",
+ "Now, to write each vector in W as a linear combination of rows of A:\n",
+ "Let b = (b1,b2,b3,b4,b5) and if b is in W, then\n",
+ "we know,b = (b1,2*b1,b3,3*b1 + 4*b3,b5) => [b1,b3,b5,0,0]*R\n",
+ "=> b = [b1,b3,b5,0,0] * P*A => b = [b1+b3,-b3,0,0,b5] * A\n",
+ "if b = (-5,-10,1,-11,20)\n",
+ "b = ( [-4, -1, 0, 0, 20] ) *[ [[1 2 0 3 0]\n",
+ " [0 0 1 4 0]\n",
+ " [0 0 0 0 1]\n",
+ " [0 0 0 0 1]\n",
+ " [0 0 0 0 0]] ]\n",
+ "-----------------------------------------\n",
+ "The equations in system RX = 0 are given by R * [x1 x2 x3 x4 x5]\n",
+ "i.e., x1 + 2*x2 + 3*x4\n",
+ "x3 + 4*x4\n",
+ "x5\n",
+ "so, V consists of all columns of the form\n",
+ "[ X=\n",
+ " -2*x2 - 3*x4\n",
+ " x2\n",
+ " -4*x4\n",
+ " x4\n",
+ " 0\n",
+ "where x2 and x4 are arbitrary ]\n",
+ "-----------------------------------------\n",
+ "Let x2 = 1,x4 = 0 then the given column forms a basis of V\n",
+ "[[-2], [1], [0], [0], [0]]\n",
+ "Similarly,if x2 = 0,x4 = 1 then the given column forms a basis of V\n",
+ "[[-3], [0], [-4], [1], [0]]\n",
+ "-----------------------------------------\n",
+ "The equation AX = Y has solutions X if and only if\n",
+ "-y1 + y2 + y3 = 0\n",
+ "-3*y1 + y2 + y4 -y5 = 0\n",
+ "where, Y = (y1 y2 y3 y4 y5)\n"
+ ]
+ }
+ ],
+ "source": [
+ "import numpy as np\n",
+ "A = np.array([[1, 2, 0, 3, 0],[1, 2, -1, -1, 0],[0 ,0 ,1 ,4 ,0],[2, 4 ,1 ,10, 1],[0 ,0 ,0 ,0 ,1]])\n",
+ "print 'A = \\n',A\n",
+ "#part a\n",
+ "T = A# #Temporary storing A in T\n",
+ "print 'Taking an identity matrix P:'\n",
+ "P = np.identity(5)\n",
+ "print 'P = \\n',P\n",
+ "print 'Applying row transformations on P and A to get a row reduced echelon matrix R:'\n",
+ "print 'R2 = R2 - R1 and R4 = R4 - 2* R1'\n",
+ "A[1,:] = A[1,:] - A[0,:]\n",
+ "P[1,:] = P[1,:] - P[0,:]\n",
+ "A[3,:] = A[3,:] - 2 * A[0,:]\n",
+ "P[3,:] = P[3,:] - 2 * P[0,:]\n",
+ "print 'A = \\n',A\n",
+ "print 'P = \\n',P\n",
+ "print 'R2 = -R2 , R3 = R3 - R1 + R2 and R4 = R4 - R1 + R2'\n",
+ "A[1,:] = -A[1,:]\n",
+ "P[1,:] = -P[1,:]\n",
+ "A[2,:] = A[2,:] - A[1,:]\n",
+ "P[2,:] = P[2,:] - P[1,:]\n",
+ "A[3,:] = A[3,:] - A[1,:]\n",
+ "P[3:] = P[3,:] - P[1,:]\n",
+ "print 'A = \\n',A\n",
+ "print 'P = \\n',P\n",
+ "print 'Mutually interchanging R3, R4 and R5'\n",
+ "x = A[2,:]\n",
+ "A[2,:] = A[4,:]\n",
+ "y = A[3,:]\n",
+ "A[3,:] = x#\n",
+ "A[4,:] = y - A[2,:]\n",
+ "x = P[2,:]\n",
+ "P[2,:] = P[4,:]\n",
+ "y = P[3,:]\n",
+ "P[3,:] = x#\n",
+ "P[4,:] = y - P[2,:]\n",
+ "R = A#\n",
+ "A = T#\n",
+ "print 'Row reduced echelon matrix R = \\n',R\n",
+ "print 'Invertible Matrix P = \\n',P\n",
+ "print 'Invertible matrix P is not unique. There can be many that depends on operations used to reduce A'\n",
+ "print '-----------------------------------------'\n",
+ "#part b\n",
+ "print 'For the basis of row space W of A, we can take the non-zero rows of R'\n",
+ "print 'It can be given by p1, p2, p3'\n",
+ "p1 = R[0,:]\n",
+ "p2 = R[1,:]\n",
+ "p3 = R[2,:]\n",
+ "print 'p1 = ',p1\n",
+ "print 'p2 = ',p2\n",
+ "print 'p3 = ',p3\n",
+ "print '-----------------------------------------'\n",
+ "#part c\n",
+ "print 'The row space W consists of vectors of the form:'\n",
+ "print 'b = c1p1 + c2p2 + c3p3'\n",
+ "print 'i.e. b = (c1,2*c1,c2,3*c1+4*c2,c3) where, c1 c2 c3 are scalars.'\n",
+ "print 'So, if b2 = 2*b1 and b4 = 3*b1 + 4*b3 => (b1,b2,b3,b4,b5) = b1p1 + b3p2 + b5p3'\n",
+ "print 'then,(b1,b2,b3,b4,b5) is in W'\n",
+ "print '-----------------------------------------'\n",
+ "#part d\n",
+ "print 'The coordinate matrix of the vector (b1,2*b1,b2,3*b1+4*b2,b3) in the basis (p1,p2,p3) is column matrix of b1,b2,b3 such that:'\n",
+ "print ' b1'\n",
+ "print ' b2'\n",
+ "print ' b3'\n",
+ "print '-----------------------------------------'\n",
+ "#part e\n",
+ "print 'Now, to write each vector in W as a linear combination of rows of A:'\n",
+ "print 'Let b = (b1,b2,b3,b4,b5) and if b is in W, then'\n",
+ "print 'we know,b = (b1,2*b1,b3,3*b1 + 4*b3,b5) => [b1,b3,b5,0,0]*R'\n",
+ "print '=> b = [b1,b3,b5,0,0] * P*A => b = [b1+b3,-b3,0,0,b5] * A'\n",
+ "print 'if b = (-5,-10,1,-11,20)'\n",
+ "b1 = -5#\n",
+ "b2 = -10#\n",
+ "b3 = 1#\n",
+ "b4 = -11#\n",
+ "b5 = 20#\n",
+ "x = [b1 + b3,-b3,0,0,b5]#\n",
+ "print 'b = (',x,')','*[',A,']'\n",
+ "print '-----------------------------------------'\n",
+ "#part f\n",
+ "print 'The equations in system RX = 0 are given by R * [x1 x2 x3 x4 x5]'\n",
+ "print 'i.e., x1 + 2*x2 + 3*x4'\n",
+ "print 'x3 + 4*x4'\n",
+ "print 'x5'\n",
+ "print 'so, V consists of all columns of the form'\n",
+ "print '[','X='\n",
+ "print ' -2*x2 - 3*x4'\n",
+ "print ' x2'\n",
+ "print ' -4*x4'\n",
+ "print ' x4'\n",
+ "print ' 0'\n",
+ "print 'where x2 and x4 are arbitrary',']'\n",
+ "print '-----------------------------------------'\n",
+ "#part g\n",
+ "print 'Let x2 = 1,x4 = 0 then the given column forms a basis of V'\n",
+ "\n",
+ "x2 = 1#\n",
+ "x4 = 0#\n",
+ "print [[-2*x2-3*x4],[ x2],[ -4*x4],[ x4],[ 0]]\n",
+ "print 'Similarly,if x2 = 0,x4 = 1 then the given column forms a basis of V'\n",
+ "x2 = 0#\n",
+ "x4 = 1#\n",
+ "print [[-2*x2-3*x4],[ x2],[ -4*x4],[ x4],[ 0]]\n",
+ "print '-----------------------------------------'\n",
+ "#part h\n",
+ "print 'The equation AX = Y has solutions X if and only if'\n",
+ "print '-y1 + y2 + y3 = 0'\n",
+ "print '-3*y1 + y2 + y4 -y5 = 0'\n",
+ "print 'where, Y = (y1 y2 y3 y4 y5)'"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/Linear_Algebra_by_K._Hoffman_and_R._Kunze/Chapter3_1.ipynb b/Linear_Algebra_by_K._Hoffman_and_R._Kunze/Chapter3_1.ipynb
new file mode 100644
index 00000000..2e2e4be2
--- /dev/null
+++ b/Linear_Algebra_by_K._Hoffman_and_R._Kunze/Chapter3_1.ipynb
@@ -0,0 +1,637 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 3 - Linear transformation"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Page 70 Example 3.6"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "a1 = [1, 2]\n",
+ "a2 = [3, 4]\n",
+ "a1 and a2 are linearly independent and hence form a basis for R**2\n",
+ "According to theorem 1, there is a linear transformation from R**2 to R**3 with the transformation functions as:\n",
+ "Ta1 = [3, 2, 1]\n",
+ "Ta2 = [6, 5, 4]\n",
+ "Now, we find scalars c1 and c2 for that we know T(c1a1 + c2a2) = c1(Ta1) + c2(Ta2))\n",
+ "if(1,0) = c1(1,2) + c2(3,4), then \n",
+ "c1 = 1\n",
+ "c2 = 3\n",
+ "The transformation function T(1,0) will be:\n",
+ "T(1,0) = [3, 2, 1, 6, 5, 4, 6, 5, 4, 6, 5, 4]\n"
+ ]
+ }
+ ],
+ "source": [
+ "import numpy as np\n",
+ "a1 = [1, 2]#\n",
+ "a2 = [3 ,4]#\n",
+ "print 'a1 = ',a1\n",
+ "print 'a2 = ',a2\n",
+ "print 'a1 and a2 are linearly independent and hence form a basis for R**2'\n",
+ "print 'According to theorem 1, there is a linear transformation from R**2 to R**3 with the transformation functions as:'\n",
+ "Ta1 = [3 ,2 ,1]#\n",
+ "Ta2 = [6, 5, 4]#\n",
+ "print 'Ta1 = ',Ta1\n",
+ "print 'Ta2 = ',Ta2\n",
+ "print 'Now, we find scalars c1 and c2 for that we know T(c1a1 + c2a2) = c1(Ta1) + c2(Ta2))'\n",
+ "print 'if(1,0) = c1(1,2) + c2(3,4), then '\n",
+ "#c = inv([a1#a2]') * [1#0]#\n",
+ "c=np.array([a1,a2]).dot(np.array([[1],[0]]))\n",
+ "c1 = c[0,0]\n",
+ "c2 = c[1,0]\n",
+ "print 'c1 = ',c1\n",
+ "print 'c2 = ',c2\n",
+ "print 'The transformation function T(1,0) will be:'\n",
+ "T = c1*Ta1 + c2*Ta2#\n",
+ "print 'T(1,0) = ',T\n",
+ "#end"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Page 81 Example 3.12"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "x1 = 5\n",
+ "x2 = 2\n",
+ "T(5,2) = [7, 5]\n",
+ "If, T(x1,x2) = 0, then\n",
+ "x1 = x2 = 0\n",
+ "So, T is non-singular\n",
+ "z1,z2 are two scalars in F\n",
+ "z1 = 0\n",
+ "z2 = 8\n",
+ "So, x1 = 8\n",
+ "x2 = -8\n",
+ "Hence, T is onto.\n",
+ "inverse(T) = [8, -8]\n"
+ ]
+ }
+ ],
+ "source": [
+ "import numpy as np\n",
+ "#x = round(rand(1,2) * 10)#\n",
+ "x1 = np.random.randint(1,9)\n",
+ "x2 = np.random.randint(1,9)\n",
+ "T = [x1+x2 ,x1]\n",
+ "print 'x1 = ',x1\n",
+ "print 'x2 = ',x2\n",
+ "print 'T(%d,%d) = '%(x1,x2),\n",
+ "print T\n",
+ "print 'If, T(x1,x2) = 0, then'\n",
+ "print 'x1 = x2 = 0'\n",
+ "print 'So, T is non-singular'\n",
+ "print 'z1,z2 are two scalars in F'\n",
+ "\n",
+ "z1 = np.random.randint(0,9)\n",
+ "z2 = np.random.randint(0,9)\n",
+ "print 'z1 = ',z1\n",
+ "print 'z2 = ',z2\n",
+ "x1 = z2#\n",
+ "x2 = z1 - z2#\n",
+ "print 'So, x1 = ',x1\n",
+ "print 'x2 = ',x2\n",
+ "print 'Hence, T is onto.'\n",
+ "Tinv = [z2, z1-z2]# \n",
+ "print 'inverse(T) = ',Tinv"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Page 89 Example 3.14"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "T is a linear operator on F**2 defined as:\n",
+ "T(x1,x2) = (x1,0)\n",
+ "B = {e1,e2} is a standard ordered basis for F**2,then\n",
+ "So, Te1 = T(1,0) = [1, 0]\n",
+ "So, Te2 = T(0,1) = [0, 0]\n",
+ "so,matrix T in ordered basis B is: \n",
+ "T = \n",
+ "[[1, 0], [0, 0]]\n"
+ ]
+ }
+ ],
+ "source": [
+ "print 'T is a linear operator on F**2 defined as:'\n",
+ "print 'T(x1,x2) = (x1,0)'\n",
+ "print 'B = {e1,e2} is a standard ordered basis for F**2,then'\n",
+ "x1 = 1#\n",
+ "x2 = 0#\n",
+ "Te1 = [x1, 0]#\n",
+ "x1 = 0#\n",
+ "x2 = 1#\n",
+ "Te2 = [x1 ,0]#\n",
+ "print 'So, Te1 = T(1,0) = ',Te1\n",
+ "print 'So, Te2 = T(0,1) = ',Te2\n",
+ "print 'so,matrix T in ordered basis B is: '\n",
+ "T = [Te1,Te2]\n",
+ "print 'T = \\n',T"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Page 89 Example 3.15"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Differentiation operator D is defined as:\n",
+ "(Df1)(x) = 0\n",
+ "(Df2)(x) = 1\n",
+ "(Df3)(x) = 2*x\n",
+ "(Df4)(x) = 3*x**2\n",
+ "Matrix of D in ordered basis is:\n",
+ "[D] = \n",
+ "[[ 0. 1. 0. 0.]\n",
+ " [ 0. 0. 2. 0.]\n",
+ " [ 0. 0. 0. 3.]\n",
+ " [ 0. 0. 0. 0.]]\n"
+ ]
+ }
+ ],
+ "source": [
+ "import numpy as np\n",
+ "import sympy as sp\n",
+ "print 'Differentiation operator D is defined as:'\n",
+ "D = np.zeros([4,4])\n",
+ "x=sp.Symbol('x')\n",
+ "for i in range(1,5):\n",
+ " t= i-1#\n",
+ " f = sp.diff(x**t,'x')\n",
+ " print '(Df%d)(x) = '%(i),\n",
+ " print f\n",
+ " if not(i == 1):\n",
+ " D[i-2,i-1] = i-1#\n",
+ " \n",
+ "\n",
+ "print 'Matrix of D in ordered basis is:'\n",
+ "print '[D] = \\n',D"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Page 92 Example 3.16"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 6,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "T is a linear operator on R**2 defined as T(x1,x2) = (x1,0)\n",
+ "So, the matrix T in standard ordered basis B = {e1,e2} is \n",
+ "[T]B = [[1 0]\n",
+ " [0 0]]\n",
+ "Let B is the ordered basis for R**2 consisting of vectors:\n",
+ "E1 = [1 1]\n",
+ "E2 = [2 1]\n",
+ "So, matrix P = \n",
+ "[[1 2]\n",
+ " [1 1]]\n",
+ "P inverse = \n",
+ "[[-1. 2.]\n",
+ " [ 1. -1.]]\n",
+ "So, matrix T in ordered basis B is [T]B = \n",
+ "[[-1. 0.]\n",
+ " [ 0. -0.]]\n"
+ ]
+ }
+ ],
+ "source": [
+ "import numpy as np\n",
+ "print 'T is a linear operator on R**2 defined as T(x1,x2) = (x1,0)'\n",
+ "print 'So, the matrix T in standard ordered basis B = {e1,e2} is '\n",
+ "T = np.array([[1, 0],[0, 0]])\n",
+ "print '[T]B = ',T\n",
+ "print 'Let B'' is the ordered basis for R**2 consisting of vectors:'\n",
+ "E1 = np.array([1, 1])\n",
+ "E2 = np.array([2 ,1])\n",
+ "print 'E1 = ',E1\n",
+ "print 'E2 = ',E2\n",
+ "P = np.transpose(([E1,E2]))\n",
+ "print 'So, matrix P = \\n',P\n",
+ "Pinv=np.linalg.inv(P)\n",
+ "print 'P inverse = \\n',Pinv\n",
+ "T1 = Pinv*T*P#\n",
+ "print 'So, matrix T in ordered basis B'' is [T]B'' = \\n',T1"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Page 93 Example 3.17"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 8,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "g1 = f1\n",
+ "g2 = t*f1 + f2\n",
+ "g3 = t**2*f1 + 2*t*f2 + f3\n",
+ "g4 = t**3*f1 + 3*t**2*f2 + 3*t*f3 + f4\n",
+ "P = \n",
+ "Matrix([[1, t, t**2, t**3], [0, 1, 2*t, 3*t**2], [0, 0, 1, 3*t], [0, 0, 0, 1]])\n",
+ "inverse P = \n",
+ "Matrix([[1, -t, t**2, -t**3], [0, 1, -2*t, 3*t**2], [0, 0, 1, -3*t], [0, 0, 0, 1]])\n",
+ "Matrix of differentiation operator D in ordered basis B is:\n",
+ "D = \n",
+ "Matrix([[0, 1, 0, 0], [0, 0, 2, 0], [0, 0, 0, 3], [0, 0, 0, 0]])\n",
+ "Matrix of D in ordered basis B is:\n",
+ "inverse(P) * D * P = Matrix([[0, 1, 0, 0], [0, 0, 2, 0], [0, 0, 0, 3], [0, 0, 0, 0]])\n"
+ ]
+ }
+ ],
+ "source": [
+ "import sympy as sp\n",
+ "t = sp.Symbol(\"t\")\n",
+ "print 'g1 = f1'\n",
+ "print 'g2 = t*f1 + f2'\n",
+ "print 'g3 = t**2*f1 + 2*t*f2 + f3'\n",
+ "print 'g4 = t**3*f1 + 3*t**2*f2 + 3*t*f3 + f4'\n",
+ "P = sp.Matrix(([1, t, t**2, t**3],[0 ,1 ,2*t, 3*t**2],[0, 0, 1, 3*t],[0, 0, 0, 1]))\n",
+ "print 'P = \\n',P\n",
+ "\n",
+ "print 'inverse P = \\n',sp.Matrix.inv(P)\n",
+ "\n",
+ "\n",
+ "\n",
+ "print 'Matrix of differentiation operator D in ordered basis B is:'# #As found in example 15\n",
+ "D = sp.Matrix(([0, 1, 0, 0],[0, 0, 2, 0],[0, 0, 0, 3],[0, 0, 0, 0]))\n",
+ "print 'D = \\n',D\n",
+ "print 'Matrix of D in ordered basis B'' is:'\n",
+ "print 'inverse(P) * D * P = ',sp.Matrix.inv(P)*D*P\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Page 98 Example 3.19"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 9,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "n = 8\n",
+ "A = \n",
+ "[[ 7. 3. 0. 4. 6. 8. 4. 4.]\n",
+ " [ 6. 4. 2. 8. 7. 8. 1. 7.]\n",
+ " [ 7. 0. 9. 3. 10. 9. 3. 8.]\n",
+ " [ 7. 5. 10. 1. 8. 6. 6. 5.]\n",
+ " [ 8. 8. 9. 9. 1. 9. 10. 4.]\n",
+ " [ 6. 3. 5. 2. 2. 4. 8. 4.]\n",
+ " [ 5. 1. 1. 2. 6. 9. 9. 5.]\n",
+ " [ 8. 6. 9. 9. 8. 9. 1. 2.]]\n",
+ "Trace of A:\n",
+ "tr(A) = 37.0\n",
+ "--------------------------------\n",
+ "c = 3\n",
+ "B = \n",
+ "[[ 4. 6. 10. 5. 8. 4. 1. 9.]\n",
+ " [ 9. 9. 3. 6. 3. 8. 2. 6.]\n",
+ " [ 1. 6. 0. 7. 7. 2. 8. 4.]\n",
+ " [ 5. 5. 9. 7. 9. 3. 9. 9.]\n",
+ " [ 7. 7. 10. 6. 1. 1. 7. 4.]\n",
+ " [ 0. 3. 10. 9. 5. 2. 8. 4.]\n",
+ " [ 1. 8. 2. 4. 5. 4. 4. 8.]\n",
+ " [ 7. 0. 1. 8. 2. 7. 4. 7.]]\n",
+ "Trace of B:\n",
+ "tr(B) = 34.0\n",
+ "tr(cA + B) = 145.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "import numpy as np\n",
+ "def trace_matrix(M,n):\n",
+ " tr=0\n",
+ " for i in range(0,n):\n",
+ " tr = tr + M[i,i]#\n",
+ " return tr\n",
+ "#n = round(rand() * 10 + 2)#\n",
+ "n=np.random.randint(1,9)\n",
+ "print 'n = ',n\n",
+ "#A = round(rand(n,n) * 10)#\n",
+ "A=np.random.rand(n,n)\n",
+ "for x in range(0,n):\n",
+ " for y in range(0,n):\n",
+ " A[x,y]=round(A[x,y]*10)\n",
+ "print 'A = \\n',A\n",
+ "\n",
+ "\n",
+ "tr = 0#\n",
+ "print 'Trace of A:'\n",
+ "tr1 = trace_matrix(A,n)#\n",
+ "print 'tr(A) = ',tr1\n",
+ "print '--------------------------------'\n",
+ "#c = round(rand() * 10 + 2)#\n",
+ "c=np.random.randint(2,9)\n",
+ "print 'c = ',c\n",
+ "\n",
+ "B=np.random.rand(n,n)\n",
+ "for x in range(0,n):\n",
+ " for y in range(0,n):\n",
+ " B[x,y]=round(B[x,y]*10)\n",
+ "print 'B = \\n',B\n",
+ "\n",
+ "print 'Trace of B:'\n",
+ "tr2 = trace_matrix(B,n)#\n",
+ "print 'tr(B) = ',tr2\n",
+ "print 'tr(cA + B) = ',(c*tr1+tr2)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Page 103 Example 3.23"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 10,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Matrix represented by given linear functionals on R**4:\n",
+ "A = \n",
+ "[[ 1 2 2 1]\n",
+ " [ 0 2 0 1]\n",
+ " [-2 0 -4 3]]\n",
+ "To find Row reduced echelon matrix of A given by R:\n",
+ "Applying row transformations on A,we get\n",
+ "R1 = R1-R2\n",
+ "A = \n",
+ "[[ 1 0 2 0]\n",
+ " [ 0 2 0 1]\n",
+ " [-2 0 -4 3]]\n",
+ "R3 = R3 + 2*R1\n",
+ "A = \n",
+ "[[1 0 2 0]\n",
+ " [0 2 0 1]\n",
+ " [0 0 0 3]]\n",
+ "R3 = R3/3\n",
+ "A = \n",
+ "[[1 0 2 0]\n",
+ " [0 2 0 1]\n",
+ " [0 0 0 1]]\n",
+ "R2 = R2/2\n",
+ "A = \n",
+ "[[1 0 2 0]\n",
+ " [0 1 0 0]\n",
+ " [0 0 0 1]]\n",
+ "R2 = R2 - 1/2*R3\n",
+ "A = \n",
+ "[[1 0 2 0]\n",
+ " [0 1 0 0]\n",
+ " [0 0 0 1]]\n",
+ "Row reduced echelon matrix of A is:\n",
+ "R = \n",
+ "[[1 0 2 0]\n",
+ " [0 1 0 0]\n",
+ " [0 0 0 1]]\n",
+ "Therefore,linear functionals g1,g2,g3 span the same subspace of (R**4)* as f1,f2,f3 are given by:\n",
+ "g1(x1,x2,x3,x4) = x1 + 2*x3\n",
+ "g1(x1,x2,x3,x4) = x2\n",
+ "g1(x1,x2,x3,x4) = x4\n",
+ "The subspace consists of the vectors with\n",
+ "x1 = -2*x3\n",
+ "x2 = x4 = 0\n"
+ ]
+ }
+ ],
+ "source": [
+ "import numpy as np\n",
+ "print 'Matrix represented by given linear functionals on R**4:'\n",
+ "A = np.array([[1, 2 ,2 ,1],[0, 2, 0, 1],[-2 ,0 ,-4, 3]])\n",
+ "print 'A = \\n',A\n",
+ "T = A #Temporary matrix to store A\n",
+ "print 'To find Row reduced echelon matrix of A given by R:'\n",
+ "print 'Applying row transformations on A,we get'\n",
+ "print 'R1 = R1-R2'\n",
+ "A[0,:] = A[0,:] - A[1,:]\n",
+ "print 'A = \\n',A\n",
+ "print 'R3 = R3 + 2*R1'\n",
+ "A[2,:] = A[2,:] + 2*A[0,:]\n",
+ "print 'A = \\n',A\n",
+ "print 'R3 = R3/3'\n",
+ "A[2,:] = 1./3*A[2,:]#\n",
+ "print 'A = \\n',A\n",
+ "print 'R2 = R2/2'\n",
+ "A[1,:] = 1./2*A[1,:]\n",
+ "print 'A = \\n',A\n",
+ "print 'R2 = R2 - 1/2*R3'\n",
+ "A[1,:] = A[1,:] - 1./2*A[2,:]\n",
+ "print 'A = \\n',A\n",
+ "R = A#\n",
+ "A = T#\n",
+ "print 'Row reduced echelon matrix of A is:'\n",
+ "print 'R = \\n',R\n",
+ "print 'Therefore,linear functionals g1,g2,g3 span the same subspace of (R**4)* as f1,f2,f3 are given by:'\n",
+ "print 'g1(x1,x2,x3,x4) = x1 + 2*x3'\n",
+ "print 'g1(x1,x2,x3,x4) = x2'\n",
+ "print 'g1(x1,x2,x3,x4) = x4'\n",
+ "print 'The subspace consists of the vectors with'\n",
+ "print 'x1 = -2*x3'\n",
+ "print 'x2 = x4 = 0'"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Page 104 Example 3.24"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 11,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "W be the subspace of R**5 spanned by vectors:\n",
+ "a1 = [2, -2, 3, 4, -1]\n",
+ "a2 = [-1, 1, 2, 5, 2]\n",
+ "a3 = [0, 0, -1, -2, 3]\n",
+ "a4 = [1, -1, 2, 3, 0]\n",
+ "Matrix A by the row vectors a1,a2,a3,a4 will be:\n",
+ "A = \n",
+ "[[ 2 -2 3 4 -1]\n",
+ " [-1 1 2 5 2]\n",
+ " [ 0 0 -1 -2 3]\n",
+ " [ 1 -1 2 3 0]]\n",
+ "After Applying row transformations, we get the row reduced echelon matrix R of A\n",
+ "R = \n",
+ "[[ 1 -1 0 -1 0]\n",
+ " [ 0 0 1 2 0]\n",
+ " [ 0 0 0 0 1]\n",
+ " [ 0 0 0 0 0]]\n",
+ "Then we obtain all the linear functionals f by assigning arbitrary values to c2 and c4\n",
+ "Let c2 = a, c4 = b then c1 = a+b, c3 = -2b, c5 = 0.\n",
+ "So, W0 consists all linear functionals f of the form\n",
+ "f(x1,x2,x3,x4,x5) = (a+b)x1 + ax2 -2bx3 + bx4\n",
+ "Dimension of W0 = 2 and basis {f1,f2} can be found by first taking a = 1, b = 0. Then a = 0,b = 1\n"
+ ]
+ }
+ ],
+ "source": [
+ "import numpy as np\n",
+ "print 'W be the subspace of R**5 spanned by vectors:'\n",
+ "a1 = [2, -2, 3 ,4 ,-1]#\n",
+ "a2 = [-1, 1, 2, 5, 2]#\n",
+ "a3 = [0 ,0 ,-1, -2, 3]#\n",
+ "a4 = [1 ,-1, 2, 3 ,0]#\n",
+ "print 'a1 = ',a1\n",
+ "print 'a2 = ',a2\n",
+ "print 'a3 = ',a3\n",
+ "print 'a4 = ',a4\n",
+ "print 'Matrix A by the row vectors a1,a2,a3,a4 will be:'\n",
+ "A = np.array([a1,a2,a3,a4])\n",
+ "print 'A = \\n',A\n",
+ "print 'After Applying row transformations, we get the row reduced echelon matrix R of A'\n",
+ "\n",
+ "T = A# #Temporary matrix to store A\n",
+ "#R1 = R1 - R4 and R2 = R2 + R4\n",
+ "A[0,:] = A[0,:] - A[3,:]#\n",
+ "A[1,:] = A[1,:] + A[3,:]#\n",
+ "#R2 = R2/2\n",
+ "A[1,:] = 1./2 * A[1,:]#\n",
+ "#R3 = R3 + R2 and R4 = R4 - R1\n",
+ "A[2,:] = A[2,:] + A[1,:]#\n",
+ "A[3,:] = A[3,:] - A[0,:]#\n",
+ "#R3 = R3 - R4\n",
+ "A[2,:] = A[2,:] - A[3,:]#\n",
+ "#R3 = R3/3\n",
+ "A[2,:] = 1./3 * A[2,:]#\n",
+ "#R2 = R2 - R3\n",
+ "A[1,:] = A[1,:] - A[2,:]#\n",
+ "#R2 = R2/2 and R4 = R4 - R2 - R3\n",
+ "A[1,:] = 1./2 * A[1,:]#\n",
+ "A[3,:] = A[3,:] - A[1,:] - A[2,:]#\n",
+ "#R1 = R1 - R2 + R3\n",
+ "A[0,:] = A[0,:] - A[1,:] + A[2,:]#\n",
+ "R = A#\n",
+ "A = T#\n",
+ "print 'R = \\n',R\n",
+ "print 'Then we obtain all the linear functionals f by assigning arbitrary values to c2 and c4'\n",
+ "print 'Let c2 = a, c4 = b then c1 = a+b, c3 = -2b, c5 = 0.'\n",
+ "print 'So, W0 consists all linear functionals f of the form'\n",
+ "print 'f(x1,x2,x3,x4,x5) = (a+b)x1 + ax2 -2bx3 + bx4'\n",
+ "print 'Dimension of W0 = 2 and basis {f1,f2} can be found by first taking a = 1, b = 0. Then a = 0,b = 1'"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/Linear_Algebra_by_K._Hoffman_and_R._Kunze/Chapter4_1.ipynb b/Linear_Algebra_by_K._Hoffman_and_R._Kunze/Chapter4_1.ipynb
new file mode 100644
index 00000000..3fb3b384
--- /dev/null
+++ b/Linear_Algebra_by_K._Hoffman_and_R._Kunze/Chapter4_1.ipynb
@@ -0,0 +1,328 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 4 - Polynomials"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Page 121 Example 4.3"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "C is the field of complex numbers\n",
+ "f = x**2 + 2\n",
+ "if a = C and z belongs to C, then f(z) = z**2 + 2\n",
+ "f(2) = 6\n",
+ "f(1+1J/1-1J) = (1+0j)\n",
+ "----------------------------------------\n",
+ "If a is the algebra of all 2*2 matrices over C and\n",
+ "B = \n",
+ "[[ 1 0]\n",
+ " [-1 2]]\n",
+ "[[ 3. 0.]\n",
+ " [ 1. 6.]] then, f(B) = \n",
+ "----------------------------------------\n",
+ "If a is algebra of all linear operators on C**3\n",
+ "And T is element of a as:\n",
+ "T(c1,c2,c3) = (i*2**1/2*c1,c2,i*2**1/2*c3)\n",
+ "Then, f(T)(c1,c2,c3) = (0,3*c2,0)\n",
+ "----------------------------------------\n",
+ "If a is the algebra of all polynomials over C\n",
+ "And, g = x**4 + 3.0*I\n",
+ "Then f(g) = (16+3j)\n"
+ ]
+ }
+ ],
+ "source": [
+ "import numpy as np\n",
+ "import sympy as sp\n",
+ "from sympy.polys.polyfuncs import horner\n",
+ "print 'C is the field of complex numbers'\n",
+ "x = sp.Symbol(\"x\")\n",
+ "def f(x):\n",
+ " ff= x**2 + 2\n",
+ " return ff\n",
+ "print 'f = ',f(x)\n",
+ "#part a\n",
+ "print 'if a = C and z belongs to C, then f(z) = z**2 + 2'\n",
+ "print 'f(2) = ',f(2)\n",
+ "\n",
+ "\n",
+ "print 'f(1+1J/1-1J) = ',f((1+1J)/(1-1J))\n",
+ "print '----------------------------------------'\n",
+ "\n",
+ "\n",
+ "#part b\n",
+ "print 'If a is the algebra of all 2*2 matrices over C and'\n",
+ "B = np.array([[1 ,0],[-1, 2]])\n",
+ "print 'B = \\n',B\n",
+ "print 2*np.identity(2) + B**2,'then, f(B) = '\n",
+ "print '----------------------------------------'\n",
+ "\n",
+ "#part c\n",
+ "print 'If a is algebra of all linear operators on C**3'\n",
+ "print 'And T is element of a as:'\n",
+ "print 'T(c1,c2,c3) = (i*2**1/2*c1,c2,i*2**1/2*c3)'\n",
+ "print 'Then, f(T)(c1,c2,c3) = (0,3*c2,0)'\n",
+ "print '----------------------------------------'\n",
+ "#part d\n",
+ "print 'If a is the algebra of all polynomials over C'\n",
+ "def g(x):\n",
+ " gg= x**4 + 3*1J\n",
+ " return gg\n",
+ "print 'And, g = ',g(x)\n",
+ "print 'Then f(g) = ',g(2)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Page 131 Example 4.7"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "M = (x+2)F[x] + (x**2 + 8x + 16)F[x]\n",
+ "We assert, M = F[x]\n",
+ "M contains: x**2 - x*(x + 2) + 8*x + 16\n",
+ "And hence M contains: x**2 - x*(x + 2) + 2*x + 4\n",
+ "Thus the scalar polynomial 1 belongs to M as well all its multiples.\n"
+ ]
+ }
+ ],
+ "source": [
+ "import sympy as sp\n",
+ "x = sp.Symbol('x')\n",
+ "p1 = x + 2#\n",
+ "p2 = x**2 + 8*x + 16#\n",
+ "print 'M = (x+2)F[x] + (x**2 + 8x + 16)F[x]'\n",
+ "print 'We assert, M = F[x]'\n",
+ "print 'M contains:',\n",
+ "t = p2 - x*p1#\n",
+ "print t\n",
+ "print 'And hence M contains:',\n",
+ "print t - 6*p1\n",
+ "print 'Thus the scalar polynomial 1 belongs to M as well all its multiples.'"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Page 133 Example 4.8"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "p1 = x + 2\n",
+ "p2 = x**2 + 8*x + 16\n",
+ "M = (x+2)F[x] + (x**2 + 8x + 16)F[x]\n",
+ "We assert, M = F[x]\n",
+ "M contains: x**2 - x*(x + 2) + 8*x + 16\n",
+ "And hence M contains: x**2 - x*(x + 2) + 2*x + 4\n",
+ "Thus the scalar polynomial 1 belongs to M as well all its multiples\n",
+ "So, gcd(p1,p2) = 1\n",
+ "----------------------------------------------\n",
+ "p1 = (x - 2)**2*(x + 1.0*I)\n",
+ "p2 = (x - 2)*(x**2 + 1)\n",
+ "M = (x - 2)**2*(x+1J)F[x] + (x-2)*(x**2 + 1\n",
+ "The ideal M contains p1 - p2 i.e., (x - 2)**2*(x + 1.0*I) - (x - 2)*(x**2 + 1)\n",
+ "Hence it contains (x-2)(x+i), which is monic and divides both,\n",
+ "So, gcd(p1,p2) = (x-2)(x+i)\n",
+ "----------------------------------------------\n"
+ ]
+ }
+ ],
+ "source": [
+ "import sympy as sp\n",
+ "x = sp.Symbol('x')\n",
+ "\n",
+ "#part a\n",
+ "p1 = x + 2#\n",
+ "p2 = x**2 + 8*x + 16#\n",
+ "print 'p1 = ',p1\n",
+ "print 'p2 = ',p2\n",
+ "print 'M = (x+2)F[x] + (x**2 + 8x + 16)F[x]'\n",
+ "print 'We assert, M = F[x]'\n",
+ "print 'M contains:',\n",
+ "t = p2 - x*p1#\n",
+ "print t\n",
+ "print 'And hence M contains:',\n",
+ "print t - 6*p1\n",
+ "print 'Thus the scalar polynomial 1 belongs to M as well all its multiples'\n",
+ "print 'So, gcd(p1,p2) = 1'\n",
+ "print '----------------------------------------------'\n",
+ "#part b\n",
+ "p1 = (x - 2)**2*(x+1J)#\n",
+ "p2 = (x-2)*(x**2 + 1)#\n",
+ "print 'p1 = ',p1\n",
+ "print 'p2 = ',p2\n",
+ "print 'M = (x - 2)**2*(x+1J)F[x] + (x-2)*(x**2 + 1'\n",
+ "print 'The ideal M contains p1 - p2 i.e.,',\n",
+ "print p1 - p2\n",
+ "print 'Hence it contains (x-2)(x+i), which is monic and divides both,'\n",
+ "print 'So, gcd(p1,p2) = (x-2)(x+i)'\n",
+ "print '----------------------------------------------'"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Page 133 Example 4.9"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "M is the ideal in F[x] generated by:\n",
+ "(x-1)*(x+2)**2\n",
+ "(x+2)**2*(x+3)\n",
+ "(x-3) and\n",
+ "M = (x-1)*(x+2)**2 F[x] + (x+2)**2*(x-3) + (x-3)\n",
+ "Then M contains: 0\n",
+ "i.e., M contains (x+2)**2\n",
+ "and since, (x+2)**2 = (x-3)(x-7) - 17\n",
+ "So M contains the scalar polynomial 1.\n",
+ "So, M = F[x] and given polynomials are relatively prime.\n"
+ ]
+ }
+ ],
+ "source": [
+ "import sympy as sp\n",
+ "x = sp.Symbol('x')\n",
+ "\n",
+ "print 'M is the ideal in F[x] generated by:'\n",
+ "print '(x-1)*(x+2)**2'\n",
+ "print '(x+2)**2*(x+3)'\n",
+ "print '(x-3)','and'\n",
+ "p1 = (x-1)*(x+2)**2#\n",
+ "p2 = (x+2)**2*(x-3)#\n",
+ "p3 = (x-3)#\n",
+ "print 'M = (x-1)*(x+2)**2 F[x] + (x+2)**2*(x-3) + (x-3)'\n",
+ "print 'Then M contains:',\n",
+ "t = 1/2*(x+2)**2*((x-1) - (x-3))#\n",
+ "print t\n",
+ "print 'i.e., M contains (x+2)**2'\n",
+ "print 'and since, (x+2)**2 = (x-3)(x-7) - 17'\n",
+ "print 'So M contains the scalar polynomial 1.'\n",
+ "print 'So, M = F[x] and given polynomials are relatively prime.'"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Page 135 Example 4.10"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "x**2 + 1 P = \n",
+ "P is reducible over complex numbers as: = x**2 + 1\n",
+ "(x-i)(x+i)\n",
+ "Whereas, P is irreducible over real numbers as: = x**2 + 1\n",
+ "(ax + b)(ax + b)\n",
+ "For, a,a,b,b to be in R,\n",
+ "aa = 1\n",
+ "ab + ba = 0\n",
+ "bb = 1\n",
+ "=> a**2 + b**2 = 0\n",
+ "=> a = b = 0\n"
+ ]
+ }
+ ],
+ "source": [
+ "import sympy as sp\n",
+ "x = sp.Symbol('x')\n",
+ "P = x**2 + 1#\n",
+ "print P,'P = '\n",
+ "print 'P is reducible over complex numbers as: ',\n",
+ "print '=',P\n",
+ "print '(x-i)(x+i)'\n",
+ "print 'Whereas, P is irreducible over real numbers as:',\n",
+ "print '=',P\n",
+ "print '(ax + b)(a''x + b'')'\n",
+ "print 'For, a,a'',b,b'' to be in R,'\n",
+ "print 'aa'' = 1'\n",
+ "print 'ab'' + ba'' = 0'\n",
+ "print 'bb'' = 1'\n",
+ "print '=> a**2 + b**2 = 0'\n",
+ "print '=> a = b = 0'"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/Linear_Algebra_by_K._Hoffman_and_R._Kunze/Chapter5_1.ipynb b/Linear_Algebra_by_K._Hoffman_and_R._Kunze/Chapter5_1.ipynb
new file mode 100644
index 00000000..9d29340c
--- /dev/null
+++ b/Linear_Algebra_by_K._Hoffman_and_R._Kunze/Chapter5_1.ipynb
@@ -0,0 +1,358 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 5 - Determinants"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Page 143 Example 5.3"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 14,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "A = \n",
+ "[[ 3. 9.]\n",
+ " [ 3. 1.]]\n",
+ "D1(A) = 3.0\n",
+ "D2(A) = -27.0\n",
+ "D(A) = D1(A) + D2(A) = -24.0\n",
+ "That is, D is a 2-linear function.\n"
+ ]
+ }
+ ],
+ "source": [
+ "import numpy as np\n",
+ "A = np.random.rand(2,2)\n",
+ "for x in range(0,2):\n",
+ " for y in range(0,2):\n",
+ " A[x,y]=round(A[x,y]*10)\n",
+ "print 'A = \\n',A\n",
+ "\n",
+ "D1 = A[0,0]*A[1,1]\n",
+ "D2 = - A[0,1]*A[1,0]\n",
+ "print 'D1(A) = ',D1\n",
+ "print 'D2(A) = ',D2\n",
+ "print 'D(A) = D1(A) + D2(A) = ',D1 + D2\n",
+ "print 'That is, D is a 2-linear function.'"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Page 145 Example 5.4"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 15,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "A = \n",
+ "Matrix([[x, 0, -x**2], [0, 1, 0], [1, 0, x**3]])\n",
+ "e1,e2,e3 are the rows of 3*3 identity matrix, then\n",
+ "e1 = [ 1. 0. 0.]\n",
+ "e2 = [ 0. 1. 0.]\n",
+ "e3 = [ 0. 0. 1.]\n",
+ "D(A) = D(x*e1 - x**2*e3, e2, e1 + x**3*e3)\n",
+ "Since, D is linear as a function of each row,\n",
+ "D(A) = x*D(e1,e2,e1 + x**3*e3) - x**2*D(e3,e2,e1 + x**3*e3)\n",
+ "D(A) = x*D(e1,e2,e1) + x**4*D(e1,e2,e3) - x**2*D(e3,e2,e1) - x**5*D(e3,e2,e3)\n",
+ "As D is alternating, So\n",
+ "D(A) = (x**4 + x**2)*D(e1,e2,e3)\n"
+ ]
+ }
+ ],
+ "source": [
+ "import numpy as np\n",
+ "import sympy as sp\n",
+ "\n",
+ "x = sp.Symbol(\"x\")\n",
+ "A = sp.Matrix(([x, 0, -x**2],[0, 1, 0],[1, 0, x**3]))\n",
+ "print 'A = \\n',A\n",
+ "print 'e1,e2,e3 are the rows of 3*3 identity matrix, then'\n",
+ "T = np.identity(3)\n",
+ "e1 = T[0,:]\n",
+ "e2 = T[1,:]\n",
+ "e3 = T[2,:]\n",
+ "print 'e1 = ',e1\n",
+ "print 'e2 = ',e2\n",
+ "print 'e3 = ',e3\n",
+ "print 'D(A) = D(x*e1 - x**2*e3, e2, e1 + x**3*e3)'\n",
+ "print 'Since, D is linear as a function of each row,'\n",
+ "print 'D(A) = x*D(e1,e2,e1 + x**3*e3) - x**2*D(e3,e2,e1 + x**3*e3)'\n",
+ "print 'D(A) = x*D(e1,e2,e1) + x**4*D(e1,e2,e3) - x**2*D(e3,e2,e1) - x**5*D(e3,e2,e3)'\n",
+ "print 'As D is alternating, So'\n",
+ "print 'D(A) = (x**4 + x**2)*D(e1,e2,e3)'"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Page 147 Example 5.5"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 16,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "A = \n",
+ "Matrix([[x - 1, x**2, x**3], [0, x - 2, 1], [0, 0, x - 3]])\n",
+ "\n",
+ "E(A) = x**3 - 6*x**2 + 11*x - 6\n",
+ "--------------------------------------\n",
+ "A = \n",
+ "Matrix([[0, 1, 0], [0, 0, 1], [1, 0, 0]])\n",
+ "\n",
+ "E(A) = 1\n"
+ ]
+ }
+ ],
+ "source": [
+ "import sympy as sp\n",
+ "\n",
+ "#part a\n",
+ "x = sp.Symbol('x')\n",
+ "A = sp.Matrix(([x-1, x**2, x**3],[0, x-2, 1],[0, 0, x-3]))\n",
+ "print 'A = \\n',A\n",
+ "print '\\nE(A) = ',A.det()\n",
+ "print '--------------------------------------'\n",
+ "#part b\n",
+ "A = sp.Matrix(([0 ,1, 0],[0, 0, 1],[1 ,0, 0]))\n",
+ "print 'A = \\n',A\n",
+ "print '\\nE(A) = ',A.det()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Page 158 Example 5.6"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 17,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Given Matrix:\n",
+ "A = \n",
+ "[[ 1 -1 2 3]\n",
+ " [ 2 2 0 2]\n",
+ " [ 4 1 -1 -1]\n",
+ " [ 1 2 3 0]]\n",
+ "After, Subtracting muliples of row 1 from rows 2 3 4\n",
+ "R2 = R2 - 2*R1\n",
+ "R3 = R3 - 4*R1\n",
+ "R4 = R4 - R1\n",
+ "A = \n",
+ "[[ 1 -1 2 3]\n",
+ " [ 0 4 -4 -4]\n",
+ " [ 0 5 -9 -13]\n",
+ " [ 0 3 1 -3]]\n",
+ "We obtain the same determinant as before.\n",
+ "Now, applying some more row transformations as:\n",
+ "R3 = R3 - 5/4 * R2\n",
+ "R4 = R4 - 3/4 * R2\n",
+ "We get B as:\n",
+ "B = \n",
+ "[[ 1 -1 2 3]\n",
+ " [ 0 4 -4 -4]\n",
+ " [ 0 0 -4 -8]\n",
+ " [ 0 0 4 0]]\n",
+ "Now,determinant of A and B will be same\n",
+ "det A = det B = 128.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "import numpy as np\n",
+ "\n",
+ "print 'Given Matrix:'\n",
+ "A = np.array([[1, -1, 2, 3],[ 2, 2, 0, 2],[ 4, 1 ,-1, -1],[1, 2, 3, 0]])\n",
+ "print 'A = \\n',A\n",
+ "print 'After, Subtracting muliples of row 1 from rows 2 3 4'\n",
+ "print 'R2 = R2 - 2*R1'\n",
+ "A[1,:] = A[1,:] - 2 * A[0,:]\n",
+ "print 'R3 = R3 - 4*R1'\n",
+ "A[2,:] = A[2,:] - 4 * A[0,:]\n",
+ "print 'R4 = R4 - R1'\n",
+ "A[3,:] = A[3,:] - A[0,:]\n",
+ "print 'A = \\n',A\n",
+ "T = A# #Temporary matrix to store A\n",
+ "print 'We obtain the same determinant as before.'\n",
+ "print 'Now, applying some more row transformations as:'\n",
+ "print 'R3 = R3 - 5/4 * R2'\n",
+ "T[2,:] = T[2,:] - 5./4 * T[1,:]\n",
+ "print 'R4 = R4 - 3/4 * R2'\n",
+ "T[3,:] = T[3,:] - 3./4 * T[1,:]\n",
+ "B = T#\n",
+ "print 'We get B as:'\n",
+ "print 'B = \\n',B\n",
+ "print 'Now,determinant of A and B will be same'\n",
+ "print 'det A = det B = ',np.linalg.det(B)\n",
+ " "
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Page 160 Example 5.7"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 18,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "A = \n",
+ "Matrix([[x**2 + x, x + 1], [x - 1, 1]])\n",
+ "B = \n",
+ "Matrix([[x**2 - 1, x + 2], [x**2 - 2*x + 3, x]])\n",
+ "det A = x + 1\n",
+ "det B = -6\n",
+ "Thus, A is not invertible over K whereas B is invertible\n",
+ "adj A = Matrix([[(x + 1)*((x - 1)/(x*(x + 1)) + 1/(x*(x + 1))), -x - 1], [-x + 1, x*(x + 1)]])\n",
+ "adj B = Matrix([[-6*(x + 2)*(-x**2/6 + 1/6)*(x**2 - 2*x + 3)/(x**2 - 1)**2 - 6/(x**2 - 1), 6*(x + 2)*(-x**2/6 + 1/6)/(x**2 - 1)], [6*(-x**2/6 + 1/6)*(x**2 - 2*x + 3)/(x**2 - 1), x**2 - 1]])\n",
+ "(adj A)A = (x+1)I\n",
+ "(adj B)B = -6I\n",
+ "B inverse = Matrix([[(x + 2)*(-x**2/6 + 1/6)*(x**2 - 2*x + 3)/(x**2 - 1)**2 + 1/(x**2 - 1), -(x + 2)*(-x**2/6 + 1/6)/(x**2 - 1)], [-(-x**2/6 + 1/6)*(x**2 - 2*x + 3)/(x**2 - 1), -x**2/6 + 1/6]])\n"
+ ]
+ }
+ ],
+ "source": [
+ "import sympy as sp\n",
+ "import numpy as np\n",
+ "\n",
+ "x = sp.Symbol(\"x\")\n",
+ "A = sp.Matrix(([x**2+x, x+1],[x-1, 1]))\n",
+ "B = sp.Matrix(([x**2-1, x+2],[x**2-2*x+3, x]))\n",
+ "print 'A = \\n',A\n",
+ "print 'B = \\n',B\n",
+ "print 'det A = ',A.det()\n",
+ "print 'det B = ',B.det()\n",
+ "print 'Thus, A is not invertible over K whereas B is invertible'\n",
+ "\n",
+ "print 'adj A = ',(A**-1)*A.det()\n",
+ "print 'adj B = ',(B**-1)*B.det()\n",
+ "print '(adj A)A = (x+1)I'\n",
+ "print '(adj B)B = -6I'\n",
+ "print 'B inverse = ',B**-1"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Page 161 Example 5.8"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 19,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "A = \n",
+ "[[1 2]\n",
+ " [3 4]]\n",
+ "det A = Determinant of A is: -2.0\n",
+ "Adjoint of A is: [[-2. -0. ]\n",
+ " [-0. -0.5]]\n",
+ "Thus, A is not invertible as a matrix over the ring of integers.\n",
+ "But, A can be regarded as a matrix over field of rational numbers.\n",
+ "Then, A is invertible and Inverse of A is: [[-2. 1. ]\n",
+ " [ 1.5 -0.5]]\n"
+ ]
+ }
+ ],
+ "source": [
+ "import numpy as np\n",
+ "\n",
+ "A = np.array([[1, 2],[3, 4]])\n",
+ "print 'A = \\n',A\n",
+ "d = np.linalg.det(A)#\n",
+ "print 'det A = ','Determinant of A is:',d\n",
+ "\n",
+ "\n",
+ "ad = (d* np.identity(2)) / A\n",
+ "print 'Adjoint of A is:',ad\n",
+ "\n",
+ "\n",
+ "print 'Thus, A is not invertible as a matrix over the ring of integers.'\n",
+ "print 'But, A can be regarded as a matrix over field of rational numbers.'\n",
+ "In = np.linalg.inv(A)#\n",
+ "#The A inverse matrix given in book has a wrong entry of 1/2. It should be -1/2.\n",
+ "print 'Then, A is invertible and Inverse of A is:',In\n"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/Linear_Algebra_by_K._Hoffman_and_R._Kunze/Chapter6_1.ipynb b/Linear_Algebra_by_K._Hoffman_and_R._Kunze/Chapter6_1.ipynb
new file mode 100644
index 00000000..9ad1cbe2
--- /dev/null
+++ b/Linear_Algebra_by_K._Hoffman_and_R._Kunze/Chapter6_1.ipynb
@@ -0,0 +1,503 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 6 - Elementary canonical forms"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Page 184 Example 6.1"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 26,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Standard ordered matrix for Linear operator T on R**2 is:\n",
+ "A = \n",
+ "Matrix([[0, -1], [1, 0]])\n",
+ "The characteristic polynomial for T or A is: Matrix([[x, 1], [-1, x]])\n",
+ "Since this polynomial has no real roots,T has no characteristic values.\n"
+ ]
+ }
+ ],
+ "source": [
+ "import sympy as sp\n",
+ "print 'Standard ordered matrix for Linear operator T on R**2 is:'\n",
+ "A = sp.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",
+ "print p\n",
+ "print 'Since this polynomial has no real roots,T has no characteristic values.'"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Page 184 Example 6.2"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 27,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "A = \n",
+ "Matrix([[3, 1, -1], [2, 2, -1], [2, 2, 0]])\n",
+ "Characteristic polynomial for A is: x**3 - 5*x**2 + 8*x - 4\n",
+ "or\n",
+ "(x-1)(x-2)**2\n",
+ "The characteristic values of A are:\n",
+ "[1, 2]\n",
+ "Now, A-I = \n",
+ "Matrix([[2, 1, -1], [2, 1, -1], [2, 2, -1]])\n",
+ "rank of A - I= 2\n",
+ "So, nullity of T-I = 1\n",
+ "The vector that spans the null space of T-I = [1, 0, 2]\n",
+ "Now,A-2I = \n",
+ "Matrix([[1, 1, -1], [2, 0, -1], [2, 2, -2]])\n",
+ "rank of A - 2I= 2\n",
+ "T*alpha = 2*alpha if alpha is a scalar multiple of a2\n",
+ "a2 = [1, 1, 2]\n"
+ ]
+ }
+ ],
+ "source": [
+ "import sympy as sp\n",
+ "A = sp.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",
+ "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",
+ "[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",
+ "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",
+ "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",
+ "a2 = [1 ,1 ,2]\n",
+ "print 'a2 = ',a2"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Page 187 Example 6.3"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 28,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Standard ordered matrix for Linear operator T on R**3 is:\n",
+ "A = \n",
+ "Matrix([[5, -6, -6], [-1, 4, 2], [3, -6, -4]])\n",
+ "xI - A = \n",
+ "Matrix([[x - 5, 6, 6], [1, x - 4, -2], [-3, 6, x + 4]])\n",
+ "Applying row and column transformations:\n",
+ "C2 = C2 - C3\n",
+ "=>\n",
+ "Matrix([[x - 5, 0, 6], [1, x - 2, -2], [-3, -x + 2, x + 4]])\n",
+ "Taking (x-2) common from C2\n",
+ "=>\n",
+ " * x - 2\n",
+ "Matrix([[x - 5, 0, 6], [1, 1, -2], [-3, (-x + 2)/(x - 2), x + 4]])\n",
+ "R3 = R3 + R2\n",
+ "=>\n",
+ " * x - 2\n",
+ "Matrix([[x - 5, 0, 6], [1, 1, -2], [-2, (-x + 2)/(x - 2) + 1, x + 2]])\n",
+ "=>\n",
+ " * x - 2\n",
+ "Matrix([[x - 5, 6], [-2, x + 2]])\n",
+ "=>\n",
+ " * x - 2\n",
+ "x**2 - 3*x + 2\n",
+ "This is the characteristic polynomial\n",
+ "Now, A - I = Matrix([[4, -6, -6], [-1, 3, 2], [3, -6, -5]])\n",
+ "And, A- 2I = Matrix([[3, -6, -6], [-1, 2, 2], [3, -6, -6]])\n",
+ "rank(A-I) = 2\n",
+ "rank(A-2I) = 2\n",
+ "W1,W2 be the spaces of characteristic vectors associated with values 1,2\n",
+ "So by theorem 2, T is diagonalizable\n",
+ "Null space of (T- I) i.e basis of W1 is spanned by a1 = [[ 3 -1 3]]\n",
+ "Null space of (T- 2I) i.e. basis of W2 is spanned by vectors x1,x2,x3 such that x1 = 2x1 + 2x3\n",
+ "One example :\n",
+ "a2 = [[2 1 0]]\n",
+ "a3 = [[2 0 1]]\n",
+ "The diagonal matrix is:\n",
+ "D = [[1 0 0]\n",
+ " [0 2 0]\n",
+ " [0 0 2]]\n",
+ "The standard basis matrix is denoted as:\n",
+ "P = [[ 3 2 2]\n",
+ " [-1 1 0]\n",
+ " [ 3 0 1]]\n",
+ "AP = Matrix([[3, 4, 4], [-1, 2, 0], [3, 0, 2]])\n",
+ "PD = [[3 0 0]\n",
+ " [0 2 0]\n",
+ " [0 0 2]]\n",
+ "That is, AP = PD\n",
+ "=> inverse(P)*A*P = D\n"
+ ]
+ }
+ ],
+ "source": [
+ "import sympy as sp\n",
+ "import numpy as np\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",
+ "print 'A = \\n',A\n",
+ "print 'xI - A = '\n",
+ "B = sp.eye(3)\n",
+ "x = sp.Symbol('x')\n",
+ "P = x*B - A#\n",
+ "print P\n",
+ "\n",
+ "print 'Applying row and column transformations:'\n",
+ "print 'C2 = C2 - C3'\n",
+ "P[:,1] = P[:,1] - P[:,2]\n",
+ "print '=>'\n",
+ "print P\n",
+ "print 'Taking (x-2) common from C2'\n",
+ "c = x-2#\n",
+ "P[:,1] = P[:,1] / (x-2)\n",
+ "print '=>'\n",
+ "print ' * ', c\n",
+ "print P\n",
+ "print 'R3 = R3 + R2'\n",
+ "P[2,:] = P[2,:] + P[1,:]\n",
+ "print '=>'\n",
+ "print ' * ', c\n",
+ "print P\n",
+ "P = sp.Matrix(([P[0,0], P[0,2]],[P[2,0], P[2,2]]))\n",
+ "print '=>'\n",
+ "print ' * ', c\n",
+ "print P\n",
+ "print '=>'\n",
+ "print ' * ',c\n",
+ "print P.det()\n",
+ "print 'This is the characteristic polynomial'\n",
+ "\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",
+ "\n",
+ "print 'rank(A-2I) = ',np.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",
+ "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",
+ "print 'D = ',D\n",
+ "print 'The standard basis matrix is denoted as:'\n",
+ "P = np.transpose(np.vstack([a1,a2,a3]))\n",
+ "print 'P = ',P\n",
+ "print 'AP = ',A*P\n",
+ "print 'PD = ',P*D\n",
+ "print 'That is, AP = PD'\n",
+ "print '=> inverse(P)*A*P = D'"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Page 193 Example 6.4"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 29,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "A = \n",
+ "[[ 5 -6 -6]\n",
+ " [-1 4 2]\n",
+ " [ 3 -6 -4]]\n",
+ "Characteristic polynomial of A is:\n",
+ "f = (x-1)(x-2)**2\n",
+ "i.e., f = (x - 2)**2*(x - 1)\n",
+ "(A-I)(A-2I) = Matrix([[0, 0, 0], [0, 0, 0], [0, 0, 0]])\n",
+ "Since, (A-I)(A-2I) = 0. So, Minimal polynomial for above is:\n",
+ "p = (x - 2)*(x - 1)\n",
+ "---------------------------------------\n",
+ "A = \n",
+ "[[ 3 1 -1]\n",
+ " [ 2 2 -1]\n",
+ " [ 2 2 0]]\n",
+ "Characteristic polynomial of A is:\n",
+ "f = (x-1)(x-2)**2\n",
+ "i.e., f = (x - 2)**2*(x - 1)\n",
+ "(A-I)(A-2I) = Matrix([[2, 0, -1], [2, 0, -1], [4, 0, -2]])\n",
+ "Since, (A-I)(A-2I) is not equal to 0. T is not diagonalizable. So, Minimal polynomial cannot be p.\n",
+ "---------------------------------------\n",
+ "A = \n",
+ "[[ 0 -1]\n",
+ " [ 1 0]]\n",
+ "Characteristic polynomial of A is:\n",
+ "f = x**2 + 1\n",
+ "A**2 + I = Matrix([[1, 1], [1, 1]])\n",
+ "Since, A**2 + I = 0, so minimal polynomial is\n",
+ "p = x**2 + 1\n"
+ ]
+ }
+ ],
+ "source": [
+ "import numpy as np\n",
+ "import sympy as sp\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",
+ "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 '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",
+ "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 '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",
+ "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 'Since, A**2 + I = 0, so minimal polynomial is'\n",
+ "p = x**2 + 1\n",
+ "print 'p = ',p"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Page 197 Example 6.5"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 30,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "A = \n",
+ "[[0 1 0 1]\n",
+ " [1 0 1 0]\n",
+ " [0 1 0 1]\n",
+ " [1 0 1 0]]\n",
+ "Computing powers on A:\n",
+ "A**2 = \n",
+ "[[0 1 0 1]\n",
+ " [1 0 1 0]\n",
+ " [0 1 0 1]\n",
+ " [1 0 1 0]]\n",
+ "A**3 = \n",
+ "[[0 1 0 1]\n",
+ " [1 0 1 0]\n",
+ " [0 1 0 1]\n",
+ " [1 0 1 0]]\n",
+ "if p = x**3 - 4x, then\n",
+ "p(A) = [[ 0 -3 0 -3]\n",
+ " [-3 0 -3 0]\n",
+ " [ 0 -3 0 -3]\n",
+ " [-3 0 -3 0]]\n",
+ "Minimal polynomial for A is: x**3 - 4*x\n",
+ "Characteristic values for A are: [-2, 0, 2]\n",
+ "Rank(A) = 2\n",
+ "So, from theorem 2, characteristic polynomial for A is: x**4 - 4*x**2\n"
+ ]
+ }
+ ],
+ "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",
+ "print 'A = \\n',A\n",
+ "print 'Computing powers on A:'\n",
+ "print 'A**2 = \\n',A*A\n",
+ "print 'A**3 = \\n',A*A*A\n",
+ "def p(x):\n",
+ " pp = x**3 - 4*x\n",
+ " return pp\n",
+ "print 'if p = x**3 - 4x, then'\n",
+ "print 'p(A) = ',p(A)\n",
+ "x = sp.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()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Page 210 Example 6.12"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 31,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "A = \n",
+ "[[ 9. 1. 3.]\n",
+ " [ 10. 1. 3.]\n",
+ " [ 10. 5. 1.]]\n",
+ "A transpose is:\n",
+ "A' = \n",
+ "[[ 9. 10. 10.]\n",
+ " [ 1. 1. 5.]\n",
+ " [ 3. 3. 1.]]\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",
+ "A2 = \n",
+ "[[ 0. -4.5 -3.5]\n",
+ " [ 4.5 0. -1. ]\n",
+ " [ 3.5 1. 0. ]]\n",
+ "A1 + A2 = \n",
+ "[[ 9. 1. 3.]\n",
+ " [ 10. 1. 3.]\n",
+ " [ 10. 5. 1.]]\n"
+ ]
+ }
+ ],
+ "source": [
+ "import numpy as np\n",
+ "\n",
+ "A = np.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",
+ "print \"A' = \\n\",Adash\n",
+ "if np.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",
+ " 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",
+ "\n",
+ "A1 = 1./2*(A + Adash)\n",
+ "A2 = 1./2*(A - Adash)\n",
+ "print 'A can be expressed as sum of A1 and A2'\n",
+ "print 'i.e., A = A1 + A2'\n",
+ "print 'A1 = \\n',A1\n",
+ "print 'A2 = \\n',A2\n",
+ "print 'A1 + A2 = \\n',A1 + A2"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/Linear_Algebra_by_K._Hoffman_and_R._Kunze/Chapter7_1.ipynb b/Linear_Algebra_by_K._Hoffman_and_R._Kunze/Chapter7_1.ipynb
new file mode 100644
index 00000000..bd958b35
--- /dev/null
+++ b/Linear_Algebra_by_K._Hoffman_and_R._Kunze/Chapter7_1.ipynb
@@ -0,0 +1,239 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 7 - The rational and jordan forms"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Page 239 Example 7.3"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "A = \n",
+ "Matrix([[5, -6, -6], [-1, 4, 2], [3, -6, -4]])\n",
+ "Characteristic polynomial for linear operator T on R**3 will be:\n",
+ "f = x**3 - 5*x**2 + 8*x - 4\n",
+ "or\n",
+ "(x-1)(x-2)**2\n",
+ "The minimal polynomial for T is:\n",
+ "p = (x - 2)*(x - 1)\n",
+ "or\n",
+ "p = (x-1)(x-2)\n",
+ "So in cyclic decomposition of T, a1 will have p as its T-annihilator.\n",
+ "Another vector a2 that generate cyclic subspace of dimension 1 will have its T-annihilator as p2.\n",
+ "p2 = x - 2\n",
+ "pp2 = (x - 2)**2*(x - 1)\n",
+ "i.e., pp2 = f\n",
+ "Therefore, A is similar to B\n",
+ "B = \n",
+ "[[ 0 -2 0]\n",
+ " [ 1 3 0]\n",
+ " [ 0 0 2]]\n",
+ "Thus, we can see thet Matrix of T in ordered basis is B\n"
+ ]
+ }
+ ],
+ "source": [
+ "import numpy as np\n",
+ "import sympy as sp\n",
+ "A = sp.Matrix(([5, -6, -6],[-1, 4 ,2],[3, -6, -4]))\n",
+ "print 'A = \\n',A\n",
+ "x=sp.Symbol('x')\n",
+ "f = A.charpoly(x).as_expr()\n",
+ "print 'Characteristic polynomial for linear operator T on R**3 will be:'\n",
+ "print 'f = ',f\n",
+ "print 'or'\n",
+ "print '(x-1)(x-2)**2'\n",
+ "print 'The minimal polynomial for T is:'\n",
+ "p = (x-1)*(x-2)#\n",
+ "print 'p = ',p\n",
+ "print 'or'\n",
+ "print 'p = (x-1)(x-2)'\n",
+ "print 'So in cyclic decomposition of T, a1 will have p as its T-annihilator.'\n",
+ "print 'Another vector a2 that generate cyclic subspace of dimension 1 will have its T-annihilator as p2.'\n",
+ "p2 = x-2#\n",
+ "print 'p2 = ',p2\n",
+ "print 'pp2 = ',p*p2\n",
+ "print 'i.e., pp2 = f'\n",
+ "print 'Therefore, A is similar to B'\n",
+ "B = np.array([[0, -2, 0],[1, 3, 0],[0, 0 ,2]])\n",
+ "print 'B = \\n',B\n",
+ "print 'Thus, we can see thet Matrix of T in ordered basis is B'"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Page 247 Example 7.6"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "A = \n",
+ "2 0 0\n",
+ "a 2 0\n",
+ "b c -1\n",
+ "A = \n",
+ "Matrix([[2, 0, 0], [1, 2, 0], [0, 0, -1]])\n",
+ "Characteristic polynomial for A is:\n",
+ "p = x**3 - 3*x**2 + 4\n",
+ "In this case, minimal polynomial is same as characteristic polynomial.\n",
+ "-----------------------------------------\n",
+ "A = \n",
+ "Matrix([[2, 0, 0], [0, 2, 0], [0, 0, -1]])\n",
+ "Characteristic polynomial for A is:\n",
+ "p = x**3 - 3*x**2 + 4\n",
+ "In this case, minimal polynomial is: (x-2)(x+1)\n",
+ "or\n",
+ "(x - 2)*(x + 1)\n",
+ "(A-2I)(A+I) = \n",
+ "0 0 0\n",
+ "3a 0 0\n",
+ "ac 0 0\n",
+ "if a = 0, A is similar to diagonal matrix.\n"
+ ]
+ }
+ ],
+ "source": [
+ "import numpy as np\n",
+ "import sympy as sp\n",
+ "print 'A = '\n",
+ "print '2 0 0'\n",
+ "print 'a 2 0'\n",
+ "print 'b c -1'\n",
+ "a = 1#\n",
+ "b = 0#\n",
+ "c = 0#\n",
+ "A = sp.Matrix(([2, 0, 0],[a, 2, 0],[b, c, -1]))\n",
+ "print 'A = \\n',A\n",
+ "print 'Characteristic polynomial for A is:'\n",
+ "x=sp.Symbol('x')\n",
+ "print 'p = ',A.charpoly(x).as_expr()\n",
+ "print 'In this case, minimal polynomial is same as characteristic polynomial.'\n",
+ "print '-----------------------------------------'\n",
+ "a = 0#\n",
+ "b = 0#\n",
+ "c = 0#\n",
+ "A = sp.Matrix(([2, 0, 0],[a, 2, 0],[b, c, -1]))\n",
+ "print 'A = \\n',A\n",
+ "print 'Characteristic polynomial for A is:'\n",
+ "x=sp.Symbol('x')\n",
+ "print 'p = ',A.charpoly(x).as_expr()\n",
+ "print 'In this case, minimal polynomial is:',\n",
+ "print '(x-2)(x+1)'\n",
+ "print 'or'\n",
+ "s = (x-2)*(x+1)#\n",
+ "print s\n",
+ "print '(A-2I)(A+I) = '\n",
+ "print '0 0 0'\n",
+ "print '3a 0 0'\n",
+ "print 'ac 0 0'\n",
+ "print 'if a = 0, A is similar to diagonal matrix.'"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Page 247 Example 7.7"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "A = \n",
+ "2 0 0 0\n",
+ "1 2 0 0\n",
+ "0 0 2 0\n",
+ "0 0 a 2\n",
+ "Considering a = 1\n",
+ "Characteristic polynomial for A is:\n",
+ "p = x**4 - 8*x**3 + 24*x**2 - 32*x + 16\n",
+ "or\n",
+ "(x-2)**4\n",
+ "Minimal polynomial for A =\n",
+ "(x-2)**2\n",
+ "For a = 0 and a = 1, characteristic and minimal polynomial are same.\n",
+ "But for a=0, the solution space of (A - 2I) has 3 dimension whereas for a = 1, it has 2 dimension. \n"
+ ]
+ }
+ ],
+ "source": [
+ "import numpy as np\n",
+ "import sympy as sp\n",
+ "print 'A = '\n",
+ "print '2 0 0 0'\n",
+ "print '1 2 0 0'\n",
+ "print '0 0 2 0'\n",
+ "print '0 0 a 2'\n",
+ "print 'Considering a = 1'\n",
+ "A = sp.Matrix(([2, 0 ,0 ,0],[1, 2, 0, 0],[0, 0 ,2 ,0],[0, 0, 1, 2]))\n",
+ "x=sp.Symbol('x')\n",
+ "p = A.charpoly(x).as_expr()\n",
+ "print 'Characteristic polynomial for A is:'\n",
+ "print 'p = ',p\n",
+ "print 'or'\n",
+ "print '(x-2)**4'\n",
+ "print 'Minimal polynomial for A ='\n",
+ "print '(x-2)**2'\n",
+ "print 'For a = 0 and a = 1, characteristic and minimal polynomial are same.'\n",
+ "print 'But for a=0, the solution space of (A - 2I) has 3 dimension whereas for a = 1, it has 2 dimension. '"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/Linear_Algebra_by_K._Hoffman_and_R._Kunze/Chapter8_1.ipynb b/Linear_Algebra_by_K._Hoffman_and_R._Kunze/Chapter8_1.ipynb
new file mode 100644
index 00000000..6f1bfe72
--- /dev/null
+++ b/Linear_Algebra_by_K._Hoffman_and_R._Kunze/Chapter8_1.ipynb
@@ -0,0 +1,561 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 8 - Inner product spaces"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Page 271 Example 8.1"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 16,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "n = 5\n",
+ "a = [[ 1. 4. 2. 8. 8.]]\n",
+ "b = [[ 10. 8. 3. 1. 8.]]\n",
+ "Then, (a|b) = \n",
+ "\n",
+ "[[ 10. 40. 20. 80. 80.]\n",
+ " [ 8. 32. 16. 64. 64.]\n",
+ " [ 3. 12. 6. 24. 24.]\n",
+ " [ 1. 4. 2. 8. 8.]\n",
+ " [ 8. 32. 16. 64. 64.]]\n"
+ ]
+ }
+ ],
+ "source": [
+ "import numpy as np\n",
+ "n=np.random.randint(2,9)\n",
+ "a=np.random.rand(1,n)\n",
+ "b=np.random.rand(1,n)\n",
+ "for i in range(0,n):\n",
+ " a[0,i]=round(a[0,i]*10)\n",
+ " b[0,i]=round(b[0,i]*10)\n",
+ "print 'n = ',n\n",
+ "print 'a = ',a\n",
+ "print 'b = ',b\n",
+ "print 'Then, (a|b) = \\n\\n',a*np.transpose(b)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Page 271 Example 8.2"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 17,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "a = [[ 4. 3.]]\n",
+ "b = [[ 7. 5.]]\n",
+ "Then, a|b = 47.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "import numpy as np\n",
+ "a=np.random.rand(1,2)\n",
+ "b=np.random.rand(1,2)\n",
+ "for i in range(0,2):\n",
+ " a[0,i]=round(a[0,i]*10)\n",
+ " b[0,i]=round(b[0,i]*10)\n",
+ "print 'a = ',a\n",
+ "print 'b = ',b\n",
+ "x1 = a[0,0]#\n",
+ "x2 = a[0,1]#\n",
+ "y1 = b[0,0]#\n",
+ "y2 = b[0,1]#\n",
+ "t = x1*y1 - x2*y1 - x1*y2 + 4*x2*y2#\n",
+ "print 'Then, a|b = ',t"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Page 307 Example 8.28"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 18,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "x1 and x2 are two real nos. i.e., x1**2 + x2**2 = 1\n",
+ "x1 = 0.383547227589\n",
+ "x2 = 0.923521263539\n",
+ "B = \n",
+ "[[ 0.38354723 0.92352126 0. ]\n",
+ " [ 0. 1. 0. ]\n",
+ " [ 0. 0. 1. ]]\n",
+ "Applying Gram-Schmidt process to B:\n",
+ "a1 = [ 0.38354723 0.92352126 0. ]\n",
+ "a2 = [-0.35421402 0.14710848 0. ]\n",
+ "a3 = [0 0 1]\n",
+ "U = \n",
+ "[[[ 0.38354723 0.92352126 0. ]]\n",
+ "\n",
+ " [[-0.92352126 0.38354723 0. ]]\n",
+ "\n",
+ " [[ 0. 0. 1. ]]]\n",
+ "M = \n",
+ "[[ 1. 0. 0. ]\n",
+ " [-2.40784236 2.60724085 0. ]\n",
+ " [ 0. 0. 1. ]]\n",
+ "inverse(M) * U = [[[ 3.83547228e-01 -4.25822963e-17 0.00000000e+00]\n",
+ " [ 3.54214020e-01 3.54214020e-01 0.00000000e+00]\n",
+ " [ 0.00000000e+00 0.00000000e+00 0.00000000e+00]]\n",
+ "\n",
+ " [[ -9.23521264e-01 -1.76848356e-17 0.00000000e+00]\n",
+ " [ -8.52891524e-01 1.47108476e-01 0.00000000e+00]\n",
+ " [ -0.00000000e+00 0.00000000e+00 0.00000000e+00]]\n",
+ "\n",
+ " [[ 0.00000000e+00 -0.00000000e+00 0.00000000e+00]\n",
+ " [ 0.00000000e+00 0.00000000e+00 0.00000000e+00]\n",
+ " [ 0.00000000e+00 0.00000000e+00 1.00000000e+00]]]\n",
+ "So, B = inverse(M) * U\n"
+ ]
+ }
+ ],
+ "source": [
+ "import numpy as np\n",
+ "print 'x1 and x2 are two real nos. i.e., x1**2 + x2**2 = 1'\n",
+ "x1 = np.random.rand()\n",
+ "x2 = np.sqrt(1 - x1**2)\n",
+ "print 'x1 = ',x1\n",
+ "print 'x2 = ',x2\n",
+ "B = np.array([[x1, x2, 0],[0, 1, 0],[0, 0, 1]])\n",
+ "print 'B = \\n',B\n",
+ "print 'Applying Gram-Schmidt process to B:'\n",
+ "a1 = np.array([x1, x2, 0])\n",
+ "a2 = np.array([0 ,1 ,0]) - x2 * np.array([x1 ,x2 ,0])\n",
+ "a3 = np.array([0, 0, 1])\n",
+ "print 'a1 = ',a1\n",
+ "print 'a2 = ',a2\n",
+ "print 'a3 = ',a3\n",
+ "U = np.array([[a1],[a2/x1],[a3]])\n",
+ "print 'U = \\n',U\n",
+ "M = np.array([[1, 0, 0],[-x2/x1, 1/x1, 0],[0, 0, 1]])\n",
+ "print 'M = \\n',M\n",
+ "print 'inverse(M) * U = ',np.linalg.inv(M) * U\n",
+ "print 'So, B = inverse(M) * U'"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Page 278 Example 8.9"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 19,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "(x,y) = [[ 5. 3.]]\n",
+ "(-y,x) = [-3.0, 5.0]\n",
+ "Inner product of these vectors is:\n",
+ "(x,y)|(-y,x) = 0.0\n",
+ "So, these are orthogonal.\n",
+ "------------------------------------------\n",
+ "If inner product is defined as:\n",
+ "(x1,x2)|(y1,y2) = x1y1- x2y1 - x1y2 + 4x2y2\n",
+ "Then, (x,y)|(-y,x) = -x*y+y**2-x**2+4*x*y = 0 if,\n",
+ "y = 1/2(-3 + sqrt(13))*x\n",
+ "or\n",
+ "y = 1/2(-3 - sqrt(13))*x\n",
+ "Hence,\n",
+ "[[ 5. 3.]]\n",
+ "is orthogonal to\n",
+ "[-3.0, 5.0]\n"
+ ]
+ }
+ ],
+ "source": [
+ "import numpy as np\n",
+ "#a = round(rand(1,2) * 10)#\n",
+ "a=np.random.rand(1,2)\n",
+ "for j in [0,1]:\n",
+ " a[0,j]=round(a[0,j]*10)\n",
+ "\n",
+ "x = a[0,0]\n",
+ "y = a[0,1]\n",
+ "b = [-y, x]#\n",
+ "print '(x,y) = ',a\n",
+ "print '(-y,x) = ',b\n",
+ "print 'Inner product of these vectors is:'\n",
+ "t = -x*y + y*x#\n",
+ "print '(x,y)|(-y,x) = ',t\n",
+ "\n",
+ "print 'So, these are orthogonal.'\n",
+ "print '------------------------------------------'\n",
+ "print 'If inner product is defined as:'\n",
+ "print '(x1,x2)|(y1,y2) = x1y1- x2y1 - x1y2 + 4x2y2'\n",
+ "print 'Then, (x,y)|(-y,x) = -x*y+y**2-x**2+4*x*y = 0 if,'\n",
+ "print 'y = 1/2(-3 + sqrt(13))*x'\n",
+ "print 'or'\n",
+ "print 'y = 1/2(-3 - sqrt(13))*x'\n",
+ "print 'Hence,'\n",
+ "if y == (1./2*(-3 + np.sqrt(13))*x) or (1./2*(-3 - np.sqrt(13))*x):\n",
+ " print a\n",
+ " print 'is orthogonal to'\n",
+ " print b\n",
+ "else:\n",
+ " print a\n",
+ " print 'is not orthogonal to'\n",
+ " print b\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Page 282 Example 8.12"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 20,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "b1 = [3 0 4]\n",
+ "b2 = [-1 0 7]\n",
+ "b3 = [ 2 9 11]\n",
+ "Applying the Gram-Schmidt process to b1,b2,b3:\n",
+ "a1 = [3 0 4]\n",
+ "a2 = [2 0 3]\n",
+ "a3 = [2 9 4]\n",
+ "{a1,a2,a3} are mutually orthogonal and hence forms orthogonal basis for R**3\n",
+ "Any arbitrary vector {x1,x2,x3} in R**3 can be expressed as:\n",
+ "y = {x1,x2,x3} = (3*x1 + 4*x3)/25*a1 + (-4*x1 + 3*x3)/25*a2 + x2/9*a3\n",
+ "x1 = 1\n",
+ "x2 = 2\n",
+ "x3 = 3\n",
+ "y = [0 0 0]\n",
+ "i.e. y = [x1 x2 x3], according to above equation.\n",
+ "Hence, we get the orthonormal basis as:\n",
+ ", [ 0.6 0. 0.8]\n",
+ ", [ 0.4 0. 0.6]\n",
+ "[ 0.22222222 1. 0.44444444]\n"
+ ]
+ }
+ ],
+ "source": [
+ "import numpy as np\n",
+ "b1 = np.array([3, 0, 4])\n",
+ "b2 = np.array([-1 ,0 ,7])\n",
+ "b3 = np.array([2 ,9 ,11])\n",
+ "print 'b1 = ',b1\n",
+ "print 'b2 = ',b2\n",
+ "print 'b3 = ',b3\n",
+ "print 'Applying the Gram-Schmidt process to b1,b2,b3:'\n",
+ "a1 = b1\n",
+ "print 'a1 = ',a1\n",
+ "a2 = b2-(np.transpose((b2*np.transpose(b1)))/25*b1)\n",
+ "print 'a2 = ',a2\n",
+ "a3 = b3-(np.transpose(b3*np.transpose(b1))/25*b1) - (np.transpose(b3*np.transpose(a2))/25*a2)\n",
+ "print 'a3 = ',a3\n",
+ "print '{a1,a2,a3} are mutually orthogonal and hence forms orthogonal basis for R**3'\n",
+ "print 'Any arbitrary vector {x1,x2,x3} in R**3 can be expressed as:'\n",
+ "print 'y = {x1,x2,x3} = (3*x1 + 4*x3)/25*a1 + (-4*x1 + 3*x3)/25*a2 + x2/9*a3'\n",
+ "x1 = 1#\n",
+ "x2 = 2#\n",
+ "x3 = 3#\n",
+ "y = (3*x1 + 4*x3)/25*a1 + (-4*x1 + 3*x3)/25*a2 + x2/9*a3#\n",
+ "print 'x1 = ',x1\n",
+ "print 'x2 = ',x2\n",
+ "print 'x3 = ',x3\n",
+ "print 'y = ',y\n",
+ "print 'i.e. y = [x1 x2 x3], according to above equation.'\n",
+ "print 'Hence, we get the orthonormal basis as:'\n",
+ "\n",
+ "print ',',1./5*a1\n",
+ "print ',',1./5*a2\n",
+ "print 1/9.*a3"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Page 283 Example 8.13"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 21,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "A = [[ 1.25598176 1.81258697]\n",
+ " [ 0.6193707 0.80341686]]\n",
+ "b1 = [ 1.25598176 1.81258697]\n",
+ "b2 = [ 0.6193707 0.80341686]\n",
+ "Applying the orthogonalization process to b1,b2:\n",
+ "[1.255981755902444, 1.8125869670307564] a1 = \n",
+ "[] a2 = \n",
+ "a2 is not equal to zero if and only if b1 and b2 are linearly independent.\n",
+ "That is, if determinant of A is non-zero.\n"
+ ]
+ }
+ ],
+ "source": [
+ "import numpy as np\n",
+ "A = np.random.rand(2,2)\n",
+ "A[0,:] = A[0,:] + 1# #so b1 is not equal to zero\n",
+ "a = A[0,0]\n",
+ "b = A[0,1]\n",
+ "c = A[1,0]\n",
+ "d = A[1,1]\n",
+ "b1 = A[0,:]\n",
+ "b2 = A[1,:]\n",
+ "print 'A = ',A\n",
+ "print 'b1 = ',b1\n",
+ "print 'b2 = ',b2\n",
+ "print 'Applying the orthogonalization process to b1,b2:'\n",
+ "\n",
+ "a1 = [a, b]\n",
+ "a2 = (np.linalg.det(A)/(a**2 + b**2))*[-np.transpose(b), np.transpose(a)]\n",
+ "print a1,'a1 = '\n",
+ "print a2,'a2 = '\n",
+ "print 'a2 is not equal to zero if and only if b1 and b2 are linearly independent.'\n",
+ "print 'That is, if determinant of A is non-zero.'"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Page 286 Example 8.14"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 22,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "v = [-10 2 8]\n",
+ "u = [ 3 12 -1]\n",
+ "Orthogonal projection of v1 on subspace W spanned by v2 is given by:\n",
+ "[-3 0 1]\n",
+ "Orthogonal projection of R**3 on W is the linear transformation E given by:\n",
+ "(x1,x2,x3) -> (3*x1 + 12*x2 - x3)/%d * (3 12 -1) 154\n",
+ "Rank(E) = 1\n",
+ "Nullity(E) = 2\n"
+ ]
+ }
+ ],
+ "source": [
+ "import numpy as np\n",
+ "v = np.array([-10 ,2 ,8])\n",
+ "u = np.array([3, 12, -1])\n",
+ "print 'v = ',v\n",
+ "print 'u = ',u\n",
+ "print 'Orthogonal projection of v1 on subspace W spanned by v2 is given by:'\n",
+ "a = (np.transpose(u*np.transpose(v)))/(u[0]**2 + u[1]**2 + u[2]**2) * u\n",
+ "print a\n",
+ "print 'Orthogonal projection of R**3 on W is the linear transformation E given by:'\n",
+ "print '(x1,x2,x3) -> (3*x1 + 12*x2 - x3)/%d * (3 12 -1)',(u[0]**2 + u[1]**2 + u[2]**2)\n",
+ "print 'Rank(E) = 1'\n",
+ "print 'Nullity(E) = 2'"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Page 288 Example 8.15"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 23,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "f = (sqrt(2)*cos(2*pi*t) + sqrt(2)*sin(4*pi*t))**2\n",
+ "Integration (f dt) in limits 0 to 1 = 2.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "from sympy.mpmath import quad,cos,sin,pi,sqrt\n",
+ "\n",
+ "#part c\n",
+ "print 'f = (sqrt(2)*cos(2*pi*t) + sqrt(2)*sin(4*pi*t))**2'\n",
+ "print 'Integration (f dt) in limits 0 to 1 = ',\n",
+ "x0 = 0#\n",
+ "x1 = 1#\n",
+ "X = quad(lambda t:(sqrt(2)*cos(2*pi*t) + sqrt(2)*sin(4*pi*t))**2,[x0,x1])\n",
+ "print X"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Page 294 Example 8.17"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 24,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Matrix of projection E in orthonormal basis is:\n",
+ "A = 1/154 * [[ 9 36 -3]\n",
+ " [ 36 144 -12]\n",
+ " [ -3 -12 1]]\n",
+ "A* = [[ 9 36 -3]\n",
+ " [ 36 144 -12]\n",
+ " [ -3 -12 1]]\n",
+ "Since, E = E* and A = A*, then A is also the matrix of E*\n",
+ "a1 = [154, 0, 0]\n",
+ "a2 = [145, -36, 3]\n",
+ "a3 = [-36, 10, 12]\n",
+ "{a1,a2,a3} is the basis.\n",
+ "Ea1 = [9, 36, -3]\n",
+ "Ea2 = [0, 0, 0]\n",
+ "Ea3 = [0, 0, 0]\n",
+ "Matrix B of E in the basis is:\n",
+ "B = \n",
+ "[[-1 0 0]\n",
+ " [-1 0 0]\n",
+ " [ 0 0 0]]\n",
+ "B* = \n",
+ "[[-1 -1 0]\n",
+ " [ 0 0 0]\n",
+ " [ 0 0 0]]\n",
+ "Since, B is not equal to B*, B is not the matrix of E*\n"
+ ]
+ }
+ ],
+ "source": [
+ "import numpy as np\n",
+ "#Equation given in example 14 is used.\n",
+ "def transform(x,y,z):\n",
+ " x1 = 3*x#\n",
+ " x2 = 12*y#\n",
+ " x3 = -z#\n",
+ " m = [x1 ,x2, x3]\n",
+ " return m\n",
+ "\n",
+ "print 'Matrix of projection E in orthonormal basis is:'\n",
+ "t1 = transform(3,3,3)#\n",
+ "t2 = transform(12,12,12)#\n",
+ "t3 = transform(-1,-1,-1)#\n",
+ "A = np.vstack([t1,t2,t3])#[t1# t2# t3]#\n",
+ "print 'A = 1/154 * ',A\n",
+ "\n",
+ "A1 = np.transpose(np.conj(A))\n",
+ "print 'A* = ',A1\n",
+ "print 'Since, E = E* and A = A*, then A is also the matrix of E*'\n",
+ "a1 = [154, 0, 0]#\n",
+ "a2 = [145 ,-36, 3]#\n",
+ "a3 = [-36 ,10 ,12]#\n",
+ "print 'a1 = ',a1\n",
+ "print 'a2 = ',a2\n",
+ "print 'a3 = ',a3\n",
+ "print '{a1,a2,a3} is the basis.'\n",
+ "Ea1 = [9 ,36 ,-3]#\n",
+ "Ea2 = [0 ,0, 0]#\n",
+ "Ea3 = [0 ,0 ,0]#\n",
+ "print 'Ea1 = ',Ea1\n",
+ "print 'Ea2 = ',Ea2\n",
+ "print 'Ea3 = ',Ea3\n",
+ "B = np.array([[-1, 0, 0],[-1, 0 ,0],[0, 0, 0]])\n",
+ "print 'Matrix B of E in the basis is:'\n",
+ "print 'B = \\n',B\n",
+ "B1 = np.transpose(np.conj(B))\n",
+ "print 'B* = \\n',B1\n",
+ "print 'Since, B is not equal to B*, B is not the matrix of E*'"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/Linear_Algebra_by_K._Hoffman_and_R._Kunze/screenshots/InverseMatrix_1.png b/Linear_Algebra_by_K._Hoffman_and_R._Kunze/screenshots/InverseMatrix_1.png
new file mode 100644
index 00000000..90f061e8
--- /dev/null
+++ b/Linear_Algebra_by_K._Hoffman_and_R._Kunze/screenshots/InverseMatrix_1.png
Binary files differ
diff --git a/Linear_Algebra_by_K._Hoffman_and_R._Kunze/screenshots/determinant_1.png b/Linear_Algebra_by_K._Hoffman_and_R._Kunze/screenshots/determinant_1.png
new file mode 100644
index 00000000..6ace8492
--- /dev/null
+++ b/Linear_Algebra_by_K._Hoffman_and_R._Kunze/screenshots/determinant_1.png
Binary files differ
diff --git a/Linear_Algebra_by_K._Hoffman_and_R._Kunze/screenshots/scalorpolynomial_1.png b/Linear_Algebra_by_K._Hoffman_and_R._Kunze/screenshots/scalorpolynomial_1.png
new file mode 100644
index 00000000..f75da6e2
--- /dev/null
+++ b/Linear_Algebra_by_K._Hoffman_and_R._Kunze/screenshots/scalorpolynomial_1.png
Binary files differ