Активируйте этот код перед использованием любых ячеек Linked Sage Cells
xxxxxxxxxx
M2=matrix(SR,2,var('a,b,c,d'))
M3=matrix(SR,3,var('a,b,c,d,e,f,g,h,i'))
M4=matrix(SR,4,var('a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p'))
A=random_matrix(ZZ,3,x=0,y=100)
B=random_matrix(ZZ,3,x=-100,y=0)
C=random_matrix(ZZ,4,x=-100,y=100)
xxxxxxxxxx
for M in [M2,M3,A,B,C]:
pretty_print((M,M.det()))
Активируйте этот код перед использованием любых ячеек Linked Python Cells
xxxxxxxxxx
import numpy,sympy
sympy.init_printing(use_unicode=True)
A1=numpy.matrix(
numpy.random.randint(0,100,size=(3,3)))
B1=numpy.matrix(
numpy.random.randint(-100,0,size=(3,3)))
C1=numpy.matrix(
numpy.random.randint(-100,100,size=(4,4)))
A2=sympy.Matrix([[-3,-3,1],[-4,-7,7],[2,2,5]])
B2=sympy.Matrix([[2,10,7],[-5,-6,-2],[-8,4,-8]])
C2=sympy.Matrix([[-8,-4,5,2],[3,-5,8,-2],
[5,4,-8,1],[7,-2,9,5]])
mm=sympy.symbols(' '.join(list('m_%d%d' %(i,j)
for i in [1,2] for j in [1,2])))
M=sympy.Matrix(int(2),int(2),mm)
nn=sympy.symbols(' '.join(list('n_%d%d' %(i,j)
for i in [1,2,3] for j in [1,2,3])))
N=sympy.Matrix(int(3),int(3),nn)
xxxxxxxxxx
for m in [A1,B1,C1]:
print([m,round(numpy.linalg.det(m))])
for m in [A2,B2,C2]:
print([m,m.det()])
for m in [M,N]:
sympy.pprint(m)
sympy.pprint(m.det())
Активируйте этот код перед использованием любых ячеек Linked R Cells
xxxxxxxxxx
%%r
A<-matrix(sample.int(100,size=3*3,replace=TRUE),
nrow=3,ncol=3)
B<-matrix(sample.int(100,size=3*3,replace=TRUE),
nrow=3,ncol=3)
C<-matrix(sample.int(100,size=4*4,replace=TRUE),
nrow=4,ncol=4)
library(Matrix)
xxxxxxxxxx
%%r
c(det(A),det(B),det(C))
xxxxxxxxxx
pretty_print('A.det()=A.T.det(): '+\
str(A.det()==A.T.det()))
pretty_print('(A*B).det()=(B*A).det()=A.det()*B.det(): '+\
str((A*B).det()==(B*A).det()==A.det()*B.det()))
pretty_print('(-2*A).det()=(-2)^A.dimensions()[0]*A.det(): '+\
str((-2*A).det()==(-2)^A.dimensions()[0]*A.det()))
# linear dependence
[matrix([[1,2,3],[0,0,0],[7,8,9]]).det(),
matrix([[1,2,3],[2,4,6],[7,8,9]]).det()]
xxxxxxxxxx
print(round(numpy.linalg.det(A1))==\
round(numpy.linalg.det(A1.T)),\
round(numpy.linalg.det(A1*B1))==\
round(numpy.linalg.det(B1*A1))==\
round(numpy.linalg.det(A1))*round(numpy.linalg.det(B1)),\
round(numpy.linalg.det(-2*A1))==\
-2**A2.shape[0]*round(numpy.linalg.det(A1)))
# linear dependence
round(numpy.linalg.det(numpy.matrix([[1,2,3],[0,0,0],[7,8,9]]))),\
round(numpy.linalg.det(numpy.matrix([[1,2,3],[2,4,6],[7,8,9]])))
xxxxxxxxxx
print([A2.det()==A2.T.det(),
(A2*B2).det()==(B2*A2).det()==A2.det()*B2.det(),
(-2*A2).det()==(-2)^A2.shape[0]*A2.det()])
# linear dependence
[sympy.Matrix([[1,2,3],[0,0,0],[7,8,9]]).det(),
sympy.Matrix([[1,2,3],[2,4,6],[7,8,9]]).det()]
xxxxxxxxxx
%%r
print(c(all.equal(det(A),det(t(A))),
all.equal(det(A%*%B),
det(B%*%A),det(A)*det(B)),
all.equal(det(-2*A),(-2)^(dim(A)[1])*det(A))))
# linear dependence
c(det(matrix(c(1,3,5,0,0,0,2,4,6),
nrow=3,ncol=3)),
det(matrix(c(1,3,5,2,6,10,2,4,6),
nrow=3,ncol=3)))
xxxxxxxxxx
%%html
$SIGN_{(3,3)} = \begin{pmatrix} + & - & + \\ - & + & -
\\ + & - & + \\ \end{pmatrix} \ \
SIGN_{(4,4)} = \begin{pmatrix} + & - & + & -
\\ - & + & - & + \\ + & - & + & - \\ - & + & - & + \end{pmatrix}$
xxxxxxxxxx
[M3.minors(2),M4.minors(3),
A.minors(2),B.minors(2),C.minors(3)]
xxxxxxxxxx
# разложение определителя по первому столбцу
M3.det()==M3[0,0]*M3.minors(2)[8]-\
M3[1,0]*M3.minors(2)[5]+M3[2,0]*M3.minors(2)[2]
xxxxxxxxxx
def minor(m,i,j):
return [row[:j]+row[j+1:] for row in (m[:i]+m[i+1:])]
def deternminant(m):
if len(m)==2:
return m[0][0]*m[1][1]-m[0][1]*m[1][0]
det=0
for c in range(len(m)):
det+=((-1)**c)*m[0][c]*deternminant(minor(m,0,c))
return det
[minor([[1,2,3],[-4,5,-6],[-7,8,-9]],1,1),
deternminant([[1,2,3],[-4,5,-6],[-7,8,-9]])]
xxxxxxxxxx
sympy.pprint(A2)
sympy.pprint(A2.minorMatrix(0,0))
xxxxxxxxxx
# разложение определителя по первому столбцу
B2.det()==B2[0,0]*B2.minorMatrix(0,0).det()-\
B2[1,0]*B2.minorMatrix(1,0).det()+\
B2[2,0]*B2.minorMatrix(2,0).det()
xxxxxxxxxx
%%r
minor_matrix<-function(A,i,j) A[-i,-j]
minor<-function(A,i,j) det(A[-i,-j])
cofactor<-function(A,i,j) (-1)^(i+j)*minor(A,i,j)
c(minor_matrix(A,1,2),minor(A,1,2),cofactor(A,1,2))
xxxxxxxxxx
%%r
c(det(A),
(A[1,1]*minor(A,1,1)-
A[2,1]*minor(A,2,1)+
A[3,1]*minor(A,3,1)))
xxxxxxxxxx
xxxxxxxxxx
import sympy,numpy,pylab
xxxxxxxxxx
%%r
xxxxxxxxxx