0

I have a function to plot along with its constraints

sum=0
  obj_fn <- function(x){
    for(i in 1:nrow(ldata)){
      for(j in 1:4){
        sum=sum+ldata[i,j]*x[j]*x[5]*d_km
      }
    }
    return(-sum)
  }

Constraints are

constraint1<-function(x){
    h <- numeric(5)
    h[1] <-  x[6]*x[1]-x[2] # r2>=fact*r1
    h[2] <- x[6]*x[2]-x[3]  # r3>=fact*r2
    h[3] <-  x[6]*x[3]-x[4] # r4>=fact*r3
    #h[4] <-  x[5]-1        # z<=1
    h[4] <-(-obj_fn(x) )-A1 # A2=A1
    h[5] <- A1-(-obj_fn(x) )
    #h[6] <- 1.5-x[6]        #fact>=1.5 here x[6] is the factor
    return(h)
  }

How can I plot as it is a huge function. Can anyone help me in this. Basically a 3D or a cotour plot is required to be produced

Prabhu
  • 87
  • 1
  • 10
  • I think this is a divide and conquer problem. Try to generate a vector for your first variable with your loop and your constraints inside checking then move to the next variable. BTW, Your constraints need a better explanation. – mccurcio Apr 22 '20 at 19:09
  • @oaxacamatt Can you clarify with little bit deeper explanation . If you want I can give you the constraints . – Prabhu Apr 23 '20 at 05:52
  • https://stackoverflow.com/questions/52917882/how-to-draw-a-three-dimensional-graph-in-r – mccurcio Apr 23 '20 at 17:07
  • Thanks@oaxacamat. Can you five some hint how to proceed in my function ? – Prabhu Apr 24 '20 at 03:02

0 Answers0