数学公式:
  

代码:
# 逆序数
def getInversion(numlist):
count = 0
for i in range(1,len(numlist)):
subscript = numlist[i]
for j in range(i):
if subscript < numlist[j]:
count += 1
return count
D = 0
# 全排列,求每项的积
def permutation(dd,ilist,jlist,index):
global D
for i in range(index,len(jlist)):
if index == len(jlist)-1:
term = 1
for ii in range(len(ilist)):
i = ilist[ii]
j = jlist[ii]
term *= dd[i][j]
if getInversion(jlist) % 2 == 0:
D += term
else:D -= term
return
tmp = jlist[index]
jlist[index] = jlist[i]
jlist[i] = tmp
permutation(dd,ilist,jlist,index+1)
tmp = jlist[index]
jlist[index] = jlist[i]
jlist[i] = tmp if __name__ == '__main__':
dd = [[1, 2, -4], [-2, 2, 1], [-3, 4, -2]]
dd =[[1,1,1,1],[-1,2,1,3],[1,4,1,9],[-1,8,1,27]]
jlist = []
ilist = []
for ii in range(len(dd)):
ilist.append(ii)
jlist.append(ii)
permutation(dd,ilist,jlist,0)
print(D)

  

Python实现行列式计算的更多相关文章

  1. 行列式计算(C#)

    最近几天学习高等代数老师说要写个程序算行列式的结果,闲来无事就简单写了一下. 不多说了,上代码 using System; using System.Collections.Generic; usin ...

  2. 使用python做科学计算

    这里总结一个guide,主要针对刚开始做数据挖掘和数据分析的同学 说道统计分析工具你一定想到像excel,spss,sas,matlab以及R语言.R语言是这里面比较火的,它的强项是强大的绘图功能以及 ...

  3. n阶行列式计算----c语言实现(完结)

    花了半天时间,写了这个n阶行列式计算的程序,应该算是比较优美吧,有很多地方多次做了优化,程序占用内存不是很大,要是说小吧,也不合适,因为里边有一个递归,而且递归的深度还比较深.时间复杂度具体没有细看, ...

  4. 使用Python做科学计算初探

    今天在搞定Django框架的blog搭建后,尝试一下python的科学计算能力. python的科学计算有三剑客:numpy,scipy,matplotlib. numpy负责数值计算,矩阵操作等: ...

  5. 使用Python做科学计算初探(转)

    今天在搞定Django框架的blog搭建后,尝试一下python的科学计算能力. python的科学计算有三剑客:numpy,scipy,matplotlib. numpy负责数值计算,矩阵操作等: ...

  6. MyMathLib系列(行列式计算)

    靠人不如靠己,准备做自己得MathLib,在学校的时候,就想过把数学数理的东西都计算机化.但一直没有时间去做这件事情,如今认为空余 时间比較闲,就做做这件事情,先从线性代数開始,毕竟这里面的非常多算法 ...

  7. windows下如何快速优雅的使用python的科学计算库?

    Python是一种强大的编程语言,其提供了很多用于科学计算的模块,常见的包括numpy.scipy.pandas和matplotlib.要利用Python进行科学计算,就需要一一安装所需的模块,而这些 ...

  8. Python之字符串计算(计算器)

    Python之字符串计算(计算器) import re expression = '-1-2*((60+2*(-3-40.0+42425/5)*(9-2*5/3+357/553/3*99/4*2998 ...

  9. MyMathLib系列(行列式计算2)

    /// <summary> /// 行列式计算,本程序属于MyMathLib的一部分.欢迎使用,參考,提意见. /// 有时间用函数语言改写,做自己得MathLib,里面的算法经过验证,但 ...

随机推荐

  1. Alternatives to Activiti for all platforms with any license

    Activiti Activiti is a light-weight workflow and Business Process Management (BPM) Platform targeted ...

  2. layer.msg 弹出不同的效果的样式

    icon 1到6的不同效果 layer.msg(,time:, shift: });//一个勾 layer.msg(,time:, shift: });//一个叉 layer.msg(,time:, ...

  3. Python“文件操作”Excel篇(上)

    大家好,我们今天来一起探索一下用Python怎么操作Excel文件.与word文件的操作库python-docx类似,Python也有专门的库为Excel文件的操作提供支持,这些库包括xlrd.xlw ...

  4. SeetaFace2 cmake VS2015编译编译

    cmake Selecting Windows SDK version 10.0.17134.0 to target Windows 10.0.18362. == BUILD_VERSION: v2. ...

  5. SFTP服务配置以及命令/代码操作

    POM <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.or ...

  6. 【源码解析】Flink 是如何基于事件时间生成Timestamp和Watermark

    生成Timestamp和Watermark 的三个重载方法介绍可参见上一篇博客: Flink assignAscendingTimestamps 生成水印的三个重载方法 之前想研究下Flink是怎么处 ...

  7. social engineering toolkit

    1. freebuf介绍 http://www.freebuf.com/sectool/73409.html 2. github https://github.com/trustedsec/socia ...

  8. 修复ubuntu 安装mysql后必须使用sudo问题

    修改root用户 查看用户的权限,是否是mysql_native_password,如果不是,则将auth_sock改为mysql_native_password update user set pl ...

  9. 软件素材--c/c++干掉代码的通用方法

    while(1) { sleep(200); } #endif

  10. LeetCode 589. N叉树的前序遍历(N-ary Tree Preorder Traversal)

    589. N叉树的前序遍历 589. N-ary Tree Preorder Traversal LeetCode589. N-ary Tree Preorder Traversal 题目描述 给定一 ...