我需要使用3個不同的目標函數(下面)和我定義的函數findLength來查找曲線長度。我通過它跑我不能得到任何數字誰能告訴我什麼是錯了,它這個代碼,我很新的蟒蛇,這是學校分配Python找到一條曲線長度
def showLength(targetFunc, minPoints, maxPoints):
while minPoints <= maxPoints:
x_ = (targetFunc(minPoints)[0][0])
y_ = (targetFunc(minPoints)[1])
length = findLength(x_, y_)
print('Length of the curve of the function %s ' % targetFunc.__name__)
print("#POINTS LENGTHS")
print(" %f %.4d" % (minPoints, length) )
minPoints = minPoints * 2
def findLength(xs,ys):
xVal = np.array(xs)
yVal = np.ndarray(ys)
length = np.sqrt((xVal - (xVal-1))**2 + (yVal - (yVal - 1))**2)
return length
def xSinx(numPoints):
MIN = -20
MAX = 20
xValues = np.linspace(MIN, MAX, numPoints)
yValues = xValues * np.sin(xValues)
return xValues, yValues
def halfCircle(numPoints):
MIN = -5
MAX = 5
xValues = np.linspace(MIN, MAX, numPoints)
yValues = np.sqrt(25 - xValues ** 2)
return xValues, yValues
def fractionalPowers(numPoints):
assert type(numPoints) is int and numPoints > 1, "invalid numPoints"
MIN = 0
MAX = 100
xValues = np.linspace(MIN, MAX, numPoints)
yValues = np.array(xValues**0.25 + (xValues**(1/3)) + np.sqrt(xValues))
return xValues, yValues
你所定義的功能,但你不執行它們。 – furas