user-2147482565
user-2147482565

Reputation: 463

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 plot

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

Upvotes: 1

Views: 4023

Answers (1)

Carlos Santillan
Carlos Santillan

Reputation: 1087

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)

Upvotes: 4

Related Questions