python - 如何最大化-log(x)曲线下的面积?

标签 python r python-2.7 equation logarithm

我正在尝试获取曲线下面积的 xy 坐标:y=-15.7log(x)+154.94 是最大值。我想用 R 或 Python 来计算这个。有人可以帮我找到它吗?

<小时/>

背景:我有销售 (y) 与价格 (x) 的数据点。我尝试在 R 中拟合一条对数曲线: lm(formula = y ~ log(x)) ,这给出了上面的方程。我正在努力增加收入,这是销售和价格的产物。因此曲线下的矩形面积应最大化。

最佳答案

R 解决方案

# objective function should be minimized
NegArea <- function (x) x * (15.7 * log(x) - 154.94)
# sketch this function: there is a minimum
curve(NegArea, from = 0, to = 10000)
# use optimize()
optimize(NegArea, c(4000, 8000))
<小时/>

解析解

一阶导数为:

15.7 + 15.7 * log(x) - 154.94

将其设置为零并解决它:

x = 7106.675

这与 R 结果一致。

关于python - 如何最大化-log(x)曲线下的面积?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43977734/

相关文章:

python - 修复由另一种语言引起的 Python Unicode 错误

Python-判断给定字符串是否只有 1 个字符重复的最有效方法是什么?

regex - R 语言 : remove first character if equal to quotation mark

r - R 建模中的数据整理

python - 如何使用 Python 获取某人的 Facebook ID?

python - 如何修复 "Could not find a version that satisfies the requirement install (from versions: ) No matching distribution found for install "错误

python - tanh 需要多少个 FLOP?

r - 使用 R 在 ggplot 中传递字符串变量 facet_wrap()

python - 在文件中要求输入使用带有文件内容的字符串

javascript - 用于解析工作时间字符串的正则表达式模式