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:
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