Learn R Programming

CVXR (version 0.99-7)

square: Square Function

Description

The elementwise square function. This is equivalent to power(x,2).

Usage

square(x)

Arguments

x

An '>Expression, vector, or matrix.

Value

An '>Expression representing the square of the input.

Examples

Run this code
# NOT RUN {
m <- 30
n <- 20
A <- matrix(stats::rnorm(m*n), nrow = m, ncol = n)
b <- matrix(stats::rnorm(m), nrow = m, ncol = 1)

x <- Variable(n)
obj <- Minimize(sum(square(A %*% x - b)))
constr <- list(0 <= x, x <= 1)
prob <- Problem(obj, constr)
result <- solve(prob)
result$value
result$getValue(x)
# }

Run the code above in your browser using DataLab