我只是负责把代码从VB和C++翻译到python而已…
#!/usr/bin/env python
# -*- coding=gb2312 -*-
from __future__ import division #python除法纠正
from math import pi #导入圆周率π
print "传热学 例题4-4 数值算法计算器"
print
Theta= [] #定义θn数组
k = int(raw_input("请输入r2/r1的值(2,3,4):"))
N = int(raw_input("请输入节点数N的值:"))
m = int(raw_input("请输入参数m的值:"))
DeltaR = 1/(N-1) #定义ΔR
for i in range(1,N+1):
Theta.append(1) #将θn的初值全部取为1
print
print "初值条件设为1。"
print
for j in range(1,10000): #不设定稳定条件,直接算10000次
for i in range(1,N-1):
Rn = 1/(k-1)+i/(N-1) #定义Rn数
#迭代运算θ
Theta[i] = (2*Rn+DeltaR)/(4*Rn*(1+(DeltaR**2)*(m**2)))*Theta[i+1]+(2*Rn-DeltaR)/(4*Rn*(1+(DeltaR**2)*(m**2)))*Theta[i-1]
#因为python的数组Theta[0]是第一个,所以需要多算一个Theta[N-2]
Theta[N-2] = (2*Rn+DeltaR)/(4*Rn*