eval_f0 <- function(x){
  x[1] <- t(t(as.array(unlist(x[1]))))
  return(t(x[1])%*%x[1])
}

eval_q0_1 <- function(x){
  return(c(-1*x[2],
           (trd %*% t(t(x[3]))-t(t(x[4]))%*%Price+x[1])-x[5],
           -1*x[5],
           x[2]-1))
}

eval_q0_2 <- function(x){
  return(c(Market.Share-x[2],
                 x[2]%*%(x[5]-(trd%*%x[3]-x[4]%*%Price+x[1])),
                 x[5]%*%(1-x[2])))
}

res1 <- nloptr( x0=list(rep(1, nrow(trd)), rep(1, nrow(trd)), rep(1, ncol(trd)), 1, rep(1, nrow(trd))),
                eval_f=eval_f0,
                lb = c(matrix(0, nrow = nrow(trd), ncol = 1),
                       matrix(0, nrow = nrow(trd), ncol = 1),
                       matrix(0, nrow = ncol(trd), ncol = 1),
                       matrix(0, nrow = nrow(trd), ncol = 1),
                       matrix(0, nrow = nrow(trd), ncol = 1)),
                ub = c(matrix(Inf, nrow = nrow(trd), ncol = 1),
                       matrix(Inf, nrow = nrow(trd), ncol = 1),
                       matrix(Inf, nrow = ncol(trd), ncol = 1),
                       matrix(Inf, nrow = nrow(trd), ncol = 1),
                       matrix(Inf, nrow = nrow(trd), ncol = 1)),
                eval_g_ineq = eval_q0_1,
                eval_g_eq = eval_q0_2,
                opts = list("algorithm"="NLOPT_LD_SLSQP")
                )