optimize a function containing min(a,b) arguments

Dear community,
I am pretty new in R and due to the fact that I am totally desperate, I really hope someone has the time to help me to solve my problem:

I want to find the solution for the following equation, where lowercase variables are known and given as variables, uppercase (X) is the one i want to solve for:

0 = a/(Xb-min(c,bX)) - d

I thought it would be good to solve by finding the minimum of the RHS of the equation and translate the min() argument in inequality constraints as follows

min(a/(Xb-Y) - d)
s.t. Y-c =< 0, Y-b=<0,
b-Y) - d )=<0

I added the third inequality constraint because otherwise my initial function is not going to be equal to zero but highly negative.

It is probably a very easy equation to solve, and I might have done too many steps due to the fact that I am not a big programmer, but here is my code how I tried to solve it, whick gives me errors unfortunately:


myfun<- function(X,Y,a,b,d){
  return(a/(X*b-Y) - d)}

eval_g_ineq <- function(X,Y,a,b,c,d,){
  return(c(Y-c , Y-b, -(a/(X*b-Y) - d)))}

opts = list("algorithm"="NLOPT_LD_MMA",
            "xtol_rel"=1.0e-4) # here I dont know if I use the right algorithm but I got errors before alerady

#here comes my optimization function:

nloptr(x0=1, eval_f=myfun, eval_g_ineq = eval_g_ineq, lb=0, ub=Inf, opts=opts,
               a=100, b=20, c=30, d=1)

And here comes my error:

Error in .checkfunargs(eval_f, arglist, "eval_f") : eval_f requires argument 'Y' but this has not been passed to the 'nloptr' function.

I also tied to specify two optimization values (for X and Y) as x0=c(1,1), lb=c(0,0), ub=c(Inf,Inf) but it didn't work. Is any one out there that is so kind and could give me some hints? Many many thanks in advance!
Best, Hans

f(x) = y is the starting point for R problem solving.

f, x\ \& \ y are objects with different properties.

x is the object at hand, y is the object desired and f is the object that converts x to y.

x in the OP is a combination of elements a,\ X, \ b, \ c\ \&d. where X is presumably a variable and the others constants.

y is a return value, 0.

f is to be composed.

An initial ambiguity must be cured in this fragment, a/(X b What does the blank between Xandbsignify. For illustration, assume+ and formin(c,b X) assume,`

A auxiliary function

g <- function(a, X, b, c, d) a / (X * b - min(c, b, X)) - d

# let
a <- 2
X <- 3
b <- 4
c <- 5
d <- 6

g(a, X, b, c, d)
#> [1] -5.777778

Created on 2020-09-30 by the reprex package (v0.3.0.9001)

Therefore, find f(g(x)) = y , such that X \in x produces y = 0.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.