在这次作业中,我已经完成了除这道题外的所有问题。我必须创建一个 python 脚本来求解方程(屏幕截图)。
不幸的是,在我对整个互联网的研究中,我无法弄清楚世界上如何将 ln 转换为日志或任何可用的东西,或任何东西。到目前为止我写的代码如下。我也会贴出我们老师说我们应该得到的答案。
import math
p = 100
r = 0.06 / 12
FV = 4000
n = str(ln * ((1 + (FV * r) / p) / (ln * (1 + r))))
print ("Number of periods = " + str(n))
我应该得到的答案是 36.55539635919235 如果您有任何建议或帮助,我们将不胜感激!
另外,我们没有使用 numpy。我已经尝试过了。
谢谢!
最佳答案
math.log
是自然对数:
math.log(x[, base]) With one argument, return the natural logarithm of x (to base e).
因此你的等式是:
n = math.log((1 + (FV * r) / p) / math.log(1 + r)))
请注意,在您的代码中,您将 n 转换为 str
两次,这是不必要的
关于python - Python 中的 ln(自然对数),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39235906/