0

Say I have n linear equations of the form:

ax1 + bx2 + cx3 = y1 -ax1 + bx2 + cx3 = y2 -ax1 -bx2 + cx3 = y3

Here is n=3 and a,b,c are known and fixed.

I'm looking for the optimal values for x1,x2,x3 such that their ranges are within [-r,r] for some positive r and the sum sum(y1,y2,y3) is maximized.

Is there a package for R which can handle such optimization problems?

Juergen
  • 3,489
  • 6
  • 35
  • 59

1 Answers1

3

You can use the optim in R function for this purpose.

If you are trying to maximize sum(y1,y2,y3), this actually simplifies the problem to maximize (ax1 + bx2 + 3*cx3) such that x1,x2,x3 ∈ [-r,r]

You can use below code to find the optimal values. Note that the optim function minimizes by default, so I am returning the negative value of the sum in the function.

max_sum <- function(x){ 
  a <- 2; b<- -3; c<-2;
  y <- a*x[1]+b*x[2]+3*c*x[3]
  return( -1*y ) }

r <- 5
optim(par=c(0,0,0), max_sum,lower= (-1*r),upper = r)

$par
[1]  5 -5  5
ab90hi
  • 435
  • 1
  • 4
  • 11