简体   繁体   中英

How to find upper and lower bounds of a function in R

I am wanting to try find the upper and lower bounds of a function in R.

I am trying to use the built in R function 'optimise', but the function tries to find where the function's tangent is zero. For instance, if you run the following code:

phi_function <- function(x) {
  return(((x^6)/8) - ((3*(x^2))/4))
}

lbound_ex <- -1.79550879355662
ubound_ex <- 0.168144378782495

LX_ex <- optimise(phi_function, interval = c(lbound_ex, ubound_ex), maximum = FALSE)$objective
UX_ex <- optimise(phi_function, interval = c(lbound_ex, ubound_ex), maximum = TRUE)$objective

curve(phi_function, from = lbound_ex, to = ubound_ex)
abline(v = lbound_ex)
abline(v = ubound_ex)
abline(h = LX_ex, col = 'red')
abline(h = UX_ex, col = 'red')
abline(h = phi_function(-1.79550879355662), col = 'green')

You get the following graph:

phi_function图

The red lines are the minimum and maximums given by the 'optimise' function and the green line is the upper bound of phi_function in the interval (lbound_ex, ubound_ex). Does anyone know how to find upper and lower bounds in R?

Thanks in advance for any help! Ryan

I don't think the green line represents a maximum (or minimum). They are defined as point where the slope of the tangent is 0, and the slope.

Your function is not unimodal (only one peak), and the max and min are outside your range.

The function optimize will search the upper and lower interval and look for maximum and minimums in the continuous function in the interval. If you extend your function you will find there is another maximum at (0,0)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM