{ "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 }