def mean_slope(f, a, b):
'''
Write a python function which returns the average slope of a function f within a range a and b.a < b
'''
print(mean_slope(some_func, 2, 8))如何编写python函数,它返回函数f在a和b.a
发布于 2022-04-21 06:50:30
这定义了一个函数mean_slope,给定一个变量f的函数,返回f在带a < b的区间[a, b]上的平均斜率。这是用函数square进行测试的。
def mean_slope(f, a, b):
"""
given a function of one variable f, returns average slope of f over
[a, b], a < b
"""
return (f(b) - f(a)) / (b - a)
def square(x):
return x * x
print(mean_slope(square, 2, 8))输出
10.0https://stackoverflow.com/questions/71948519
复制相似问题