summaryrefslogtreecommitdiff
path: root/Linear_Algebra_by_K._Hoffman_and_R._Kunze/Chapter1.ipynb
diff options
context:
space:
mode:
Diffstat (limited to 'Linear_Algebra_by_K._Hoffman_and_R._Kunze/Chapter1.ipynb')
-rw-r--r--[-rwxr-xr-x]Linear_Algebra_by_K._Hoffman_and_R._Kunze/Chapter1.ipynb121
1 files changed, 59 insertions, 62 deletions
diff --git a/Linear_Algebra_by_K._Hoffman_and_R._Kunze/Chapter1.ipynb b/Linear_Algebra_by_K._Hoffman_and_R._Kunze/Chapter1.ipynb
index b45b10cf..d1fed764 100755..100644
--- a/Linear_Algebra_by_K._Hoffman_and_R._Kunze/Chapter1.ipynb
+++ b/Linear_Algebra_by_K._Hoffman_and_R._Kunze/Chapter1.ipynb
@@ -82,8 +82,8 @@
}
],
"source": [
- "import numpy as np\n",
- "a = np.array([[2, -1, 3, 2],[1, 4, 0 ,-1],[2, 6, -1, 5]])\n",
+ "from numpy import array\n",
+ "a = 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",
@@ -165,8 +165,8 @@
}
],
"source": [
- "import numpy as np\n",
- "a=np.array([[-1, 1J],[-1J, 3],[1 ,2]])\n",
+ "from numpy import array\n",
+ "a=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",
@@ -203,23 +203,25 @@
"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",
+ "[[ 1. 0. 0. 0. 0. 0. 0.]\n",
+ " [ 0. 1. 0. 0. 0. 0. 0.]\n",
+ " [ 0. 0. 1. 0. 0. 0. 0.]\n",
+ " [ 0. 0. 0. 1. 0. 0. 0.]\n",
+ " [ 0. 0. 0. 0. 1. 0. 0.]\n",
+ " [ 0. 0. 0. 0. 0. 1. 0.]\n",
+ " [ 0. 0. 0. 0. 0. 0. 1.]]\n",
+ "This is an Identity matrix of order 7 * 7\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",
+ "from numpy import random, identity\n",
+ "i=2;\n",
+ "while i<=2:\n",
+ " n = random.randint(9)\n",
+ " i=n\n",
+ "print identity(n)\n",
"print 'This is an Identity matrix of order %d * %d'%(n,n)\n",
"print 'And It is a row reduced matrix.'"
]
@@ -242,16 +244,11 @@
"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",
+ "[[ 1.]]\n",
+ "This is an Identity matrix of order 1 * 1\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",
+ "[[ 0. 0. 0. 0.]]\n",
+ "This is an Zero matrix of order 1 * 4\n",
"And It is also a row reduced matrix.\n",
"a = \n",
"[[ 0. 1. -3. 0. 0.5]\n",
@@ -262,17 +259,17 @@
}
],
"source": [
- "import numpy as np\n",
- "n = np.random.randint(9)\n",
- "print np.identity(n)\n",
+ "from numpy import random,identity, zeros,array\n",
+ "n = random.randint(9)\n",
+ "print 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",
+ "m = random.randint(0,9)\n",
+ "n = random.randint(9)\n",
+ "print 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",
+ "a = 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"
]
@@ -330,8 +327,8 @@
}
],
"source": [
- "import numpy as np\n",
- "A = np.array([[1, -2, 1],[2, 1, 1],[0, 5, -1]])\n",
+ "from numpy import array\n",
+ "A = 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",
@@ -452,53 +449,53 @@
}
],
"source": [
- "import numpy as np\n",
+ "from numpy import array\n",
"#Part a\n",
- "a = np.array([[1, 0],[-3, 1]])\n",
- "b = np.array([[5, -1, 2],[15, 4, 8]])\n",
+ "a = array([[1, 0],[-3, 1]])\n",
+ "b = 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",
+ "a = array([[1, 0],[-2, 3],[5 ,4],[0, 1]])\n",
+ "b = 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",
+ "a = array([[2, 1],[5, 4]])\n",
+ "b = 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",
+ "a = array([[-1],[3]])\n",
+ "b = 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",
+ "a = array([[2, 4]])\n",
+ "b = 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",
+ "a = array([[0, 1 ,0],[0, 0, 0],[0, 0, 0]])\n",
+ "b = 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",
+ "a = array([[1, -5, 2],[2, 3, 4],[9, -1, 3]])\n",
+ "b = 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)"
@@ -532,10 +529,10 @@
}
],
"source": [
- "import numpy as np\n",
- "a = np.array([[0, 1],[1, 0]])\n",
+ "from numpy import array,linalg\n",
+ "a = array([[0, 1],[1, 0]])\n",
"print 'a = \\n',a\n",
- "print 'inverse a = \\n',np.linalg.inv(a)"
+ "print 'inverse a = \\n',linalg.inv(a)"
]
},
{
@@ -547,7 +544,7 @@
},
{
"cell_type": "code",
- "execution_count": 25,
+ "execution_count": 8,
"metadata": {
"collapsed": false
},
@@ -584,9 +581,9 @@
}
],
"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",
+ "from numpy import array,linalg\n",
+ "a = array([[2, -1],[1 ,3]])\n",
+ "b = 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",
@@ -604,7 +601,7 @@
"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"
+ "print linalg.inv(b)# #a was stored in b"
]
},
{
@@ -616,7 +613,7 @@
},
{
"cell_type": "code",
- "execution_count": 26,
+ "execution_count": 9,
"metadata": {
"collapsed": false
},
@@ -688,10 +685,10 @@
}
],
"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",
+ "from numpy import array,identity,matrix\n",
+ "a = 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",
+ "b = 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",
@@ -723,7 +720,7 @@
"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 'a = \\n',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"