傳熱學第四版例題4-4數值演算法計算器
阿新 • • 發佈:2019-01-23
我只是負責把程式碼從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*(1+(DeltaR**2)*(m**2)))*Theta[N-1]+(2*Rn-DeltaR)/(4*Rn*(1+(DeltaR**2)*(m**2)))*Theta[N-3] Theta[N-1] = Theta[N-2] print def main(): #定義肋效率計算函式 s1 = 0 s2 = 0 for i in range(1,N+1): R = 1/(k-1)+i/(N-1) s1 = s1+R*DeltaR*Theta[i-1]*4*pi s2 = s2+R*DeltaR*4*pi Fi = s1/s2 print "解得肋效率為:",Fi main() print if len(raw_input("按回車鍵退出或直接關閉視窗…")) == 0: exit()