Learn R Programming

CVXR (version 1.0-14)

vec: Vectorization of a Matrix

Description

Flattens a matrix into a vector in column-major order.

Usage

vec(X)

Value

An Expression representing the vectorized matrix.

Arguments

X

An Expression or matrix.

Examples

Run this code
A <- Variable(2,2)
c <- 1:4
expr <- vec(A)
obj <- Minimize(t(expr) %*% c)
constraints <- list(A == cbind(c(-1,-2), c(3,4)))
prob <- Problem(obj, constraints)
result <- solve(prob)
result$value
result$getValue(expr)

Run the code above in your browser using DataLab