Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

diag

Matrix Diagonal


Description

Extracts the diagonal from a matrix or makes a vector into a diagonal matrix.

Usage

## S4 method for signature 'Expression'
diag(x = 1, nrow, ncol)

Arguments

x

An Expression, vector, or square matrix.

nrow, ncol

(Optional) Dimensions for the result when x is not a matrix.

Value

An Expression representing the diagonal vector or matrix.

Examples

C <- Variable(3,3)
obj <- Maximize(C[1,3])
constraints <- list(diag(C) == 1, C[1,2] == 0.6, C[2,3] == -0.3, C == Variable(3,3, PSD = TRUE))
prob <- Problem(obj, constraints)
result <- solve(prob)
result$value
result$getValue(C)

CVXR

Disciplined Convex Optimization

v1.0-10
Apache License 2.0 | file LICENSE
Authors
Anqi Fu [aut, cre], Balasubramanian Narasimhan [aut], David W Kang [aut], Steven Diamond [aut], John Miller [aut], Stephen Boyd [ctb], Paul Kunsberg Rosenfield [ctb]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.