from numpy.linalg import det
from numpy.random import rand
n= 4 # the value of n
a=rand(n,n)
determinant = det(a)
print 'Determinant=',determinant
from numpy import mat,shape, transpose as tp
from numpy.linalg import det
A=[[2, -1, 0, 0],[-1, 2, -1, 0],[0, -1 ,2 ,-1],[0, 0 ,-1 ,2]]
A=mat(A)
print 'A=\n',A
m,n=shape(A)
a=A[1,:]
c=[];
for L in range(0,4):
for i in range(0,4):
l=[]
for j in range(0,4):
if i!=j:
l.append(j)
B=A[1:4,l]
c1l=(-1)**(1+L+1)*det(B);
c=c+[c1l]
d=a*tp(mat(c))+1;
print d
# inverse of a sum matrix is a difference matrix
from numpy import mat,linalg,dot
A=mat([[1, 1 ,1],[0, 1, 1],[0, 0, 1]])
adjA = linalg.det(A)*linalg.inv(A)*linalg.det(A)
invA=(adjA/det(A))
print 'Adjoint of A:\n',adjA
print 'inv(A):\n',invA
from numpy import mat
from numpy.linalg import det
#x1+3x2=0
#2x1+4x2=6
A=mat([[1, 3],[2, 4]])
b=mat([[0],[6]])
X1=mat([[0, 3],[6, 4]])
X2=mat([[1, 0],[2, 6]])
print 'x1=',(det(X1)/det(A))
print 'x2=',(det(X2)/det(A))