12.07.2015 Views

Linear Algebra

Linear Algebra

Linear Algebra

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

340 Chapter Four. Determinants3 The Rule of Sarrus is a mnemonic that students often learn in prior coursesfor the 3×3 determinant formula. On the right of the matrix copy the first twocolumns.a b c a bd e f d eg h i g hThe determinant is the sum of the three upper-left to lower-right diagonals minusthe three lower-left to upper-right diagonals aei + bfg + cdh − gec − hfa − idb.Count the operations involved in Sarrus’s formula and Chiò’s formula for the 3×3case and see which uses fewer.4 Prove Chiò’s Formula.Computer CodeThis implements Chiò’s Method. It is in the computer language Python but tomake it as readable as possible the code avoids some Python facilities. Note therecursive call in the final line of chio_det.#!/usr/bin/python# chio.py# Calculate a determinant using Chio’s method.# Jim Hefferon; PD# For demonstration only; does not handle the M[0][0]=0 case!def det_two(a,b,c,d):"""Return the determinant of the 2x2 matrix [[a,b], [c,d]]"""return a*d-b*cdef chio_mat(M):"""Return the Chio matrix as a list of the rowsM nxn matrix, list of rows"""dim=len(M)C=[]for row in range(1,dim):C.append([])for col in range(1,dim):C[-1].append(det_two(M[0][0], M[0][col], M[row][0], M[row][col]))return Cdef chio_det(M,show=None):"""Find the determinant of M by Chio’s methodM mxm matrix, list of rows"""dim=len(M)key_elet=M[0][0]if dim==1:return key_eletreturn chio_det(chio_mat(M))/(key_elet**(dim-2))if __name__==’__main__’:M=[[2,1,1], [3,4,-1], [1,5,1]]print "M=",Mprint "Chio det is", chio_det(M)This is the result of calling the program from my command line.$ python chio.pyM=[[2, 1, 1], [3, 4, -1], [1, 5, 1]]Chio det is 25

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!