I'm trying to minimize the cost per action which is total spend/ total actions which equals to the below function with a few constraints.

CPA function:

'(a+b+c+d)/((consta+(Baln(a)))+ (constb+(Bbln(b)))+(constc+(Bcln(c)))+(constd+(Bdln(d)))'

where the unknown variables are a,b,c,d and const* stands for constant from a regressions and B* stand for coefficient from a regression (so they are values that I have).

Here is the simplified filled in function that I'm trying to minimize:

'(a+b+c+d)/ (((69.31*ln(a))+(14.885*ln(b))+(21.089*ln(c))+(9.934*ln(d))-(852.93))'

Constraints:

a+b+c+d>=0

a+b+c+d<=130000(total spend) a<=119000 (maxa) a>=272.56(mina) b<=11000(maxb) b>=2.04(minb) c<=2900(maxc) c>=408.16(minc) d<=136800(maxd) d>=55.02(mind)

I'm doing this using the constraints optimization function. My code is below:

' g<-function(a,b,c,d) { (a+b+c+d)/((consta+(Balog(a)))+ (constb+ (Bblog(b)))+ (constc+(Bclog(c)))+ (constd+(Bdlog(d)))) }

gr<-function(a,b,c,d) {

c((1/((consta+(Balog(a)))+ (constb+(Bblog(b)))+(constc+(Bclog(c)))+(constd+(Bdlog(d)))))-((Ba*(a+b+c+d))/(a*((consta+(Balog(a)))+ (constb+(Bblog(b)))+(constc+(Bclog(c)))+(constd+(Bdlog(d))))**2)),

(1/((consta+(Balog(a)))+ (constb+(Bblog(b)))+(constc+(Bclog(c)))+(constd+(Bdlog(d)))))-((Bb*(a+b+c+d))/(b*((consta+(Balog(a)))+ (constb+(Bblog(b)))+(constc+(Bclog(c)))+(constd+(Bdlog(d))))**2)),

(1/((consta+(Balog(a)))+ (constb+(Bblog(b)))+(constc+(Bclog(c)))+(constd+(Bdlog(d)))))-((Bc*(a+b+c+d))/(c*((consta+(Balog(a)))+ (constb+(Bblog(b)))+(constc+(Bclog(c)))+(constd+(Bdlog(d))))**2)),

(1/((consta+(Balog(a)))+ (constb+(Bblog(b)))+(constc+(Bclog(c)))+(constd+(Bdlog(d)))))-((Bd*(a+b+c+d))/(d*((consta+(Balog(a)))+ (constb+(Bblog(b)))+(constc+(Bclog(c)))+(constd+(Bdlog(d))))**2)))

}

A<-matrix(c(1,0,0,0,-1,0,0,0,0,1,0,0,0,-1,0,0,0,0,1,0,0,0,-1,0,0,0,0,1,0,0,0,-1,-1,-1,-1,-1,1,1,1,1),10,4)

B<- c(mina, -maxa, minb, -maxb, minc, -maxc, mind, -maxd,-totalspend, 0)

constrOptim(c(273,6,409,56),gr,NULL,A,B)'

When I run the optimization function, it states that the values are not in the interior of the feasible region(Error in constrOptim(c(273, 6, 409, 56), gr, NULL, A, B) : initial value is not in the interior of the feasible region). However, the starting values that I have inputted satisfy all of the function constraints. I also checked to make sure that my function, gradient function, Ui, and Ci are properly coded. Is my initial value not a feasible solution? Any help is appreciated.