感谢您查看我的问题。我写了一个函数
def find_term_derivative(term):
x , y = term
new_term = (y*x, y-1)
return new_term它本质上使用幂规则来求特定项的导数,所以当我想求x^3的导数时,输入是(1,3),输出是(3,2),表示3x^2。
我想将其应用于多参数函数,例如4x^3-3x返回12x^2-3
Input is [(4, 3), (-3, 1)] Output应为:[(12, 2), (-3, 0)]
我的函数只返回第一项,我想知道是否有人可以帮助解释为什么?
def find_derivative(function_terms):
for term in function_terms:
new_function = []
new_term = find_term_derivative(term)
new_function.append(new_term)
return new_function发布于 2019-06-19 18:05:39
def find_derivative(function_terms):
new_function = []
for term in function_terms:
new_term = find_term_derivative(term)
new_function.append(new_term)
return new_function由于您在forloop内部返回,因此您的函数将返回第一项。
https://stackoverflow.com/questions/56664998
复制相似问题