diff options
author | Trupti Kini | 2016-09-03 23:30:23 +0600 |
---|---|---|
committer | Trupti Kini | 2016-09-03 23:30:23 +0600 |
commit | 07cf280d177584baac74e351b3d76d085d0e6619 (patch) | |
tree | 202a15d7bc23aa1d1dc2a4a9397c94d344ff8dc8 /Linear_Algebra_And_Its_Applications_by_G._Strang/CHAPTER4.ipynb | |
parent | 3c5945f0aaf1d2d1f84e43ead6676aa497c9c4f8 (diff) | |
download | Python-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
Diffstat (limited to 'Linear_Algebra_And_Its_Applications_by_G._Strang/CHAPTER4.ipynb')
-rw-r--r-- | Linear_Algebra_And_Its_Applications_by_G._Strang/CHAPTER4.ipynb | 194 |
1 files changed, 194 insertions, 0 deletions
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 +} |