matrix_frac | R Documentation |
tr(X^T P^{-1} X)
.
matrix_frac(X, P)
X |
An Expression or matrix. Must have the same number of rows as |
P |
An Expression or matrix. Must be an invertible square matrix. |
An Expression representing the matrix fraction evaluated at the input.
## Not run:
set.seed(192)
m <- 100
n <- 80
r <- 70
A <- matrix(stats::rnorm(m*n), nrow = m, ncol = n)
b <- matrix(stats::rnorm(m), nrow = m, ncol = 1)
G <- matrix(stats::rnorm(r*n), nrow = r, ncol = n)
h <- matrix(stats::rnorm(r), nrow = r, ncol = 1)
# ||Ax-b||^2 = x^T (A^T A) x - 2(A^T b)^T x + ||b||^2
P <- t(A) %*% A
q <- -2 * t(A) %*% b
r <- t(b) %*% b
Pinv <- base::solve(P)
x <- Variable(n)
obj <- matrix_frac(x, Pinv) + t(q) %*% x + r
constr <- list(G %*% x == h)
prob <- Problem(Minimize(obj), constr)
result <- solve(prob)
result$value
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.