summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrupti Kini2016-09-03 23:30:23 +0600
committerTrupti Kini2016-09-03 23:30:23 +0600
commit07cf280d177584baac74e351b3d76d085d0e6619 (patch)
tree202a15d7bc23aa1d1dc2a4a9397c94d344ff8dc8
parent3c5945f0aaf1d2d1f84e43ead6676aa497c9c4f8 (diff)
downloadPython-Textbook-Companions-07cf280d177584baac74e351b3d76d085d0e6619.tar.gz
Python-Textbook-Companions-07cf280d177584baac74e351b3d76d085d0e6619.tar.bz2
Python-Textbook-Companions-07cf280d177584baac74e351b3d76d085d0e6619.zip
Added(A)/Deleted(D) following books
A Linear_Algebra_And_Its_Applications_by_G._Strang/CHAPTER1.ipynb A Linear_Algebra_And_Its_Applications_by_G._Strang/CHAPTER2.ipynb A Linear_Algebra_And_Its_Applications_by_G._Strang/CHAPTER3.ipynb A Linear_Algebra_And_Its_Applications_by_G._Strang/CHAPTER4.ipynb A Linear_Algebra_And_Its_Applications_by_G._Strang/CHAPTER5.ipynb A Linear_Algebra_And_Its_Applications_by_G._Strang/CHAPTER6.ipynb A Linear_Algebra_And_Its_Applications_by_G._Strang/CHAPTER7.ipynb A Linear_Algebra_And_Its_Applications_by_G._Strang/CHAPTER8.ipynb A Linear_Algebra_And_Its_Applications_by_G._Strang/screenshots/Ch5Eigenmatrix.png A Linear_Algebra_And_Its_Applications_by_G._Strang/screenshots/Ch5eigenVectors.png A Linear_Algebra_And_Its_Applications_by_G._Strang/screenshots/ch5eigenvaluematrix.png
-rw-r--r--Linear_Algebra_And_Its_Applications_by_G._Strang/CHAPTER1.ipynb927
-rw-r--r--Linear_Algebra_And_Its_Applications_by_G._Strang/CHAPTER2.ipynb476
-rw-r--r--Linear_Algebra_And_Its_Applications_by_G._Strang/CHAPTER3.ipynb578
-rw-r--r--Linear_Algebra_And_Its_Applications_by_G._Strang/CHAPTER4.ipynb194
-rw-r--r--Linear_Algebra_And_Its_Applications_by_G._Strang/CHAPTER5.ipynb411
-rw-r--r--Linear_Algebra_And_Its_Applications_by_G._Strang/CHAPTER6.ipynb373
-rw-r--r--Linear_Algebra_And_Its_Applications_by_G._Strang/CHAPTER7.ipynb352
-rw-r--r--Linear_Algebra_And_Its_Applications_by_G._Strang/CHAPTER8.ipynb70
-rw-r--r--Linear_Algebra_And_Its_Applications_by_G._Strang/screenshots/Ch5Eigenmatrix.pngbin0 -> 35135 bytes
-rw-r--r--Linear_Algebra_And_Its_Applications_by_G._Strang/screenshots/Ch5eigenVectors.pngbin0 -> 27849 bytes
-rw-r--r--Linear_Algebra_And_Its_Applications_by_G._Strang/screenshots/ch5eigenvaluematrix.pngbin0 -> 46485 bytes
11 files changed, 3381 insertions, 0 deletions
diff --git a/Linear_Algebra_And_Its_Applications_by_G._Strang/CHAPTER1.ipynb b/Linear_Algebra_And_Its_Applications_by_G._Strang/CHAPTER1.ipynb
new file mode 100644
index 00000000..65e5ae8c
--- /dev/null
+++ b/Linear_Algebra_And_Its_Applications_by_G._Strang/CHAPTER1.ipynb
@@ -0,0 +1,927 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 1 - Matrix notation & matrix multiplication"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex:1.3.1 Pg:20"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "x=\n",
+ "[[u]\n",
+ " [v]\n",
+ " [w]]\n",
+ "R2=R2-R1,R3=R3-4*R1\n",
+ "[[1 1 1]\n",
+ " [0 0 3]\n",
+ " [0 2 4]]\n",
+ "R2<->R3\n",
+ "[[1 1 1]\n",
+ " [0 2 4]\n",
+ " [0 0 3]]\n",
+ "The system is now triangular and the equations can be solved by Back substitution\n"
+ ]
+ }
+ ],
+ "source": [
+ "from sympy.abc import u,v,w\n",
+ "from numpy import array\n",
+ "a =array([[1 ,1 ,1],[2, 2, 5],[4, 6, 8]])\n",
+ "x=[[u],[v],[w]]\n",
+ "x=array(x)\n",
+ "print 'x=\\n',x\n",
+ "print 'R2=R2-R1,R3=R3-4*R1'\n",
+ "a[1,:]=a[1,:]-2*a[0,:]\n",
+ "a[2,:]=a[2,:]-4*a[0,:]\n",
+ "print a\n",
+ "print 'R2<->R3'\n",
+ "def swap_rows(arr, frm, to):\n",
+ " arr[[frm, to],:] = arr[[to, frm],:]\n",
+ "swap_rows(a,1,2)\n",
+ "print a\n",
+ "print 'The system is now triangular and the equations can be solved by Back substitution'"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex:1.3.2 Pg:21"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "a=\n",
+ "[[1 1 1]\n",
+ " [2 2 5]\n",
+ " [4 4 8]]\n",
+ "x=\n",
+ "[[u]\n",
+ " [v]\n",
+ " [w]]\n",
+ "R2=R2-2*R1,R3=R3-4*R1\n",
+ "[[1 1 1]\n",
+ " [0 0 3]\n",
+ " [0 0 4]]\n",
+ "No exchange of equations can avoid zero in the second pivot positon ,therefore the equations are unsolvable\n"
+ ]
+ }
+ ],
+ "source": [
+ "from sympy.abc import u,v,w\n",
+ "from numpy import array\n",
+ "a =array([[1, 1, 1],[2, 2, 5],[4, 4, 8]])\n",
+ "print 'a=\\n',a\n",
+ "x=[[u],[v],[w]]\n",
+ "x=array(x)\n",
+ "print 'x=\\n',x\n",
+ "print 'R2=R2-2*R1,R3=R3-4*R1'\n",
+ "a[1,:]=a[1,:]-2*a[0,:]\n",
+ "a[2,:]=a[2,:]-4*a[0,:]\n",
+ "print a\n",
+ "print 'No exchange of equations can avoid zero in the second pivot positon ,therefore the equations are unsolvable'"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Ex:1.4.1 Pg:21"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "A = \n",
+ "[[2 3]\n",
+ " [4 0]]\n",
+ "B = \n",
+ "[[ 1 2 0]\n",
+ " [ 5 -1 0]]\n",
+ "AB=\n",
+ "[[17 1 0]\n",
+ " [ 4 8 0]]\n"
+ ]
+ }
+ ],
+ "source": [
+ "from numpy import array\n",
+ "A=array([[2, 3],[4, 0]])\n",
+ "print 'A = \\n',A\n",
+ "B=array([[1, 2, 0],[5, -1, 0]])\n",
+ "print 'B = \\n',B\n",
+ "print 'AB=\\n',A.dot(B)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex:1.4.2 Pg:22"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 37,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "A=\n",
+ "[[2 3]\n",
+ " [7 8]]\n",
+ "P(Row exchange matrix)=\n",
+ "[[0 1]\n",
+ " [1 0]]\n",
+ "PA=\n",
+ "[[7 8]\n",
+ " [2 3]]\n"
+ ]
+ }
+ ],
+ "source": [
+ "from numpy import array\n",
+ "A=array([[2, 3],[7, 8]])\n",
+ "print 'A=\\n',A\n",
+ "P=array([[0, 1],[1, 0]])\n",
+ "print 'P(Row exchange matrix)=\\n',P\n",
+ "print 'PA=\\n',P.dot(A)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex:1.4.3 Pg:24"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "A=\n",
+ "[[1 2]\n",
+ " [3 4]]\n",
+ "I=\n",
+ "[[ 1. 0.]\n",
+ " [ 0. 1.]]\n",
+ "IA=\n",
+ "[[ 1. 2.]\n",
+ " [ 3. 4.]]\n"
+ ]
+ }
+ ],
+ "source": [
+ "from numpy import array,identity\n",
+ "A=array([[1, 2],[3, 4]])\n",
+ "print 'A=\\n',A\n",
+ "I=identity(2)\n",
+ "print 'I=\\n',I\n",
+ "print 'IA=\\n',I.dot(A)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex:1.4.4 Pg:25"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 39,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "E=\n",
+ "[[ 1. 0. 0.]\n",
+ " [-2. 1. 0.]\n",
+ " [ 0. 0. 1.]]\n",
+ "F=\n",
+ "[[ 1. 0. 0.]\n",
+ " [ 0. 1. 0.]\n",
+ " [ 1. 0. 1.]]\n",
+ "EF=\n",
+ "[[ 1. 0. 0.]\n",
+ " [-2. 1. 0.]\n",
+ " [ 1. 0. 1.]]\n",
+ "FE=\n",
+ "[[ 1. 0. 0.]\n",
+ " [-2. 1. 0.]\n",
+ " [ 1. 0. 1.]]\n",
+ "Here,EF=FE,so this shows that these two matrices commute\n"
+ ]
+ }
+ ],
+ "source": [
+ "from numpy import array,identity\n",
+ "E=identity(3)\n",
+ "E[1,:]=E[1,:]-2*E[0,:]\n",
+ "print 'E=\\n',E\n",
+ "F=identity(3)\n",
+ "F[2,:]=F[2,:]+F[0,:]\n",
+ "print 'F=\\n',F\n",
+ "print 'EF=\\n',E.dot(F)\n",
+ "print 'FE=\\n',F.dot(E)\n",
+ "print 'Here,EF=FE,so this shows that these two matrices commute'"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex:1.4.5 Pg:25"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "E=\n",
+ "[[ 1. 0. 0.]\n",
+ " [-2. 1. 0.]\n",
+ " [ 0. 0. 1.]]\n",
+ "F=\n",
+ "[[ 1. 0. 0.]\n",
+ " [ 0. 1. 0.]\n",
+ " [ 1. 0. 1.]]\n",
+ "G=\n",
+ "[[ 1. 0. 0.]\n",
+ " [ 0. 1. 0.]\n",
+ " [ 0. 1. 1.]]\n",
+ "GE= [[ 1. 0. 0.]\n",
+ " [-2. 1. 0.]\n",
+ " [-2. 1. 1.]]\n",
+ "EG=\n",
+ "[[ 1. 0. 0.]\n",
+ " [-2. 1. 0.]\n",
+ " [ 0. 1. 1.]]\n",
+ "Here EG is not equal to GE,Therefore these two matrices do not commute and shows that most matrices do not commute.\n",
+ "GFE=\n",
+ "[[ 1. 0. 0.]\n",
+ " [-2. 1. 0.]\n",
+ " [-1. 1. 1.]]\n",
+ "EFG=\n",
+ "[[ 1. 0. 0.]\n",
+ " [-2. 1. 0.]\n",
+ " [ 1. 1. 1.]]\n",
+ "The product GFE is the true order of elimation.It is the matrix that takes the original A to the upper triangular U.\n"
+ ]
+ }
+ ],
+ "source": [
+ "from numpy import array,identity\n",
+ "E=identity(3)\n",
+ "E[1,:]=E[1,:]-2*E[0,:]\n",
+ "print 'E=\\n',E\n",
+ "F=identity(3)\n",
+ "F[2,:]=F[2,:]+F[0,:]\n",
+ "print 'F=\\n',F\n",
+ "G=identity(3)\n",
+ "G[2,:]=G[2,:]+G[1,:]\n",
+ "print 'G=\\n',G\n",
+ "print 'GE=',G.dot(E)\n",
+ "print 'EG=\\n',E.dot(G)\n",
+ "print 'Here EG is not equal to GE,Therefore these two matrices do not commute and shows that most matrices do not commute.'\n",
+ "print 'GFE=\\n',G.dot(F.dot(E))\n",
+ "print 'EFG=\\n',E.dot(F.dot(G))\n",
+ "print 'The product GFE is the true order of elimation.It is the matrix that takes the original A to the upper triangular U.'"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex:1.5.1 Pg: 34"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 6,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "A= [[1 2]\n",
+ " [3 8]]\n",
+ "L= [[ 1. 0. ]\n",
+ " [ 0.33333333 1. ]]\n",
+ "U= [[ 3. 8. ]\n",
+ " [ 0. -0.66666667]]\n",
+ "LU=\n",
+ "[[ 3. 8.]\n",
+ " [ 1. 2.]]\n"
+ ]
+ }
+ ],
+ "source": [
+ "from numpy import mat,dot\n",
+ "from scipy.linalg import lu\n",
+ "A=mat([[1, 2],[3, 8]])\n",
+ "print 'A=',A\n",
+ "L=lu(A)[1]\n",
+ "U=lu(A)[2]\n",
+ "print 'L=',L\n",
+ "print 'U=',U\n",
+ "L=mat(L);U=mat(U)\n",
+ "print 'LU=\\n',dot(L,U)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex:1.5.2 Pg: 34"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 42,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "A= [[0 2]\n",
+ " [3 4]]\n",
+ "Here this cannot be factored into A=LU,(Needs a row exchange)\n"
+ ]
+ }
+ ],
+ "source": [
+ "from numpy import mat\n",
+ "A=[[0, 2],[3, 4]]\n",
+ "print 'A=',mat(A)\n",
+ "print 'Here this cannot be factored into A=LU,(Needs a row exchange)'"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex:1.5.3 Pg: 34"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 8,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Given Matrix:\n",
+ "A= [[1, 1, 1], [1, 2, 2], [1, 2, 3]]\n",
+ "\n",
+ "L= [[ 1. 0. 0.]\n",
+ " [ 1. 1. 0.]\n",
+ " [ 1. 1. 1.]]\n",
+ "\n",
+ "U= [[ 1. 1. 1.]\n",
+ " [ 0. 1. 1.]\n",
+ " [ 0. 0. 1.]]\n",
+ "\n",
+ "LU=\n",
+ "[[ 1. 1. 1.]\n",
+ " [ 1. 2. 2.]\n",
+ " [ 1. 2. 3.]]\n",
+ "Here LU=A,from A to U there are subtraction of rows.Frow U to A there are additions of rows\n"
+ ]
+ }
+ ],
+ "source": [
+ "from numpy import mat\n",
+ "from scipy.linalg import lu\n",
+ "print 'Given Matrix:'\n",
+ "A=[[1, 1 ,1],[1, 2, 2],[1, 2, 3]]\n",
+ "print 'A=',A\n",
+ "L=lu(A)[1]\n",
+ "U=lu(A)[2]\n",
+ "print '\\nL=',L\n",
+ "print '\\nU=',U\n",
+ "print '\\nLU=\\n',mat(L)*mat(U)\n",
+ "print 'Here LU=A,from A to U there are subtraction of rows.Frow U to A there are additions of rows'\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex:1.5.4 Pg: 34"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 9,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "L=\n",
+ "[[ 1. 0. 0. ]\n",
+ " [ 0.74342501 1. 0. ]\n",
+ " [ 0.97556591 0.5785538 1. ]]\n",
+ "U=\n",
+ "[[ 1. 0. 0.]\n",
+ " [ 0. 1. 0.]\n",
+ " [ 0. 0. 1.]]\n",
+ "E=\n",
+ "[[ 1. 0. 0. ]\n",
+ " [-0.74342501 1. 0. ]\n",
+ " [ 0. 0. 1. ]]\n",
+ "F=\n",
+ "[[ 1. 0. 0. ]\n",
+ " [ 0. 1. 0. ]\n",
+ " [-0.97556591 0. 1. ]]\n",
+ "G=\n",
+ "[[ 1. 0. 0. ]\n",
+ " [ 0. 1. 0. ]\n",
+ " [ 0. -0.5785538 1. ]]\n",
+ "A=inv(E)*inv(F)*inv(G)*U\n",
+ "A=\n",
+ "[[ 1. 0. 0. ]\n",
+ " [ 0.74342501 1. 0. ]\n",
+ " [ 0.97556591 0.5785538 1. ]]\n",
+ "When U is identity matrix then L is same as A\n"
+ ]
+ }
+ ],
+ "source": [
+ "from numpy.random import random\n",
+ "from numpy import mat,eye\n",
+ "a=random()\n",
+ "b=random()\n",
+ "c=random()\n",
+ "L=mat([[1, 0, 0],[a, 1, 0],[b, c, 1]])\n",
+ "print 'L=\\n',L\n",
+ "U=eye(3)\n",
+ "print 'U=\\n',U\n",
+ "E=mat([[1, 0, 0],[-a, 1, 0],[0, 0, 1]])\n",
+ "print 'E=\\n',E\n",
+ "F=mat([[1, 0, 0],[0, 1, 0],[-b, 0, 1]])\n",
+ "print 'F=\\n',F\n",
+ "G=mat([[1, 0, 0],[0, 1, 0],[0, -c, 1]])\n",
+ "print 'G=\\n',G\n",
+ "print 'A=inv(E)*inv(F)*inv(G)*U'\n",
+ "A=(E**-1)*(F**-1)*(G**-1)*U#\n",
+ "print 'A=\\n',A\n",
+ "print 'When U is identity matrix then L is same as A'"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex:1.5.5 Pg: 39"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 10,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "A=\n",
+ "[[ 1 -1 0 0]\n",
+ " [-1 2 -1 0]\n",
+ " [ 0 -1 2 -1]\n",
+ " [ 0 0 -1 2]]\n",
+ "U=\n",
+ "[[ 1. -1. 0. 0.]\n",
+ " [ 0. 1. -1. 0.]\n",
+ " [ 0. 0. 1. -1.]\n",
+ " [ 0. 0. 0. 1.]]\n",
+ "L=\n",
+ "[[ 1. 0. 0. 0.]\n",
+ " [-1. 1. 0. 0.]\n",
+ " [ 0. -1. 1. 0.]\n",
+ " [ 0. 0. -1. 1.]]\n",
+ "This shows how a matrix A with 3 diagnols has factors L and U with two diagnols.\n"
+ ]
+ }
+ ],
+ "source": [
+ "from numpy import mat\n",
+ "from scipy.linalg import lu\n",
+ "\n",
+ "A=mat([[1, -1, 0, 0],[-1, 2 ,-1, 0],[0, -1, 2 ,-1],[0, 0 ,-1 ,2]])\n",
+ "print 'A=\\n',A\n",
+ "L=lu(A)[1]\n",
+ "U=lu(A)[2]\n",
+ "print 'U=\\n',U\n",
+ "print 'L=\\n',L\n",
+ "print 'This shows how a matrix A with 3 diagnols has factors L and U with two diagnols.'"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex:1.5.6 Pg: 36"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 11,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "a=\n",
+ "[[ 1 -1 0 0]\n",
+ " [-1 2 -1 0]\n",
+ " [ 0 -1 2 -1]\n",
+ " [ 0 0 -1 2]]\n",
+ "b=\n",
+ "[[1]\n",
+ " [1]\n",
+ " [1]\n",
+ " [1]]\n",
+ "Given Equation ,ax=b\n",
+ "U=\n",
+ "[[ 1. -1. 0. 0.]\n",
+ " [ 0. 1. -1. 0.]\n",
+ " [ 0. 0. 1. -1.]\n",
+ " [ 0. 0. 0. 1.]]\n",
+ "L=\n",
+ "[[ 1. 0. 0. 0.]\n",
+ " [-1. 1. 0. 0.]\n",
+ " [ 0. -1. 1. 0.]\n",
+ " [ 0. 0. -1. 1.]]\n",
+ "Augmented Matrix of L and b=\n",
+ "[[ 1. 0. 0. 0. 1. -1. 0. 0.]\n",
+ " [-1. 1. 0. 0. 0. 1. -1. 0.]\n",
+ " [ 0. -1. 1. 0. 0. 0. 1. -1.]\n",
+ " [ 0. 0. -1. 1. 0. 0. 0. 1.]]\n",
+ "c=\n",
+ "[[ 1.]\n",
+ " [ 2.]\n",
+ " [ 2.]\n",
+ " [ 2.]]\n",
+ "Augmented matrix of U and c=\n",
+ "[[ 1. -1. 0. 0. 1.]\n",
+ " [ 0. 1. -1. 0. 2.]\n",
+ " [ 0. 0. 1. -1. 2.]\n",
+ " [ 0. 0. 0. 1. 2.]]\n",
+ "x=\n",
+ "[[ 0.]\n",
+ " [ 6.]\n",
+ " [ 4.]\n",
+ " [ 2.]]\n"
+ ]
+ }
+ ],
+ "source": [
+ "from numpy import mat,hstack,zeros,arange\n",
+ "from scipy.linalg import lu\n",
+ "\n",
+ "a=mat([[1, -1, 0 ,0],[-1, 2, -1, 0],[0, -1, 2, -1],[0, 0, -1, 2]])\n",
+ "print 'a=\\n',a\n",
+ "b=mat([[1],[1],[1],[1]])\n",
+ "print 'b=\\n',b\n",
+ "print 'Given Equation ,ax=b'\n",
+ "\n",
+ "L=lu(a)[1]\n",
+ "U=lu(a)[2]\n",
+ "print 'U=\\n',U\n",
+ "print 'L=\\n',L\n",
+ "print 'Augmented Matrix of L and b='\n",
+ "A=hstack([L,U])\n",
+ "print A\n",
+ " \n",
+ "\n",
+ "c=zeros([4,1])#\n",
+ "n=4\n",
+ "#Algorithm Finding the value of c\n",
+ "c[0]=A[0,n]/A[0,0]\n",
+ "for i in range(1,n):\n",
+ " sumk=0#\n",
+ " for k in range(0,n-1):\n",
+ " sumk=sumk+A[i,k]*c[k]\n",
+ " \n",
+ " c[i]=(A[i,n+1]-sumk)/A[i,i]\n",
+ "\n",
+ "print 'c=\\n',c\n",
+ "x=zeros([4,1])\n",
+ "print 'Augmented matrix of U and c='\n",
+ "B=hstack([U,c])\n",
+ "print B\n",
+ "#Algorithm for finding value of x\n",
+ "x[n-1]=B[n-1,n]/B[n-1,n-1]\n",
+ "for i in arange(n-1-1,-1+1,-1):\n",
+ " sumk=0#\n",
+ " for k in range(i+1-1,n):\n",
+ " sumk=sumk+B[i,k]*x[k]\n",
+ " \n",
+ " x[i]=(B[i,n+1-1]-sumk)/B[i,i]\n",
+ "\n",
+ "print 'x=\\n',x\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex:1.5.7 Pg: 39"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 12,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "A=\n",
+ "[[1 1 1]\n",
+ " [1 1 3]\n",
+ " [2 5 8]]\n",
+ "L=\n",
+ "[[ 1. 0. 0. ]\n",
+ " [ 0.5 1. 0. ]\n",
+ " [ 0.5 1. 1. ]]\n",
+ "U=\n",
+ "[[ 2. 5. 8. ]\n",
+ " [ 0. -1.5 -1. ]\n",
+ " [ 0. 0. -2. ]]\n",
+ "P=\n",
+ "[[ 0. 0. 1.]\n",
+ " [ 0. 1. 0.]\n",
+ " [ 1. 0. 0.]]\n",
+ "PA=\n",
+ "[[ 2. 5. 8.]\n",
+ " [ 1. 1. 3.]\n",
+ " [ 1. 1. 1.]]\n",
+ "LU=\n",
+ "[[ 2. 0. 0. ]\n",
+ " [ 0. -1.5 -0. ]\n",
+ " [ 0. 0. -2. ]]\n"
+ ]
+ }
+ ],
+ "source": [
+ "from numpy import mat\n",
+ "from scipy.linalg import lu\n",
+ "\n",
+ "A=mat([[1, 1, 1],[1, 1, 3],[2, 5, 8]])\n",
+ "print 'A=\\n',A\n",
+ "P=lu(A)[0]\n",
+ "L=lu(A)[1]\n",
+ "U=lu(A)[2]\n",
+ "print 'L=\\n',L\n",
+ "print 'U=\\n',U\n",
+ "print 'P=\\n',P\n",
+ "print 'PA=\\n',(P*A)\n",
+ "print 'LU=\\n',(L*U)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex:1.6.1 Pg: 47"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 13,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Given matrix:\n",
+ "[[ 2 1 1]\n",
+ " [ 4 -6 0]\n",
+ " [-2 7 2]]\n",
+ "Augmented matrix :\n",
+ "[[ 2. 1. 1. 1. 0. 0.]\n",
+ " [ 4. -6. 0. 0. 1. 0.]\n",
+ " [-2. 7. 2. 0. 0. 1.]]\n",
+ "R2=R2-2*R1,R3=R3-(-2)*R1\n",
+ "[[ 2. 1. 1. 1. 0. 0.]\n",
+ " [ 8. -4. 2. 2. 1. 0.]\n",
+ " [ 0. 8. 3. 1. 0. 1.]]\n",
+ "R3=R3-(-1)*R2\n",
+ "a=\n",
+ "[[ 2. 1. 1. 1. 0. 0.]\n",
+ " [ 8. -4. 2. 2. 1. 0.]\n",
+ " [ 8. 4. 5. 3. 1. 1.]]\n",
+ "[U inv(L)] :\n",
+ "[[ 2. 1. 1. 1. 0. 0.]\n",
+ " [ 8. -4. 2. 2. 1. 0.]\n",
+ " [ 8. 4. 5. 3. 1. 1.]]\n",
+ "R2=R2-(-2)*R3,R1=R1-R3\n",
+ "[[ 10. 5. 6. 4. 1. 1.]\n",
+ " [ 24. 4. 12. 8. 3. 2.]\n",
+ " [ 8. 4. 5. 3. 1. 1.]]\n",
+ "R1=R1-(-1/8)*R2)\n",
+ "[[ 13. 5.5 7.5 5. 1.375 1.25 ]\n",
+ " [ 24. 4. 12. 8. 3. 2. ]\n",
+ " [ 8. 4. 5. 3. 1. 1. ]]\n",
+ "[I inv(A)]:\n",
+ "[[ 1. 0.42307692 0.57692308 0.38461538 0.10576923 0.09615385]\n",
+ " [ 6. 1. 3. 2. 0.75 0.5 ]\n",
+ " [ 1.6 0.8 1. 0.6 0.2 0.2 ]]\n",
+ "inv(A):\n",
+ "[[ 0.38461538 0.10576923 0.09615385]\n",
+ " [ 2. 0.75 0.5 ]\n",
+ " [ 0.6 0.2 0.2 ]]\n"
+ ]
+ }
+ ],
+ "source": [
+ "from numpy import mat,shape,nditer,hstack,eye,nditer\n",
+ "\n",
+ "print 'Given matrix:'\n",
+ "A=mat([[2, 1, 1],[4, -6, 0],[-2, 7, 2]])\n",
+ "print A\n",
+ "m=int(shape(A)[0])\n",
+ "n=int(shape(A)[1])\n",
+ "print 'Augmented matrix :'\n",
+ "a=hstack([A,eye(n)])\n",
+ "print a\n",
+ "print 'R2=R2-2*R1,R3=R3-(-2)*R1'\n",
+ "def fun1(a,x,y,n):\n",
+ " import numpy as np\n",
+ " z=[]\n",
+ " for xx,yy in nditer([a[x-1],a[y-1]]):\n",
+ " z.append(xx-n*yy)\n",
+ " a[x-1]=z\n",
+ " return a \n",
+ "\n",
+ " \n",
+ "a=fun1(a,2,1,-2)\n",
+ "a=fun1(a,3,1,-1)\n",
+ "print a\n",
+ "print 'R3=R3-(-1)*R2'\n",
+ "a=fun1(a,3,2,-1) # a(3,:)-(-1)*a(2,:)#\n",
+ "print 'a=\\n',a\n",
+ "print '[U inv(L)] :\\n',a\n",
+ "print 'R2=R2-(-2)*R3,R1=R1-R3'\n",
+ "a=fun1(a,2,3,-2)\n",
+ "a=fun1(a,1,3,-1)\n",
+ "print a\n",
+ "print 'R1=R1-(-1/8)*R2)'\n",
+ "a=fun1(a,1,2,-1./8)\n",
+ "print a\n",
+ "\n",
+ "a[0]=a[0]/a[0,0]\n",
+ "a[1]=a[1]/a[1,1]\n",
+ "print '[I inv(A)]:'\n",
+ "a[2]=a[2]/a[2,2]\n",
+ "print a\n",
+ "print 'inv(A):'\n",
+ "print a[:,range(3,6)]"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex:1.6.2 Pg:51"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 14,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "R= [[1 2]]\n",
+ "Transpose of the given matrix is : [[1]\n",
+ " [2]]\n",
+ "The product of R & transpose(R)is : [[5]]\n",
+ "The product of transpose(R)& R is : [[1 2]\n",
+ " [2 4]]\n",
+ "Rt*R and R*Rt are not likely to be equal even if m==n.\n"
+ ]
+ }
+ ],
+ "source": [
+ "from numpy import mat,transpose\n",
+ "R=mat([1, 2])\n",
+ "print 'R=',R\n",
+ "Rt=transpose(R)\n",
+ "print 'Transpose of the given matrix is :',Rt\n",
+ "print 'The product of R & transpose(R)is :',(R*Rt)\n",
+ "print 'The product of transpose(R)& R is :',(Rt*R)\n",
+ "print 'Rt*R and R*Rt are not likely to be equal even if m==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_And_Its_Applications_by_G._Strang/CHAPTER2.ipynb b/Linear_Algebra_And_Its_Applications_by_G._Strang/CHAPTER2.ipynb
new file mode 100644
index 00000000..9d2e4638
--- /dev/null
+++ b/Linear_Algebra_And_Its_Applications_by_G._Strang/CHAPTER2.ipynb
@@ -0,0 +1,476 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter2 Vector Spaces"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex:2.1.1 Pg: 70"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Consider all vectors in R**2 whose components are positive or zero\n",
+ "The subset is first Quadrant of x-y plane,the co-ordinates satisfy x>=0 and y>=0.It is not a subspace.\n",
+ "If the Vector= [1, 1]\n",
+ "Taking a scalar,c=-1\n",
+ "c*v= [-1, -1]\n",
+ "It lies in third Quadrant instead of first,Hence violating the rule(ii).\n"
+ ]
+ }
+ ],
+ "source": [
+ "print 'Consider all vectors in R**2 whose components are positive or zero'\n",
+ "print 'The subset is first Quadrant of x-y plane,the co-ordinates satisfy x>=0 and y>=0.It is not a subspace.'\n",
+ "v=[1,1]\n",
+ "print 'If the Vector=',v\n",
+ "print 'Taking a scalar,c=-1'\n",
+ "c=-1# #scalar\n",
+ "print 'c*v=',[c*vv for vv in v]\n",
+ "print 'It lies in third Quadrant instead of first,Hence violating the rule(ii).'"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex:2.3.2 Pg: 92"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Given matrix:\n",
+ "[[ 1 3 3 2]\n",
+ " [ 2 6 9 5]\n",
+ " [-1 -3 3 0]]\n",
+ "C2->C2-3*C1\n",
+ "[[ 1 0 3 2]\n",
+ " [ 2 0 9 5]\n",
+ " [-1 0 3 0]]\n",
+ "Here,C2=3*C1,Therefore the columns are linearly dependent.\n",
+ "R3->R3-2*R2+5*R1\n",
+ "[[1 0 3 2]\n",
+ " [2 0 9 5]\n",
+ " [0 0 0 0]]\n",
+ "Here R3=R3-2*R2+5*R1,therefore the rows are linearly dependent.\n"
+ ]
+ }
+ ],
+ "source": [
+ "from numpy import mat\n",
+ "A=mat([[1, 3 ,3 ,2],[2, 6, 9, 5],[-1, -3, 3, 0]])\n",
+ "print 'Given matrix:'\n",
+ "print A\n",
+ "B=A\n",
+ "print 'C2->C2-3*C1'\n",
+ "A[:,1]=A[:,1]-3*A[:,0]\n",
+ "print A\n",
+ "print 'Here,C2=3*C1,Therefore the columns are linearly dependent.'\n",
+ "print 'R3->R3-2*R2+5*R1'\n",
+ "B[2,:]=B[2,:]-2*B[1,:]+5*B[0,:]\n",
+ "print B\n",
+ "print 'Here R3=R3-2*R2+5*R1,therefore the rows are linearly dependent.'"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex:2.3.3 Pg: "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "A=\n",
+ "[[3 4 2]\n",
+ " [0 1 5]\n",
+ " [0 0 2]]\n",
+ "The columns of the triangular matrix are linearly independent,it has no zeros on the diagonal\n"
+ ]
+ }
+ ],
+ "source": [
+ "from numpy import mat\n",
+ "A=mat([[3, 4 ,2],[0, 1 ,5],[0, 0, 2]])\n",
+ "print 'A=\\n',A\n",
+ "print 'The columns of the triangular matrix are linearly independent,it has no zeros on the diagonal'"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex:2.3.4 Pg: 93"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "The columns of the nxn identity matrix are independent.\n",
+ "I=\n",
+ "[[ 1. 0. 0. 0.]\n",
+ " [ 0. 1. 0. 0.]\n",
+ " [ 0. 0. 1. 0.]\n",
+ " [ 0. 0. 0. 1.]]\n"
+ ]
+ }
+ ],
+ "source": [
+ "from numpy import eye\n",
+ "print 'The columns of the nxn identity matrix are independent.'\n",
+ "n=4 # size for identity matrix\n",
+ "I=eye(n)\n",
+ "print 'I=\\n',I"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex:2.3.5 Pg: 93"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Three columns in R2 cannot be independent.\n",
+ "Given matrix:\n",
+ "[[1 2 1]\n",
+ " [1 2 3]]\n",
+ "U=\n",
+ "[[ 1. 2. 1.]\n",
+ " [ 0. 0. 2.]]\n",
+ "If c3 is 1 ,then back-substitution Uc=0 gives c2=-1,c1=1,With these three weights,the first column minus the second plus the third equals zero ,therefore linearly dependent.\n"
+ ]
+ }
+ ],
+ "source": [
+ "from scipy.linalg import lu\n",
+ "from numpy import mat\n",
+ "print 'Three columns in R2 cannot be independent.'\n",
+ "A=mat([[1, 2, 1],[1, 2, 3]])\n",
+ "print 'Given matrix:\\n',A\n",
+ "L=lu(A)[1]\n",
+ "U=lu(A)[2]\n",
+ "print 'U=\\n',U\n",
+ "print 'If c3 is 1 ,then back-substitution Uc=0 gives c2=-1,c1=1,With these three weights,the first column minus the second plus the third equals zero ,therefore linearly dependent.'"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex:2.3.9 Pg: 96"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 11,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "These four columns span the column space U,but they are not independent.\n",
+ "U=\n",
+ "[[1 3 3 2]\n",
+ " [0 0 3 1]\n",
+ " [0 0 0 0]]\n",
+ "The columns that contains pivots (here 1st & 3rd) are a basis for the column space. These columns are independent, and it is easy to see that they span the space.In fact,the column space of U is just the x-y plane withinn R3. C(U) is not the same as the column space C(A) before elimination-but the number of independent columns did not change.\n"
+ ]
+ }
+ ],
+ "source": [
+ "from numpy import mat\n",
+ "print 'These four columns span the column space U,but they are not independent.'\n",
+ "U=mat([[1, 3 ,3, 2],[0, 0 ,3 ,1],[0, 0, 0, 0]])\n",
+ "print 'U=\\n',U\n",
+ "print 'The columns that contains pivots (here 1st & 3rd) are a basis for the column space. These columns are independent, and it is easy to see that they span the space.In fact,the column space of U is just the x-y plane withinn R3. C(U) is not the same as the column space C(A) before elimination-but the number of independent columns did not change.'"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex:2.4.1 Pg: 107"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "A=\n",
+ "[[1 2]\n",
+ " [3 6]]\n",
+ "m= 2\n",
+ "n= 2\n",
+ "rank= 1\n",
+ "Column space= [[1]\n",
+ " [3]]\n",
+ "Null space=\n",
+ "[[-0.89442719]\n",
+ " [ 0.4472136 ]]\n",
+ "Row space=\n",
+ "[[1]\n",
+ " [2]]\n",
+ "Left null sapce=\n",
+ "[[-0.9486833 ]\n",
+ " [ 0.31622777]]\n"
+ ]
+ }
+ ],
+ "source": [
+ "from numpy import mat,shape\n",
+ "from sympy import Matrix\n",
+ "from scipy import linalg, matrix, compress,transpose\n",
+ "A=mat([[1 ,2],[3, 6]])\n",
+ "print 'A=\\n',A\n",
+ "m=shape(A)[0]\n",
+ "n=shape(A)[1]\n",
+ "print 'm=',m\n",
+ "print 'n=',n\n",
+ "v=Matrix(A).rref()[0]\n",
+ "pivot=Matrix(A).rref()[1]\n",
+ "r=len(pivot)\n",
+ "print 'rank=',r\n",
+ "cs=A[:,r-1]\n",
+ "print 'Column space=',cs\n",
+ "\n",
+ "\n",
+ "def kernel(A, eps=1e-15):\n",
+ " u, s, vh = linalg.svd(A)\n",
+ " null_mask = (s <= eps)\n",
+ " null_space = compress(null_mask, vh, axis=0)\n",
+ " return transpose(null_space)\n",
+ "A=mat([[1 ,2],[3, 6]])\n",
+ "\n",
+ "ns=kernel(A)\n",
+ "print 'Null space=\\n',ns\n",
+ "v=mat(v)\n",
+ "rs=transpose(v[range(0,r),:])\n",
+ "print 'Row space=\\n',rs\n",
+ "lns=kernel(transpose(A))\n",
+ "print 'Left null sapce=\\n',lns"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex:2.4.2 Pg: 108"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "A=\n",
+ "[[4 0 0]\n",
+ " [0 5 0]]\n",
+ "m= 2\n",
+ "n= 3\n",
+ "rank= 2\n",
+ "since m=r=2 ,there exists a right inverse .\n",
+ "Best right inverse=\n",
+ "[[ 0.25 0. ]\n",
+ " [ 0. 0.2 ]\n",
+ " [ 0. 0. ]]\n"
+ ]
+ }
+ ],
+ "source": [
+ "from numpy import mat,shape,rank,transpose\n",
+ "A=mat([[4, 0, 0],[0, 5, 0]])\n",
+ "print 'A=\\n',A\n",
+ "m=shape(A)[0]\n",
+ "n=shape(A)[1]\n",
+ "print 'm=',m\n",
+ "print 'n=',n\n",
+ "r=rank(A)\n",
+ "print 'rank=',r\n",
+ "print 'since m=r=2 ,there exists a right inverse .'\n",
+ "C=transpose(A)*(A*transpose(A))**-1\n",
+ "print 'Best right inverse=\\n',C"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex:2.5.1 Pg: 121"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 6,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Applying current law Ay=f at nodes 1,2,3:\n",
+ "A' = \n",
+ "[[-1 0 -1 0 -1]\n",
+ " [ 1 -1 0 0 0]\n",
+ " [ 0 1 1 -1 0]]\n",
+ "[[ 0. ]\n",
+ " [ 0. ]\n",
+ " [ 0.59010697]\n",
+ " [ 0. ]\n",
+ " [ 0. ]\n",
+ " [ 0. ]\n",
+ " [ 0.55757785]\n",
+ " [ 0. ]]\n",
+ "The other equation is inv(C)y+Ax=b.The block form of the two equations is:\n",
+ "[[ 1.37051236 0. 0. 0. 0. -1.\n",
+ " 1. 0. ]\n",
+ " [ 0. 1.54412147 0. 0. 0. 0.\n",
+ " -1. 1. ]\n",
+ " [ 0. 0. 9.1949881 0. 0. -1.\n",
+ " 0. 1. ]\n",
+ " [ 0. 0. 0. 13.91590014 0. 0.\n",
+ " 0. -1. ]\n",
+ " [ 0. 0. 0. 0. 2.46587381 -1.\n",
+ " 0. 0. ]\n",
+ " [ -1. 0. -1. 0. -1. 0.\n",
+ " 0. 0. ]\n",
+ " [ 1. -1. 0. 0. 0. 0.\n",
+ " 0. 0. ]\n",
+ " [ 0. 1. 1. -1. 0. 0.\n",
+ " 0. 0. ]]\n",
+ "X=\n",
+ "[['y1']\n",
+ " ['y2']\n",
+ " ['y3']\n",
+ " ['y4']\n",
+ " ['y5']\n",
+ " ['x1']\n",
+ " ['x2']\n",
+ " ['x3']]\n",
+ "X= [[ 0.3717052 ]\n",
+ " [-0.18587265]\n",
+ " [ 0.08836592]\n",
+ " [-0.09750673]\n",
+ " [-0.46007112]\n",
+ " [-1.13447733]\n",
+ " [-1.6439039 ]\n",
+ " [-1.35689395]]\n"
+ ]
+ }
+ ],
+ "source": [
+ "from numpy import mat,transpose,diag,zeros,random,vstack,hstack,linalg\n",
+ "print 'Applying current law A''y=f at nodes 1,2,3:'\n",
+ "A=mat([[-1, 1 ,0],[0, -1, 1],[ -1, 0 ,1],[0, 0 ,-1],[-1, 0, 0]])\n",
+ "print \"A' = \\n\",transpose(A)\n",
+ "C=diag(random.rand(5))# #Taking some values for the resistances.\\\n",
+ "b=zeros([5,1])\n",
+ "b[2,0]=random.rand(1)[0]##Taking some value of the battery.\n",
+ "f=zeros([3,1])\n",
+ "f[1,0]=random.rand(1)[0]##Taking some value of the current source.\n",
+ "B=vstack([b,f])#[b]#f]\n",
+ "print B\n",
+ "print 'The other equation is inv(C)y+Ax=b.The block form of the two equations is:'\n",
+ "#C=[C**-1 A],[np.transpose(A),np.zeros([3,3])]\n",
+ "C1=hstack([linalg.inv(C),A])\n",
+ "C2=hstack([transpose(A),zeros([3,3])])\n",
+ "C=vstack([C1,C2])\n",
+ "print C\n",
+ "X=mat([['y1'],['y2'],['y3'],['y4'],['y5'],['x1'],['x2'],['x3']])\n",
+ "print \"X=\\n\",X\n",
+ "X=linalg.solve(C,B)\n",
+ "print 'X=',X"
+ ]
+ }
+ ],
+ "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_And_Its_Applications_by_G._Strang/CHAPTER3.ipynb b/Linear_Algebra_And_Its_Applications_by_G._Strang/CHAPTER3.ipynb
new file mode 100644
index 00000000..e0a2d2d7
--- /dev/null
+++ b/Linear_Algebra_And_Its_Applications_by_G._Strang/CHAPTER3.ipynb
@@ -0,0 +1,578 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter3 Orthogonality"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex:3.1.1 Pg: 143"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "x1=\n",
+ "[[ 2]\n",
+ " [ 2]\n",
+ " [-1]]\n",
+ "x2=\n",
+ "[[-1]\n",
+ " [ 2]\n",
+ " [ 2]]\n",
+ "x1'*x2=\n",
+ "[[0]]\n",
+ "Therefore,X1 is orthogonal to x2 .Both have length of sqrt(14).\n"
+ ]
+ }
+ ],
+ "source": [
+ "from numpy import mat,transpose\n",
+ "x1=mat([[2],[2],[-1]])\n",
+ "print 'x1=\\n',x1\n",
+ "x2=mat([[-1],[2],[2]])\n",
+ "print 'x2=\\n',x2\n",
+ "print \"x1'*x2=\\n\",(transpose(x1)*x2)\n",
+ "print 'Therefore,X1 is orthogonal to x2 .Both have length of sqrt(14).'"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex:3.1.3 Pg: 145"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "A=\n",
+ "[[1 3]\n",
+ " [2 6]\n",
+ " [3 9]]\n",
+ "Null space=\n",
+ "[[-0.9486833 ]\n",
+ " [ 0.31622777]]\n",
+ "A(1,:)*ns= [[ -2.22044605e-16]]\n",
+ "A(2,:)*ns= [[ -4.44089210e-16]]\n",
+ "A(3,:)*ns= [[ -4.44089210e-16]]\n",
+ "This shows that the null space of A is orthogonal to the row space.\n"
+ ]
+ }
+ ],
+ "source": [
+ "from numpy import mat,linalg,atleast_2d\n",
+ "A=mat([[1, 3],[2, 6],[3, 9]])\n",
+ "print 'A=\\n',A\n",
+ "def nullspace(A, atol=1e-13, rtol=0):\n",
+ " \n",
+ " A = atleast_2d(A)\n",
+ " u, s, vh = linalg.svd(A)\n",
+ " tol = max(atol, rtol * s[0])\n",
+ " nnz = (s >= tol).sum()\n",
+ " ns = vh[nnz:].conj().T\n",
+ " return ns\n",
+ "ns=nullspace(A)\n",
+ "print 'Null space=\\n',ns\n",
+ "print 'A(1,:)*ns=',(A[0]*ns)\n",
+ "print 'A(2,:)*ns=',(A[1]*ns)\n",
+ "print 'A(3,:)*ns=',(A[2]*ns)\n",
+ "print 'This shows that the null space of A is orthogonal to the row space.'"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "\n",
+ "## Ex:3.2.1 Pg: 155"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "b=\n",
+ "[[1]\n",
+ " [2]\n",
+ " [3]]\n",
+ "a=\n",
+ "[[1]\n",
+ " [1]\n",
+ " [1]]\n",
+ "Projection p of b onto the line through a is x***a=\n",
+ "[[2]\n",
+ " [2]\n",
+ " [2]]\n",
+ "cos(thetha) = 0.925820099773\n"
+ ]
+ }
+ ],
+ "source": [
+ "from numpy import mat,transpose,sqrt,transpose\n",
+ "b=mat([[1],[2],[3]])\n",
+ "print 'b=\\n',b\n",
+ "a=mat([[1],[1],[1]])\n",
+ "print 'a=\\n',a\n",
+ "x=(transpose(a)*b)/(transpose(a)*a)\n",
+ "x=x[0,0]\n",
+ "print 'Projection p of b onto the line through a is x***a=\\n',(x*a)\n",
+ "cos_theta=(transpose(a)*b)[0,0]/(sqrt(transpose(a)*a)[0,0]*sqrt(transpose(b)*b)[0,0])\n",
+ "print 'cos(thetha) =',cos_theta"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex:3.2.2 Pg: 156"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "a=\n",
+ "[[ 1.]\n",
+ " [ 1.]\n",
+ " [ 1.]]\n",
+ "Matrix that projects onto a line through a=(1,1,1) is\n",
+ "[[ 0.33333333 0.33333333 0.33333333]\n",
+ " [ 0.33333333 0.33333333 0.33333333]\n",
+ " [ 0.33333333 0.33333333 0.33333333]]\n"
+ ]
+ }
+ ],
+ "source": [
+ "from numpy import mat,transpose\n",
+ "a=mat([[1.],[1],[1]])\n",
+ "print 'a=\\n',a\n",
+ "P=(a*transpose(a))/(transpose(a)*a)[0,0]\n",
+ "print 'Matrix that projects onto a line through a=(1,1,1) is\\n',P"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex:3.2.3 Pg: 156"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "a=\n",
+ "[[ 0.70710678]\n",
+ " [ 0.70710678]]\n",
+ "Projection of line onto the thetha-direction(thetha taken as 45) in the x-y plane passing through a is\n",
+ "[[ 0.5 0.5]\n",
+ " [ 0.5 0.5]]\n"
+ ]
+ }
+ ],
+ "source": [
+ "from numpy import mat,transpose,sin,pi,cos\n",
+ "thetha=45# #Taking some value for thetha\n",
+ "a=mat([[cos(thetha*pi/180)],[sin(thetha*pi/180)]])\n",
+ "print 'a=\\n',a\n",
+ "P=(a*transpose(a))/(transpose(a)*a)\n",
+ "print 'Projection of line onto the thetha-direction(thetha taken as 45) in the x-y plane passing through a is\\n',P"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex:3.3.1 Pg: 165"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 6,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "A=\n",
+ "[[ 0.09246118 0.04909557 0.71167391 0.77035248]\n",
+ " [ 0.4079182 0.15730679 0.91259156 0.21064709]\n",
+ " [ 0.02898159 0.87211114 0.11852139 0.69009963]\n",
+ " [ 0.16889615 0.35412933 0.60067694 0.1180308 ]]\n",
+ "P=A*inv(A*A)*A\n",
+ "Projection of a invertible 4x4 matrix on to the whole space is:\n",
+ "[[ 3.38771356e-02 -8.74775251e-02 -1.51348916e-02 1.06873528e+00]\n",
+ " [ -8.74775251e-02 1.39664206e-03 1.08138671e+00 4.69417392e-03]\n",
+ " [ -1.51348916e-02 1.08138671e+00 -1.24018336e-04 -6.61277992e-02]\n",
+ " [ 1.06873528e+00 4.69417392e-03 -6.61277992e-02 -7.30165590e-03]]\n",
+ "Its identity matrix.\n"
+ ]
+ }
+ ],
+ "source": [
+ "from numpy import mat,transpose,linalg,random\n",
+ "A=random.rand(4,4)\n",
+ "print 'A=\\n',A\n",
+ "P=A*linalg.inv(transpose(A)*A)*transpose(A)\n",
+ "print 'P=A*inv(A''*A)*A'\n",
+ "print 'Projection of a invertible 4x4 matrix on to the whole space is:\\n',P\n",
+ "print 'Its identity matrix.'"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex:3.3.2 Pg: 166"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 7,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "b=C+Dt\n",
+ "Ax=b\n",
+ "A=\n",
+ "[[ 1 -1]\n",
+ " [ 1 1]\n",
+ " [ 1 2]]\n",
+ "b=\n",
+ "[[1]\n",
+ " [1]\n",
+ " [3]]\n",
+ "If Ax=b could be solved then they would be no errors, they cant be solved because the points are not on a line.Therefore they are solved by least squares.\n",
+ "so,AAx**=Ab\n",
+ "C** = 1.28571428571\n",
+ "D**= 0.571428571429\n",
+ "The best line is 9/7+4/7t\n"
+ ]
+ }
+ ],
+ "source": [
+ "from numpy import mat,transpose,zeros,linalg\n",
+ "print 'b=C+Dt'\n",
+ "print 'Ax=b'\n",
+ "A=mat([[1, -1],[1, 1],[1, 2]])\n",
+ "print 'A=\\n',A\n",
+ "b=mat([[1],[1],[3]])\n",
+ "print 'b=\\n',b\n",
+ "print 'If Ax=b could be solved then they would be no errors, they can''t be solved because the points are not on a line.Therefore they are solved by least squares.'\n",
+ "print 'so,A''Ax**=A''b'\n",
+ "x=zeros([1,2])\n",
+ "x=linalg.solve((transpose(A)*A), (transpose(A)*b))\n",
+ "print 'C** =',x[0,0]\n",
+ "print 'D**=',x[1,0]\n",
+ "print 'The best line is 9/7+4/7t'"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex:3.4.1 Pg: 175"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 8,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Q=\n",
+ "[[ 0.70710678 -0.70710678]\n",
+ " [ 0.70710678 0.70710678]]\n",
+ "\n",
+ "Q'=inv(Q)=\n",
+ "[[ 0.70710678 0.70710678]\n",
+ " [-0.70710678 0.70710678]]\n",
+ "\n",
+ "Q rotates every vector through an angle thetha, and Q rotates it back through -thetha.The columns are clearly orthogonal and they are orthonormal because sin**2(theta)+cos**2(thetha)=1.\n"
+ ]
+ }
+ ],
+ "source": [
+ "from numpy import mat,transpose,sin,pi,cos\n",
+ "thetha=45##Taking some value for thetha.\n",
+ "Q=mat([[cos(pi/180*thetha),-sin(thetha*pi/180)],[sin(pi/180*thetha),cos(pi/180*thetha)]])\n",
+ "print 'Q=\\n',Q\n",
+ "print \"\\nQ'=inv(Q)=\\n\",transpose(Q)\n",
+ "print '\\nQ rotates every vector through an angle thetha, and Q'' rotates it back through -thetha.The columns are clearly orthogonal and they are orthonormal because sin**2(theta)+cos**2(thetha)=1.'"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex:3.4.2 Pg: 175"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 9,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Any permutation matrix is an orthogonal matrix.The columns are certainly unit vectors and certainly orthogonal-because the 1 appears in a differnt place in each column\n",
+ "P=\n",
+ "[[0 1 0]\n",
+ " [0 0 1]\n",
+ " [1 0 0]]\n",
+ "inv(P)=P'=\n",
+ "[[0 0 1]\n",
+ " [1 0 0]\n",
+ " [0 1 0]]\n",
+ "And,P'*P=\n",
+ "[[1 0 0]\n",
+ " [0 1 0]\n",
+ " [0 0 1]]\n"
+ ]
+ }
+ ],
+ "source": [
+ "from numpy import mat,transpose\n",
+ "print 'Any permutation matrix is an orthogonal matrix.The columns are certainly unit vectors and certainly orthogonal-because the 1 appears in a differnt place in each column'\n",
+ "P=mat([[0, 1, 0],[0, 0 ,1],[1, 0, 0]])\n",
+ "print 'P=\\n',P\n",
+ "print \"inv(P)=P'=\\n\",transpose(P)\n",
+ "print \"And,P'*P=\\n\",(transpose(P)*P)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex:3.4.3 Pg: 175"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 10,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "If we project b=(x,y,z) onto the x-y plane then its projection is p=(x,y,0),and is the sum of projection onto x- any y-axes.\n",
+ "q1=\n",
+ "[[1]\n",
+ " [0]\n",
+ " [0]]\n",
+ "q2=\n",
+ "[[0]\n",
+ " [1]\n",
+ " [0]]\n",
+ "Overall projection matrix,P=\n",
+ "[[1 0 0]\n",
+ " [0 1 0]\n",
+ " [0 0 0]]\n",
+ "and,P[x#y#z]=[x#y#0]\n",
+ "Projection onto a plane=sum of projections onto orthonormal q1 and q2.\n"
+ ]
+ }
+ ],
+ "source": [
+ "from numpy import mat,transpose,random\n",
+ "print 'If we project b=(x,y,z) onto the x-y plane then its projection is p=(x,y,0),and is the sum of projection onto x- any y-axes.'\n",
+ "b=random.rand(3,1)\n",
+ "q1=mat([[1],[0],[0]])\n",
+ "print 'q1=\\n',q1\n",
+ "q2=mat([[0],[1],[0]])\n",
+ "print 'q2=\\n',q2\n",
+ "P=q1*transpose(q1)+q2*transpose(q2)\n",
+ "print 'Overall projection matrix,P=\\n',P\n",
+ "print 'and,P[x#y#z]=[x#y#0]'\n",
+ "print 'Projection onto a plane=sum of projections onto orthonormal q1 and q2.'"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex:3.4.4 Pg: 166"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 19,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "y=C+Dt\n",
+ "Ax=b\n",
+ "A=\n",
+ "[[ 1 -3]\n",
+ " [ 1 0]\n",
+ " [ 1 3]]\n",
+ "y=\n",
+ "[[ 0.72089857]\n",
+ " [ 0.89298883]\n",
+ " [ 0.60457288]]\n",
+ "the columns of A are orthogonal,so\n",
+ "C** =\n",
+ "[[ 0.12324779]]\n",
+ "D** =\n",
+ "[[-0.12014976 0. 0.12014976]\n",
+ " [-0.14883147 0. 0.14883147]\n",
+ " [-0.10076215 0. 0.10076215]]\n",
+ "C** gives the besy fit ny horizontal line, whereas D**t is the best fit by a straight line through the origin.\n"
+ ]
+ }
+ ],
+ "source": [
+ "from numpy import mat,transpose,random,zeros\n",
+ "print 'y=C+Dt'\n",
+ "print 'Ax=b'\n",
+ "A=mat([[1, -3],[1, 0],[1, 3]])\n",
+ "print 'A=\\n',A\n",
+ "y=random.rand(3,1)\n",
+ "print 'y=\\n',y\n",
+ "print 'the columns of A are orthogonal,so'\n",
+ "x=zeros([1,2])\n",
+ "print \"C** =\\n\",( (mat([1, 1, 1])*y)/(transpose(A[:,1])*A[:,1]) )\n",
+ "\n",
+ "print \"D** =\\n\",( mat([-3, 0 ,3]*y)/(transpose(A[:,1])*A[:,1]) )\n",
+ "print 'C** gives the besy fit ny horizontal line, whereas D**t is the best fit by a straight line through the origin.'"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex:3.4.5 Pg: 166"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 11,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "A=\n",
+ "[[1 0 1]\n",
+ " [1 0 0]\n",
+ " [2 1 0]]\n",
+ "Q=\n",
+ "[[ 0.40824829 0. 0.91287093]\n",
+ " [ 0.40824829 0. -0.18257419]\n",
+ " [ 0.81649658 1. -0.36514837]]\n"
+ ]
+ }
+ ],
+ "source": [
+ "from numpy import mat,transpose,zeros,shape,linalg\n",
+ "A=mat([[1, 0 ,1],[1, 0, 0],[2, 1, 0]]) #independent vectors stored in columns of A\n",
+ "print 'A=\\n',A\n",
+ "m,n=shape(A)\n",
+ "V=mat(zeros([n,n]))\n",
+ "R=mat(zeros([n,n]))\n",
+ "for k in range(0,n):\n",
+ " V[:,k]=A[:,k]\n",
+ " for j in range(0,k-1):\n",
+ " R[j,k]=transpose(V[:,j])*A[:,k]\n",
+ " V[:,k]=V[:,k]-R[j,k]*V[:,j]\n",
+ " \n",
+ " R[k,k]=linalg.norm(V[:,k])\n",
+ " V[:,k]=V[:,k]/R[k,k]\n",
+ "\n",
+ "print 'Q=\\n',V"
+ ]
+ }
+ ],
+ "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_And_Its_Applications_by_G._Strang/CHAPTER4.ipynb b/Linear_Algebra_And_Its_Applications_by_G._Strang/CHAPTER4.ipynb
new file mode 100644
index 00000000..a31c01e3
--- /dev/null
+++ b/Linear_Algebra_And_Its_Applications_by_G._Strang/CHAPTER4.ipynb
@@ -0,0 +1,194 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 4 Determinants"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex:4.3.1 Pg:210"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Determinant= -0.0288448892628\n"
+ ]
+ }
+ ],
+ "source": [
+ "from numpy.linalg import det\n",
+ "from numpy.random import rand\n",
+ "n= 4 # the value of n\n",
+ "a=rand(n,n)\n",
+ "determinant = det(a)\n",
+ "print 'Determinant=',determinant"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex:4.3.3 Pg: 214"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "A=\n",
+ "[[ 2 -1 0 0]\n",
+ " [-1 2 -1 0]\n",
+ " [ 0 -1 2 -1]\n",
+ " [ 0 0 -1 2]]\n",
+ "[[ 5.]]\n"
+ ]
+ }
+ ],
+ "source": [
+ "from numpy import mat,shape, transpose as tp\n",
+ "from numpy.linalg import det\n",
+ "A=[[2, -1, 0, 0],[-1, 2, -1, 0],[0, -1 ,2 ,-1],[0, 0 ,-1 ,2]]\n",
+ "A=mat(A)\n",
+ "print 'A=\\n',A\n",
+ "m,n=shape(A)\n",
+ "\n",
+ "a=A[1,:]\n",
+ "\n",
+ "c=[];\n",
+ "for L in range(0,4):\n",
+ " \n",
+ " for i in range(0,4):\n",
+ " l=[]\n",
+ " for j in range(0,4):\n",
+ " if i!=j:\n",
+ " l.append(j)\n",
+ " \n",
+ " B=A[1:4,l]\n",
+ " \n",
+ " \n",
+ " c1l=(-1)**(1+L+1)*det(B);\n",
+ " c=c+[c1l]\n",
+ "\n",
+ "d=a*tp(mat(c))+1;\n",
+ "print d"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex:4.4.1 Pg:282"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 10,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Adjoint of A:\n",
+ "[[ 1. -1. 0.]\n",
+ " [ 0. 1. -1.]\n",
+ " [ 0. 0. 1.]]\n",
+ "inv(A):\n",
+ "[[ 1. -1. 0.]\n",
+ " [ 0. 1. -1.]\n",
+ " [ 0. 0. 1.]]\n"
+ ]
+ }
+ ],
+ "source": [
+ "# inverse of a sum matrix is a difference matrix\n",
+ "from numpy import mat,linalg,dot\n",
+ "A=mat([[1, 1 ,1],[0, 1, 1],[0, 0, 1]])\n",
+ "adjA = linalg.det(A)*linalg.inv(A)*linalg.det(A)\n",
+ "invA=(adjA/det(A))\n",
+ "print 'Adjoint of A:\\n',adjA\n",
+ "print 'inv(A):\\n',invA"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex:4.4.2 Pg: 222"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 56,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "x1= 9.0\n",
+ "x2= -3.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "from numpy import mat\n",
+ "from numpy.linalg import det\n",
+ "#x1+3x2=0\n",
+ "#2x1+4x2=6\n",
+ "A=mat([[1, 3],[2, 4]])\n",
+ "b=mat([[0],[6]])\n",
+ "X1=mat([[0, 3],[6, 4]])\n",
+ "X2=mat([[1, 0],[2, 6]])\n",
+ "print 'x1=',(det(X1)/det(A))\n",
+ "print 'x2=',(det(X2)/det(A))"
+ ]
+ }
+ ],
+ "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_And_Its_Applications_by_G._Strang/CHAPTER5.ipynb b/Linear_Algebra_And_Its_Applications_by_G._Strang/CHAPTER5.ipynb
new file mode 100644
index 00000000..af1f3093
--- /dev/null
+++ b/Linear_Algebra_And_Its_Applications_by_G._Strang/CHAPTER5.ipynb
@@ -0,0 +1,411 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 5 Eigenvalues and Eigenvectors"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex:5.1.1 Pg: 238"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Eigen values: [ 3. 2.]\n",
+ "Eigen vectors:\n",
+ "[[ 1. 0.]] \n",
+ " and\n",
+ "[[ 0. 1.]]\n"
+ ]
+ }
+ ],
+ "source": [
+ "from numpy import mat\n",
+ "from numpy.linalg import eig\n",
+ "A=mat([[3, 0],[0, 2]])\n",
+ "Eig,V=eig(A)\n",
+ "print 'Eigen values:',Eig\n",
+ "print 'Eigen vectors:\\n',V[0],'\\n and\\n',V[1]"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex:5.1.2 Pg: 238"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "The eigen values of a projection matrix are 1 or 0.\n",
+ "Eigen values: ['1', '0']\n",
+ "Eigen vectors:\n",
+ "[[ 0.70710678 -0.70710678]] \n",
+ " and\n",
+ "[[ 0.70710678 0.70710678]]\n"
+ ]
+ }
+ ],
+ "source": [
+ "from __future__ import division\n",
+ "from numpy import mat\n",
+ "from numpy.linalg import eig\n",
+ "print 'The eigen values of a projection matrix are 1 or 0.'\n",
+ "P=mat([[1/2, 1/2],[1/2, 1/2]])\n",
+ "Eig,V=eig(P)\n",
+ "Eig=[\"%.f\"%xx for xx in Eig]\n",
+ "print 'Eigen values:',Eig\n",
+ "print 'Eigen vectors:\\n',V[0],'\\n and\\n',V[1]"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex:5.2.1 Pg: 238"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Eigenvalue matrix: [ 3. 2.]\n",
+ "S=\n",
+ "[[ 1. 0.]\n",
+ " [ 0. 1.]]\n",
+ "AS=S*eigenvaluematrix\n",
+ "[[ 3. 0.]\n",
+ " [ 0. 2.]]\n",
+ "Therefore inv(S)*A*S=eigenvalue matrix\n"
+ ]
+ }
+ ],
+ "source": [
+ "from __future__ import division\n",
+ "from numpy import mat\n",
+ "from numpy.linalg import eig\n",
+ "P=mat([[1/2, 1/2],[1/2, 1/2]])\n",
+ "Val,V=eig(A)\n",
+ "print 'Eigenvalue matrix:',Val\n",
+ "print 'S=\\n',V\n",
+ "print 'AS=S*eigenvaluematrix\\n',(A*V)\n",
+ "print 'Therefore inv(S)*A*S=eigenvalue matrix'"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex:5.2.2 Pg: 238"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "The eigenvalues themselves are not so clear for a rotation.\n",
+ "90 degree rotation\n",
+ "K= [[ 0 -1]\n",
+ " [ 1 0]]\n",
+ "Eigen values: [ 0.+1.j 0.-1.j]\n",
+ "Eigen vectors:\n",
+ "[[ 0.70710678+0.j 0.70710678-0.j]] \n",
+ " and\n",
+ "[[ 0.-0.70710678j 0.+0.70710678j]]\n"
+ ]
+ }
+ ],
+ "source": [
+ "from __future__ import division\n",
+ "from numpy import mat\n",
+ "from numpy.linalg import eig\n",
+ "print 'The eigenvalues themselves are not so clear for a rotation.'\n",
+ "print '90 degree rotation'\n",
+ "K=mat([[0, -1],[1, 0]])\n",
+ "print 'K=',K\n",
+ "Val,V=eig(K)\n",
+ "print 'Eigen values:',Val\n",
+ "print 'Eigen vectors:\\n',V[0],'\\n and\\n',V[1]"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex:5.2.3 Pg: 249"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "K is rotation through 90 degree,then K**2 is rotation through 180 degree and inv(k is rotation through -90 degree)\n",
+ "K=\n",
+ "[[ 0 -1]\n",
+ " [ 1 0]]\n",
+ "K**2=\n",
+ "[[-1 0]\n",
+ " [ 0 -1]]\n",
+ "K**3=\n",
+ "[[ 0 1]\n",
+ " [-1 0]]\n",
+ "K**4=\n",
+ "[[1 0]\n",
+ " [0 1]]\n",
+ "K**4 is a complete rotation through 360 degree.\n",
+ "Eigen value matrix,D of K:\n",
+ "[ 0.+1.j 0.-1.j]\n",
+ "and also D**4=\n",
+ "[ 1.+0.j 1.+0.j]\n"
+ ]
+ }
+ ],
+ "source": [
+ "from __future__ import division\n",
+ "from numpy import mat\n",
+ "from numpy.linalg import eig\n",
+ "print 'K is rotation through 90 degree,then K**2 is rotation through 180 degree and inv(k is rotation through -90 degree)'\n",
+ "K=mat([[0, -1],[1, 0]])\n",
+ "print 'K=\\n',K\n",
+ "print 'K**2=\\n',(K*K)\n",
+ "print 'K**3=\\n',(K*K*K)\n",
+ "print 'K**4=\\n',(K**4)\n",
+ "D,V=eig(K)\n",
+ "print 'K**4 is a complete rotation through 360 degree.'\n",
+ "print 'Eigen value matrix,D of K:\\n',D\n",
+ "print 'and also D**4=\\n',(D**4)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex:5.3.1 Pg: 249"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 6,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "A=\n",
+ "[[ 0. 4. ]\n",
+ " [ 0. 0.5]]\n",
+ "Eigen values: [ 0. 0.5]\n",
+ "[[ 1.]\n",
+ " [ 0.]]\n",
+ "k= 0\n",
+ "U(k+1)(K from 0 to 5)\n",
+ "[[ 0.]\n",
+ " [ 0.]]\n",
+ "k= 1\n",
+ "U(k+1)(K from 0 to 5)\n",
+ "[[ 0.]\n",
+ " [ 0.]]\n",
+ "k= 2\n",
+ "U(k+1)(K from 0 to 5)\n",
+ "[[ 0.]\n",
+ " [ 0.]]\n",
+ "k= 3\n",
+ "U(k+1)(K from 0 to 5)\n",
+ "[[ 0.]\n",
+ " [ 0.]]\n",
+ "k= 4\n",
+ "U(k+1)(K from 0 to 5)\n",
+ "[[ 0.]\n",
+ " [ 0.]]\n",
+ "k= 5\n",
+ "U(k+1)(K from 0 to 5)\n",
+ "[[ 0.]\n",
+ " [ 0.]]\n",
+ "k= 5\n",
+ "U(k+1)=\n",
+ "[[ 0.49613894]\n",
+ " [ 0.06201737]]\n",
+ "k= 5\n",
+ "U(k+1)=\n",
+ "[[ 0.24806947]\n",
+ " [ 0.03100868]]\n",
+ "k= 5\n",
+ "U(k+1)=\n",
+ "[[ 0.12403473]\n",
+ " [ 0.01550434]]\n",
+ "k= 5\n",
+ "U(k+1)=\n",
+ "[[ 0.06201737]\n",
+ " [ 0.00775217]]\n",
+ "k= 5\n",
+ "U(k+1)=\n",
+ "[[ 0.03100868]\n",
+ " [ 0.00387609]]\n",
+ "k= 5\n",
+ "U(k+1)=\n",
+ "[[ 0.01550434]\n",
+ " [ 0.00193804]]\n"
+ ]
+ }
+ ],
+ "source": [
+ "from __future__ import division\n",
+ "from numpy import mat\n",
+ "from numpy.linalg import eig\n",
+ "A=mat([[0, 4],[0, 1/2]])\n",
+ "print 'A=\\n',A\n",
+ "Eig,zz=eig(A)\n",
+ "print 'Eigen values:',Eig\n",
+ "D,v=eig(A)\n",
+ "u0=v[:,0] #Taking u0 as the 1st eigen Vector.\n",
+ "print u0\n",
+ "for k in range(0,6):\n",
+ " print 'k=',k\n",
+ " u=A*u0\n",
+ " print 'U(k+1)(K from 0 to 5)\\n',u\n",
+ " u0=u\n",
+ "\n",
+ "u0=v[:,1] ##Taking u0 as the 2nd eigen vector.\n",
+ "for ki in range(0,6):\n",
+ " print 'k=',k\n",
+ " u=A*u0\n",
+ " print 'U(k+1)=\\n',u\n",
+ " u0=u"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex:5.5.1 Pg:282"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 8,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "x= (3+4j)\n",
+ "xx_= (25+0j)\n",
+ "r= (5+0j)\n"
+ ]
+ }
+ ],
+ "source": [
+ "from numpy import sqrt\n",
+ "x=3+4*1J\n",
+ "print 'x=',x\n",
+ "x_=x.conjugate()\n",
+ "print 'xx_=',x*x_\n",
+ "r=sqrt(x*x_)\n",
+ "print 'r=',r"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex:5.5.2 Pg:282"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 9,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Length of x squared: 2.0\n",
+ "Length of y squared: 25.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "from numpy import mat\n",
+ "i=1J\n",
+ "x=mat([[1, i]]).H\n",
+ "y=mat([[2+1*i, 2-4*i]]).H\n",
+ "print 'Length of x squared:',abs(x.H*x)[0,0]\n",
+ "print 'Length of y squared:',abs( y.H*y)[0,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_And_Its_Applications_by_G._Strang/CHAPTER6.ipynb b/Linear_Algebra_And_Its_Applications_by_G._Strang/CHAPTER6.ipynb
new file mode 100644
index 00000000..bb0b912e
--- /dev/null
+++ b/Linear_Algebra_And_Its_Applications_by_G._Strang/CHAPTER6.ipynb
@@ -0,0 +1,373 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 6 Positive Definite Matrices"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex:6.1.1 Pg:313"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "f(x,y)=x**2-10*x*y+y**2\n",
+ "f(1,1)= -8\n",
+ "The conditions a>0 and c>0 ensure that f(x,y) is positive on the x and y axes. But this function is negative on the line x=y,because b=-10 overwhelms a and c. \n"
+ ]
+ }
+ ],
+ "source": [
+ "print 'f(x,y)=x**2-10*x*y+y**2'\n",
+ "a=1\n",
+ "c=1\n",
+ "def f(x,y):\n",
+ " ff=x**2-10*x*y+y**2\n",
+ " return ff\n",
+ "print 'f(1,1)=',f(1,1)\n",
+ "print 'The conditions a>0 and c>0 ensure that f(x,y) is positive on the x and y axes. But this function is negative on the line x=y,because b=-10 overwhelms a and c. '"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex:6.1.3 Pg:315"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "f(x,y)=2*x**2+4*x*y+y**2\n",
+ "ac= 1\n",
+ "b**2= 4\n",
+ "Saddle point,as ac<b**2\n"
+ ]
+ }
+ ],
+ "source": [
+ "print 'f(x,y)=2*x**2+4*x*y+y**2'\n",
+ "A=[[2, 2],[2, 1]]\n",
+ "a=1\n",
+ "c=1\n",
+ "b=2\n",
+ "print 'ac=',a*c\n",
+ "print 'b**2=',b**2\n",
+ "print 'Saddle point,as ac<b**2'"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex:6.1.4 Pg:315"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "f(x,y)=2*x**2+4*x*y+y**2\n",
+ "ac= 0\n",
+ "b**2= 1\n",
+ "Saddle point,as ac<b**2\n"
+ ]
+ }
+ ],
+ "source": [
+ "print 'f(x,y)=2*x**2+4*x*y+y**2'\n",
+ "A=[[2 ,2],[2, 1]]\n",
+ "a=0\n",
+ "c=0\n",
+ "b=1\n",
+ "print 'ac=',a*c\n",
+ "print 'b**2=',b**2\n",
+ "print 'Saddle point,as ac<b**2'"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex:6.2.2 Pg:313"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "f(x,y)=x**2+4*x*y+y**2\n",
+ "f(0,0)= 0\n",
+ "Here 2b=4 it still does not ensure a minimum ,the sign of b is of no importance.Neither F nor f has a minimum at(0,0) because f(1,-1)=-1.\n"
+ ]
+ }
+ ],
+ "source": [
+ "print 'f(x,y)=x**2+4*x*y+y**2'\n",
+ "a=1\n",
+ "c=1\n",
+ "def f(x,y):\n",
+ " ff=x**2+4*x*y+y**2\n",
+ " return ff\n",
+ "print 'f(0,0)=',f(0,0)\n",
+ "print 'Here 2b=4 it still does not ensure a minimum ,the sign of b is of no importance.Neither F nor f has a minimum at(0,0) because f(1,-1)=-1.'"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex:6.3.1 Pg:332"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "A= [[-1]\n",
+ " [ 2]\n",
+ " [ 2]]\n",
+ "U= [[-0.33333333 0.66666667 0.66666667]\n",
+ " [ 0.66666667 0.66666667 -0.33333333]\n",
+ " [ 0.66666667 -0.33333333 0.66666667]]\n",
+ "diagnol= [ 3.]\n",
+ "V'= [[ 1.]]\n",
+ "A=U*diagnol*V'=\n",
+ "[[-1. 2. 2.]\n",
+ " [ 2. 2. -1.]\n",
+ " [ 2. -1. 2.]]\n"
+ ]
+ }
+ ],
+ "source": [
+ "from scipy.linalg import svd\n",
+ "from numpy import array,transpose\n",
+ "A=transpose(array([[-1, 2, 2]]))\n",
+ "print 'A=',A\n",
+ "ans=svd(A)\n",
+ "U=ans[0]\n",
+ "diagnol=ans[1]\n",
+ "V=ans[2] \n",
+ "print 'U=',U\n",
+ "print 'diagnol=',diagnol\n",
+ "print \"V'=\",V\n",
+ "print \"A=U*diagnol*V'=\\n\",U*diagnol*transpose(V)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex:6.3.2 Pg:332"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 6,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "A=\n",
+ "[[-1 1 0]\n",
+ " [ 0 -1 1]]\n",
+ "U=\n",
+ "[[-0.70710678 0.70710678]\n",
+ " [ 0.70710678 0.70710678]]\n",
+ "Diagonal=\n",
+ "[[ 1.73205081 0. 0. ]\n",
+ " [ 0. 1. 0. ]]\n",
+ "V'= [[ 4.08248290e-01 -7.07106781e-01 5.77350269e-01]\n",
+ " [ -8.16496581e-01 -2.77555756e-16 5.77350269e-01]\n",
+ " [ 4.08248290e-01 7.07106781e-01 5.77350269e-01]]\n",
+ "[[-1.22474487 0.70710678 0. ]\n",
+ " [ 1.22474487 0.70710678 0. ]]\n",
+ "A=U*diagonal*V'=\n",
+ "[[-1.07735027 0.8660254 -0.29885849]\n",
+ " [-0.07735027 -0.8660254 1.11535507]]\n"
+ ]
+ }
+ ],
+ "source": [
+ "from scipy.linalg import svd\n",
+ "from numpy import mat,array,transpose as tp, zeros\n",
+ "A=mat([[-1, 1, 0],[0, -1, 1]])\n",
+ "print 'A=\\n',A\n",
+ "U,diagnl1,V=svd(A)\n",
+ "diagnl=zeros([2,3])\n",
+ "diagnl[0,0]=diagnl1[0]\n",
+ "diagnl[1,1]=diagnl1[1]\n",
+ "U=mat(U)\n",
+ "diagnl=mat(diagnl)\n",
+ "V=mat(V)\n",
+ "print 'U=\\n',U\n",
+ "print 'Diagonal=\\n',diagnl\n",
+ "print \"V'=\",tp(V)\n",
+ "print (U*diagnl)\n",
+ "print \"A=U*diagonal*V'=\\n\",((U*diagnl)*tp(V))"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex:6.3.3 Pg:332"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 7,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "A=\n",
+ "[[ 1 -2]\n",
+ " [ 3 -1]]\n",
+ "Q=\n",
+ "[[ 1.11022302e-16 -1.00000000e+00]\n",
+ " [ 1.00000000e+00 1.11022302e-16]]\n",
+ "S=\n",
+ "[[ 3. -1.]\n",
+ " [-1. 2.]]\n",
+ "A=SQ=\n",
+ "[[ 1. -2.]\n",
+ " [ 3. -1.]]\n"
+ ]
+ }
+ ],
+ "source": [
+ "from numpy import mat, transpose as tp \n",
+ "from scipy.linalg import svd\n",
+ "A=mat([[1, -2],[3, -1]])\n",
+ "print 'A=\\n',A\n",
+ "U,S,V=svd(A)\n",
+ "Q=U*tp(mat(V))\n",
+ "S=V*S*tp(mat(V))\n",
+ "print 'Q=\\n',Q\n",
+ "print 'S=\\n',S\n",
+ "print 'A=SQ=\\n',(Q*S)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex:6.3.4 Pg:332"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 8,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "A=\n",
+ "[[ 1 -2]\n",
+ " [ 3 -1]]\n",
+ "Q=\n",
+ "[[ 1.11022302e-16 -1.00000000e+00]\n",
+ " [ 1.00000000e+00 1.11022302e-16]]\n",
+ "S=\n",
+ "[[2 1]\n",
+ " [1 3]]\n",
+ "A=S'Q=\n",
+ "[[-1. 2.]\n",
+ " [-3. 1.]]\n"
+ ]
+ }
+ ],
+ "source": [
+ "from __future__ import division\n",
+ "from numpy import mat, transpose as tp \n",
+ "from scipy.linalg import svd\n",
+ "\n",
+ "A=mat([[1, -2],[3, -1]])\n",
+ "print 'A=\\n',A\n",
+ "U,diag1,V=svd(A)\n",
+ "Q=U*tp(mat(V))\n",
+ "S=mat([[2, 1],[1, 3]])\n",
+ "print 'Q=\\n',Q\n",
+ "print 'S=\\n',S\n",
+ "print \"A=S'Q=\\n\",(S*tp(mat(Q)))"
+ ]
+ }
+ ],
+ "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_And_Its_Applications_by_G._Strang/CHAPTER7.ipynb b/Linear_Algebra_And_Its_Applications_by_G._Strang/CHAPTER7.ipynb
new file mode 100644
index 00000000..b791345b
--- /dev/null
+++ b/Linear_Algebra_And_Its_Applications_by_G._Strang/CHAPTER7.ipynb
@@ -0,0 +1,352 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 7 Computations with Matrices"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex:7.4.1 Pg: 238"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "intial v & w:\n",
+ "[[ 0.]\n",
+ " [ 0.]] \n",
+ "\n",
+ "k= 0\n",
+ "v(k+1) & w(k+1)= [[ 1.]\n",
+ " [ 1.]] \n",
+ "\n",
+ "k= 1\n",
+ "v(k+1) & w(k+1)= [[ 1.5]\n",
+ " [ 1.5]] \n",
+ "\n",
+ "k= 2\n",
+ "v(k+1) & w(k+1)= [[ 1.75]\n",
+ " [ 1.75]] \n",
+ "\n",
+ "k= 3\n",
+ "v(k+1) & w(k+1)= [[ 1.875]\n",
+ " [ 1.875]] \n",
+ "\n",
+ "k= 4\n",
+ "v(k+1) & w(k+1)= [[ 1.9375]\n",
+ " [ 1.9375]] \n",
+ "\n",
+ "k= 5\n",
+ "v(k+1) & w(k+1)= [[ 1.96875]\n",
+ " [ 1.96875]] \n",
+ "\n",
+ "k= 6\n",
+ "v(k+1) & w(k+1)= [[ 1.984375]\n",
+ " [ 1.984375]] \n",
+ "\n",
+ "k= 7\n",
+ "v(k+1) & w(k+1)= [[ 1.9921875]\n",
+ " [ 1.9921875]] \n",
+ "\n",
+ "k= 8\n",
+ "v(k+1) & w(k+1)= [[ 1.99609375]\n",
+ " [ 1.99609375]] \n",
+ "\n",
+ "k= 9\n",
+ "v(k+1) & w(k+1)= [[ 1.99804688]\n",
+ " [ 1.99804688]] \n",
+ "\n",
+ "k= 10\n",
+ "v(k+1) & w(k+1)= [[ 1.99902344]\n",
+ " [ 1.99902344]] \n",
+ "\n",
+ "k= 11\n",
+ "v(k+1) & w(k+1)= [[ 1.99951172]\n",
+ " [ 1.99951172]] \n",
+ "\n",
+ "k= 12\n",
+ "v(k+1) & w(k+1)= [[ 1.99975586]\n",
+ " [ 1.99975586]] \n",
+ "\n",
+ "k= 13\n",
+ "v(k+1) & w(k+1)= [[ 1.99987793]\n",
+ " [ 1.99987793]] \n",
+ "\n",
+ "k= 14\n",
+ "v(k+1) & w(k+1)= [[ 1.99993896]\n",
+ " [ 1.99993896]] \n",
+ "\n",
+ "k= 15\n",
+ "v(k+1) & w(k+1)= [[ 1.99996948]\n",
+ " [ 1.99996948]] \n",
+ "\n",
+ "k= 16\n",
+ "v(k+1) & w(k+1)= [[ 1.99998474]\n",
+ " [ 1.99998474]] \n",
+ "\n",
+ "k= 17\n",
+ "v(k+1) & w(k+1)= [[ 1.99999237]\n",
+ " [ 1.99999237]] \n",
+ "\n",
+ "k= 18\n",
+ "v(k+1) & w(k+1)= [[ 1.99999619]\n",
+ " [ 1.99999619]] \n",
+ "\n",
+ "k= 19\n",
+ "v(k+1) & w(k+1)= [[ 1.99999809]\n",
+ " [ 1.99999809]] \n",
+ "\n",
+ "k= 20\n",
+ "v(k+1) & w(k+1)= [[ 1.99999905]\n",
+ " [ 1.99999905]] \n",
+ "\n",
+ "k= 21\n",
+ "v(k+1) & w(k+1)= [[ 1.99999952]\n",
+ " [ 1.99999952]] \n",
+ "\n",
+ "k= 22\n",
+ "v(k+1) & w(k+1)= [[ 1.99999976]\n",
+ " [ 1.99999976]] \n",
+ "\n",
+ "k= 23\n",
+ "v(k+1) & w(k+1)= [[ 1.99999988]\n",
+ " [ 1.99999988]] \n",
+ "\n",
+ "k= 24\n",
+ "v(k+1) & w(k+1)= [[ 1.99999994]\n",
+ " [ 1.99999994]] \n",
+ "\n",
+ "k= 25\n",
+ "v(k+1) & w(k+1)= [[ 1.99999997]\n",
+ " [ 1.99999997]] \n",
+ "\n"
+ ]
+ }
+ ],
+ "source": [
+ "from __future__ import division\n",
+ "from numpy import mat,transpose,zeros\n",
+ "A=mat([[2 ,-1],[-1, 2]])\n",
+ "S=mat([[2, 0],[0, 2]])\n",
+ "T=mat([[0, 1],[1, 0]])\n",
+ "p=S**-1*T\n",
+ "b=transpose(mat([2 ,2]))\n",
+ "x=zeros([2,1])\n",
+ "print 'intial v & w:\\n',x,'\\n'\n",
+ "x_1=zeros([1,2])\n",
+ "for k in range(0,26):\n",
+ " x_1=p*x+(S**-1)*b\n",
+ " x=x_1\n",
+ " print 'k=',k\n",
+ " print 'v(k+1) & w(k+1)=',x_1,'\\n'\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex:7.4.2 Pg: 238"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "intial v & w: [[ 0.]\n",
+ " [ 0.]]\n",
+ "k=\n",
+ "0\n",
+ "v(k+1) & w(k+1)=\n",
+ "[[ 0.10887353]\n",
+ " [ 0.53877511]]\n",
+ "k=\n",
+ "1\n",
+ "v(k+1) & w(k+1)=\n",
+ "[[ 0.37826108]\n",
+ " [ 0.67346888]]\n",
+ "k=\n",
+ "2\n",
+ "v(k+1) & w(k+1)=\n",
+ "[[ 0.44560797]\n",
+ " [ 0.70714233]]\n",
+ "k=\n",
+ "3\n",
+ "v(k+1) & w(k+1)=\n",
+ "[[ 0.46244469]\n",
+ " [ 0.71556069]]\n",
+ "k=\n",
+ "4\n",
+ "v(k+1) & w(k+1)=\n",
+ "[[ 0.46665387]\n",
+ " [ 0.71766528]]\n",
+ "k=\n",
+ "5\n",
+ "v(k+1) & w(k+1)=\n",
+ "[[ 0.46770617]\n",
+ " [ 0.71819143]]\n",
+ "k=\n",
+ "6\n",
+ "v(k+1) & w(k+1)=\n",
+ "[[ 0.46796924]\n",
+ " [ 0.71832296]]\n",
+ "k=\n",
+ "7\n",
+ "v(k+1) & w(k+1)=\n",
+ "[[ 0.46803501]\n",
+ " [ 0.71835585]]\n",
+ "k=\n",
+ "8\n",
+ "v(k+1) & w(k+1)=\n",
+ "[[ 0.46805145]\n",
+ " [ 0.71836407]]\n",
+ "k=\n",
+ "9\n",
+ "v(k+1) & w(k+1)=\n",
+ "[[ 0.46805556]\n",
+ " [ 0.71836612]]\n",
+ "k=\n",
+ "10\n",
+ "v(k+1) & w(k+1)=\n",
+ "[[ 0.46805659]\n",
+ " [ 0.71836664]]\n",
+ "k=\n",
+ "11\n",
+ "v(k+1) & w(k+1)=\n",
+ "[[ 0.46805685]\n",
+ " [ 0.71836676]]\n",
+ "k=\n",
+ "12\n",
+ "v(k+1) & w(k+1)=\n",
+ "[[ 0.46805691]\n",
+ " [ 0.7183668 ]]\n",
+ "k=\n",
+ "13\n",
+ "v(k+1) & w(k+1)=\n",
+ "[[ 0.46805693]\n",
+ " [ 0.71836681]]\n",
+ "k=\n",
+ "14\n",
+ "v(k+1) & w(k+1)=\n",
+ "[[ 0.46805693]\n",
+ " [ 0.71836681]]\n",
+ "k=\n",
+ "15\n",
+ "v(k+1) & w(k+1)=\n",
+ "[[ 0.46805693]\n",
+ " [ 0.71836681]]\n",
+ "k=\n",
+ "16\n",
+ "v(k+1) & w(k+1)=\n",
+ "[[ 0.46805693]\n",
+ " [ 0.71836681]]\n",
+ "k=\n",
+ "17\n",
+ "v(k+1) & w(k+1)=\n",
+ "[[ 0.46805693]\n",
+ " [ 0.71836681]]\n",
+ "k=\n",
+ "18\n",
+ "v(k+1) & w(k+1)=\n",
+ "[[ 0.46805693]\n",
+ " [ 0.71836681]]\n",
+ "k=\n",
+ "19\n",
+ "v(k+1) & w(k+1)=\n",
+ "[[ 0.46805693]\n",
+ " [ 0.71836681]]\n",
+ "k=\n",
+ "20\n",
+ "v(k+1) & w(k+1)=\n",
+ "[[ 0.46805693]\n",
+ " [ 0.71836681]]\n",
+ "k=\n",
+ "21\n",
+ "v(k+1) & w(k+1)=\n",
+ "[[ 0.46805693]\n",
+ " [ 0.71836681]]\n",
+ "k=\n",
+ "22\n",
+ "v(k+1) & w(k+1)=\n",
+ "[[ 0.46805693]\n",
+ " [ 0.71836681]]\n",
+ "k=\n",
+ "23\n",
+ "v(k+1) & w(k+1)=\n",
+ "[[ 0.46805693]\n",
+ " [ 0.71836681]]\n",
+ "k=\n",
+ "24\n",
+ "v(k+1) & w(k+1)=\n",
+ "[[ 0.46805693]\n",
+ " [ 0.71836681]]\n",
+ "k=\n",
+ "25\n",
+ "v(k+1) & w(k+1)=\n",
+ "[[ 0.46805693]\n",
+ " [ 0.71836681]]\n"
+ ]
+ }
+ ],
+ "source": [
+ "from __future__ import division\n",
+ "from numpy import mat,transpose,zeros\n",
+ "from numpy.random import rand\n",
+ "from numpy.linalg import inv\n",
+ "A=mat([[2, -1],[-1, 2]])\n",
+ "S=mat([[2, 0],[-1, 2]])\n",
+ "T=mat([[0, 1],[0, 0]])\n",
+ "b=rand(2,1)\n",
+ "p=inv(S)*T\n",
+ "x=zeros([2,1])\n",
+ "print 'intial v & w:',x\n",
+ "x_1=zeros([1,2])\n",
+ "for k in range(0,26):\n",
+ " x_1=p*x+inv(S)*b\n",
+ " x=x_1\n",
+ " print 'k=\\n',k\n",
+ " print 'v(k+1) & w(k+1)=\\n',x_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_And_Its_Applications_by_G._Strang/CHAPTER8.ipynb b/Linear_Algebra_And_Its_Applications_by_G._Strang/CHAPTER8.ipynb
new file mode 100644
index 00000000..ff8dc5c8
--- /dev/null
+++ b/Linear_Algebra_And_Its_Applications_by_G._Strang/CHAPTER8.ipynb
@@ -0,0 +1,70 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 8 - Linear Programming and Game Theory"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Ex:8.2.2 Pg: 238"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "New corner: [ 0. 0. 0. 0.33333333 3. ]\n",
+ "Minimum cost: -9.33333333333\n"
+ ]
+ }
+ ],
+ "source": [
+ "from scipy.optimize import linprog\n",
+ "from numpy import array, transpose\n",
+ "A=array([[1, 0 ,1 ,6, 2],[0, 1, 1, 0, 3]])\n",
+ "b=transpose(array([8, 9]))\n",
+ "c=transpose(array([0, 0, 7 ,-1, -3]))\n",
+ "lb=transpose(array([0, 0 ,0 ,0 ,0]))\n",
+ "ub=[]\n",
+ "ans=linprog(c,A,b)\n",
+ "x=ans.x\n",
+ "f=ans.fun\n",
+ "print 'New corner:',x\n",
+ "print 'Minimum cost:',f"
+ ]
+ }
+ ],
+ "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_And_Its_Applications_by_G._Strang/screenshots/Ch5Eigenmatrix.png b/Linear_Algebra_And_Its_Applications_by_G._Strang/screenshots/Ch5Eigenmatrix.png
new file mode 100644
index 00000000..e8f08c7d
--- /dev/null
+++ b/Linear_Algebra_And_Its_Applications_by_G._Strang/screenshots/Ch5Eigenmatrix.png
Binary files differ
diff --git a/Linear_Algebra_And_Its_Applications_by_G._Strang/screenshots/Ch5eigenVectors.png b/Linear_Algebra_And_Its_Applications_by_G._Strang/screenshots/Ch5eigenVectors.png
new file mode 100644
index 00000000..6e4a1111
--- /dev/null
+++ b/Linear_Algebra_And_Its_Applications_by_G._Strang/screenshots/Ch5eigenVectors.png
Binary files differ
diff --git a/Linear_Algebra_And_Its_Applications_by_G._Strang/screenshots/ch5eigenvaluematrix.png b/Linear_Algebra_And_Its_Applications_by_G._Strang/screenshots/ch5eigenvaluematrix.png
new file mode 100644
index 00000000..88f316f7
--- /dev/null
+++ b/Linear_Algebra_And_Its_Applications_by_G._Strang/screenshots/ch5eigenvaluematrix.png
Binary files differ