# MAT 232 Chapter Four

## Determinants

We won't do that much with them, but you should know how to calculate them, anyway, and then verify with Sage.

M = matrix([[2,0],[-1,3]]); M
 [ 2 0] [-1 3] [ 2 0] [-1 3]
det(M)
 6 6
N = matrix([[2,1,1],[0,5,-2],[1,-3,4]])
det(N)
 21 21
O = matrix([[1,0,0,1],[2,1,1,0],[-1,0,1,0],[1,1,1,0]])
det(O)
 1 1
det(random_matrix(ZZ,10))
 -11442264861 -11442264861

How fast is matrix determinant calculation?

timeit('det(random_matrix(RDF,3))',seconds=True)
 0.00021783370971679687 0.00021783370971679687
L = [random_matrix(RDF,i) for i in [1..100]]
timelist = [timeit('det(M)',seconds=True) for M in L]
points(enumerate(timelist),figsize=5)

Can we guess just how fast this is growing?

@interact def _(a=.0001,b=.0001,pow=2): show(points(enumerate(timelist))+plot(a*x^pow+b,(x,0,100)),figsize=5) pretty_print(html('${}x^{}+{}$'.format(a,pow,b)))

 a b pow

## Click to the left again to hide and once more to show the dynamic interactive window

M.parent().dims()[0]
 100 100
def mydet(M): n = M.dimensions()[0] if n == 1: return M[0,0] sum = 0 for a in range(n): sum += (-1)^a*M[a,0]*mydet(M.matrix_from_rows_and_columns([0..a-1]+[a+1..n-1],[1..n-1])) return sum
M = random_matrix(RDF,5) mydet(M)-det(M)
 4.163336342344337e-17 4.163336342344337e-17
L = [random_matrix(RDF,i) for i in [1..6]]

Don't try to run this too many times, my determinant function is slow!

timelist = [timeit('mydet(M)',seconds=True) for M in L]
@interact def _(a=.1,b=.1,pow=2): show(points(zip([1..6],timelist))+plot(a*x^pow+b,(x,0,6)),figsize=5)

## Click to the left again to hide and once more to show the dynamic interactive window

Whatever complexity this has, it's pretty bad.

We can also use determinants to tell us how much bigger or smaller Smiley Guy gets.

t = var('t') @interact def _(A=matrix(RDF,[[1,0],[0,1]]),auto_update=False): ID = matrix(RDF,[[1,0],[0,1]]) def makeface(M): pll=M*vector((-0.5,0.5)) plr=M*vector((-0.3,0.5)) prl=M*vector((0.3,0.5)) prr=M*vector((0.5,0.5)) left_eye=line([pll,plr])+point(pll,size=5)+point(plr,size=5) right_eye=line([prl,prr],color='green')+point(prl,size=5,color='green')+point(prr,size=5,color='green') mouth=parametric_plot(M*vector([t, -0.15*sin(2*pi*t)-0.5]), (t, -0.5, 0),color='red')+parametric_plot(M*vector([t, -0.15*sin(2*pi*t)-0.5]), (t,0,0.5),color='orange') face=parametric_plot(M*vector([cos(t),sin(t)]), (t,0,pi/2),color='black')+parametric_plot(M*vector([cos(t),sin(t)]), (t,pi/2,pi),color='lavender')+parametric_plot(M*vector([cos(t),sin(t)]), (t,pi,3*pi/2),color='cyan')+parametric_plot(M*vector([cos(t),sin(t)]),(t,3*pi/2,2*pi),color='sienna') return right_eye+left_eye+face+mouth pretty_print(html('smiley guy, then transformed by $A$')) pretty_print(html('which makes him {} times bigger!'.format(det(A)))) G = makeface(ID)+makeface(A) G.show(aspect_ratio=1,figsize=5)

## Click to the left again to hide and once more to show the dynamic interactive window

What if we had two transformations?

t = var('t') @interact(layout=[['A','B'],['auto_update']]) def _(A=matrix(RDF,[[1,0],[0,1]]),B=matrix(RDF,[[1,0],[0,1]]),auto_update=False): ID = matrix(RDF,[[1,0],[0,1]]) def makeface(M): pll=M*vector((-0.5,0.5)) plr=M*vector((-0.3,0.5)) prl=M*vector((0.3,0.5)) prr=M*vector((0.5,0.5)) left_eye=line([pll,plr])+point(pll,size=5)+point(plr,size=5) right_eye=line([prl,prr],color='green')+point(prl,size=5,color='green')+point(prr,size=5,color='green') mouth=parametric_plot(M*vector([t, -0.15*sin(2*pi*t)-0.5]), (t, -0.5, 0),color='red')+parametric_plot(M*vector([t, -0.15*sin(2*pi*t)-0.5]), (t,0,0.5),color='orange') face=parametric_plot(M*vector([cos(t),sin(t)]), (t,0,pi/2),color='black')+parametric_plot(M*vector([cos(t),sin(t)]), (t,pi/2,pi),color='lavender')+parametric_plot(M*vector([cos(t),sin(t)]), (t,pi,3*pi/2),color='cyan')+parametric_plot(M*vector([cos(t),sin(t)]),(t,3*pi/2,2*pi),color='sienna') return right_eye+left_eye+face+mouth pretty_print(html('smiley guy, then transformed by $A$, and next by $B$')) pretty_print(html('which makes him {} times bigger, then {} times bigger'.format(det(A),det(B)))) pretty_print(html('and the determinant of the matrix product is {}'.format(det(B*A)))) G = makeface(ID)+makeface(A)+makeface(B*A) G.show(aspect_ratio=1,figsize=5)

## Click to the left again to hide and once more to show the dynamic interactive window