📜  微分导数微分 - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:21.506000             🧑  作者: Mango

代码示例1
# function wrt to differentate
def cu(x):
    return x*x*x

# differentation function
# Slightly increase x and compute the result. 
# Then compute the ratio of change in result with change in x
def diff(fun, x):
    delta = 0.000000001
    y = fun(x)
    x1 = x+delta
    y1 = fun(x1)
    return (y1-y) / (x1-x)

# X^3 = 3X^2
diff(cu,2)
# >>12.0