Search code examples
pythonrpython-2.7equationlogarithm

How to maximize the area under -log(x) curve?


I'm trying to get the x and y coordinates for which the area under the curve: y=-15.7log(x)+154.94 is maximum. I would like to compute this in R or Python. Can someone please help me to find it?


Background: I have data points of sales (y) vs prices (x). I tried fitting a log curve in R: lm(formula = y ~ log(x)) which gave me the above equation. I'm trying to increase the revenue which is the product of sales and prices. Hence the rectangular area under the curve should be maximized.


Solution

  • R solution

    # 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))
    

    Analytical solution

    First derivative is:

    15.7 + 15.7 * log(x) - 154.94
    

    Set it to zero and solve it:

    x = 7106.675
    

    This agrees with R result.