The horizontal concatenation of expressions. This is equivalent to cbind when applied to objects with the same number of rows.

hstack(...)

Arguments

...

Expression objects, vectors, or matrices. All arguments must have the same number of rows.

Value

An Expression representing the concatenated inputs.

Examples

x <- Variable(2)
y <- Variable(3)
c <- matrix(1, nrow = 1, ncol = 5)
prob <- Problem(Minimize(c %*% t(hstack(t(x), t(y)))), list(x == c(1,2), y == c(3,4,5)))
result <- solve(prob)
result$value
#> [1] 15

c <- matrix(1, nrow = 1, ncol = 4)
prob <- Problem(Minimize(c %*% t(hstack(t(x), t(x)))), list(x == c(1,2)))
result <- solve(prob)
result$value
#> [1] 6

A <- Variable(2,2)
C <- Variable(3,2)
c <- matrix(1, nrow = 2, ncol = 2)
prob <- Problem(Minimize(sum_entries(hstack(t(A), t(C)))), list(A >= 2*c, C == -2))
result <- solve(prob)
result$value
#> [1] -4
result$getValue(A)
#>      [,1] [,2]
#> [1,]    2    2
#> [2,]    2    2

D <- Variable(3,3)
expr <- hstack(C, D)
obj <- expr[1,2] + sum(hstack(expr, expr))
constr <- list(C >= 0, D >= 0, D[1,1] == 2, C[1,2] == 3)
prob <- Problem(Minimize(obj), constr)
result <- solve(prob)
result$value
#> [1] 13
result$getValue(C)
#>              [,1]         [,2]
#> [1,] 6.665644e-31 3.000000e+00
#> [2,] 6.665644e-31 6.665644e-31
#> [3,] 6.665644e-31 6.665644e-31
result$getValue(D)
#>              [,1]         [,2]         [,3]
#> [1,] 2.000000e+00 6.665644e-31 6.665644e-31
#> [2,] 6.665644e-31 6.665644e-31 6.665644e-31
#> [3,] 6.665644e-31 6.665644e-31 6.665644e-31