python求n阶矩阵Hermite标准型阶梯矩阵加行列式

import math
line = int(input("矩阵有多少行:",))
row = int(input("矩阵列数:",))
c=1
while c<=line:
    exec("listx = input('第"+str(c)+"行:',)")
    exec("line"+str(c)+"=[]")
    list0 = listx.split(",")
    d = 0
    while d<=row-1:
        exec("line"+str(c)+"+= [int(list0["+str(d)+"])]")
        d+=1
    exec("print(line"+str(c)+")")
    c+=1
exchange = 0
L = 2;R = 0
while L <= row:
    try:
        exec("judgement = (line"+str(L-1)+"["+str(R)+"]==0)")
    except:
        break
    if judgement:
        a = L
        while a <= line+1-L :
            exec("number = line"+str(a)+"["+str(R)+"]")
            if number == 0:
                a += 1
            else:
                print("交换line"+str(L-1)+"和line"+str(a))
                exec("linex = line"+str(L-1))
                exec("liney = line"+str(a))
                exec("line"+str(L-1)+" = liney")
                exec("line"+str(a)+" = linex")
                a = 100;exchange+=1
        if a==100:
            pass
        elif a == line+2-L:
            R+=1
            print("      !!!!!!第"+str(R)+ "列全为零")
    else:
        i = L
        while i <= line:
            r = R
            try:
                exec("plus = -(line" + str(i)+"["+str(r)+"])/(line"+str(L-1)+"["+str(r)+"])")
            except:
                break
            print("plus: "+str(plus))
            while r <= row-1:
                exec("line"+str(i)+"["+str(r)+"]="+"line"+str(i)+"["+str(r)+"]+""line"+str(L-1)+"["+str(r)+"]*plus")
                exec("x=line"+str(i)+"["+str(r)+"]"+"-math.ceil(line"+str(i)+"["+str(r)+"])")
                exec("y=line"+str(i)+"["+str(r)+"]"+"-math.floor(line"+str(i)+"["+str(r)+"])")
                exe1 = (abs(x)<0.000000000001)
                exe2 = (abs(y)<0.000000000001)
                if exe1:
                    exec("line"+str(i)+"["+str(r)+"]=math.ceil(line"+str(i)+"["+str(r)+"])")
                elif exe2:
                    exec("line"+str(i)+"["+str(r)+"]=math.floor(line"+str(i)+"["+str(r)+"])")
                print("正在处理line"+str(i)+"["+str(r)+"]")    
                r+=1
            exec("print(line"+str(i)+")")
            i+=1
        print("                       ----第"+str(R+1)+"列处理完成")
        L+=1;R+=1
L=line;R=row-1
while L>=2:
    exec("exer=(line"+str(L)+"["+str(R)+"]==0)")
    if not exer:
        i=L
        while i>=2:
            exec("plus=-line"+str(i-1)+"["+str(R)+"]/line"+str(L)+"["+str(R)+"]")
            print("plus: "+str(plus))
            exec("line"+str(i-1)+"["+str(R)+"]=line"+str(i-1)+"["+str(R)+"]+"+"line"+str(L)+"["+str(R)+"]*plus")
            print("正在处理line"+str(i-1)+"["+str(R)+"]")
            exec("x=line"+str(i-1)+"["+str(R)+"]"+"-math.ceil(line"+str(i-1)+"["+str(R)+"])")
            exec("y=line"+str(i-1)+"["+str(R)+"]"+"-math.floor(line"+str(i-1)+"["+str(R)+"])")
            exe1 = (abs(x)<0.000000000001)
            exe2 = (abs(y)<0.000000000001)
            if exe1:
                exec("line"+str(i-1)+"["+str(R)+"]=math.ceil(line"+str(i-1)+"["+str(R)+"])")
            elif exe2:
                exec("line"+str(i-1)+"["+str(R)+"]=math.floor(line"+str(i-1)+"["+str(R)+"])")
            i-=1
        print("                       ----第"+str(R+1)+"列处理完成")
        L-=1;R-=1
    else:
        a=L-1
        while exer:
            exec("exer=(line"+str(a)+"["+str(R)+"]==0)")
            a-=1
        
        L = a
        
print()
print()
print()
print("Hermite:")
a=1        
while a<=row:
    exec("print(line"+str(a)+")")
    a+=1
print()
print("行列式: ",end = "")
a=1;A=1
while a<=row:
    exec("A=A*line"+str(a)+"["+str(a-1)+"]")
    a+=1
A=A*((-1)**exchange)
print(A)

好臃肿的代码

但是是线代作业无所谓啦

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值