利用python实现利用追赶法解决线性方程组

追赶法
大二在读,能力有限,轻喷
python实现追赶法解方程组,通篇都是低级函数,适合初学者学习

jieshu=int(input(“矩阵的阶数:”))
print(“请输入a”)
a=[]
for i in range(jieshu-1):
x=float(input())
a.append(x)
print(“请输入b”)
b=[]
for i in range(jieshu):
x=float(input())
b.append(x)
print(“请输入c”)
c=[]
for i in range(jieshu-1):
x=float(input())
c.append(x)
print(“请输入f”)
f=[]
for i in range(jieshu):
x=float(input())
f.append(x)
beita=[]
arf=[]
y=[]
x=[]
for i in range(jieshu-1):
beita.append(0)
for i in range(jieshu):
arf.append(0)
for i in range(jieshu):
y.append(0)
for i in range(jieshu):
x.append(0)
for i in range(jieshu-1):

if i == 0:
beita[0]=c[0]/b[0]
else:

beita[i]=c[i]/(b[i]-a[i-1]*beita[i-1])
for i in range(jieshu):
if i==0:
y[0]=f[0]/b[0]
else:
y[i]=(f[i]-a[i-1]*y[i-1])/(b[i]-a[i-1]*beita[i-1])
for i in range(jieshu):
wuhu=jieshu-i
if wuhu==jieshu:
x[jieshu-1]=y[jieshu-1]
else:
x[wuhu-1]=y[wuhu-1]-beita[wuhu-1]*x[wuhu]
print(‘beita=’,beita)
print(‘y=’,y)
print(‘x=’,x)
for i in range(jieshu):
print(‘x’,i+1,’=’,x[i])