Optimise a function with two parameters and constraints in R using solnp function?
问题 I have the following function and would like to optimise parameters x and y in order to maximise the output. I am trying to do that using optimise . EDIT Thanks to the comments here I am able to optimise using Rsolnp::solnp . But now I get error when I add upper and lower bounds. See example below Ojective function: my_fn <- function(x) { z <- ifelse(x[1] < 1000000, 0, ifelse(x[1] < 19500000, x[1] * 0.0175, ifelse(x[1] < 20500000, x[1] * 0.0190, ifelse(x[1] < 21500000, x[1] * 0.0220, ifelse(x