0
您好我在本書中發現:在工程數值方法與Python模塊run_kut5,但該模塊,我需要模塊printSoln,書中所有提供。現在我編寫代碼,進行必要的行調整等等。代碼如下:printSoln模塊問題
# -*- coding: cp1250 -*-
## module printSoln
''' printSoln(X,Y,freq).
Prints X and Y returned from the differential
equation solvers using printput frequency ’freq’.
freq = n prints every nth step.
freq = 0 prints initial and final values only.
'''
def printSoln(X,Y,freq):
def printHead(n):
print "\n x ",
for i in range (n):
print " y[",i,"] ",
print
def printLine(x,y,n):
print "%13.4e"% x,f
for i in range (n):
print "%13.4e"% y[i],
print
m = len(Y)
try: n = len(Y[0])
except TypeError: n = 1
if freq == 0: freq = m
printHead(n)
for i in range(0,m,freq):
printLine(X[i],Y[i],n)
if i != m - 1: printLine(X[m - 1],Y[m - 1],n)
現在,當我運行它,它說:
line 24, in <module>
m = len(Y)
NameError: name 'Y' is not defined
但我從書cp'd:\所以,現在當我打電話的run_kut模塊我得到的同樣的錯誤,沒有爲Y printSoln定義...
我想摸不着頭腦,但我吸:(
幫助,請...
我做到了,起初有這個問題,但我做了所有正確的壓痕,現在我得到這樣的:\ – 2011-02-27 12:49:11