The quadratic form, \(x^TPx\).

quad_form(x, P)

Arguments

x

An Expression or vector.

P

An Expression or matrix.

Value

An Expression representing the quadratic form evaluated at the input.

Examples

x <- Variable(2)
P <- rbind(c(4,0), c(0,9))
prob <- Problem(Minimize(quad_form(x,P)), list(x >= 1))
result <- solve(prob)
result$value
#> [1] 13
result$getValue(x)
#>      [,1]
#> [1,]    1
#> [2,]    1

A <- Variable(2,2)
c <- c(1,2)
prob <- Problem(Minimize(quad_form(c,A)), list(A >= 1))
result <- solve(prob)
result$value
#> [1] 9
result$getValue(A)
#>      [,1] [,2]
#> [1,]    1    1
#> [2,]    1    1