1 core.matrices.QuadraticForm

core.matrices.QuadraticForm(vector, matrix)

Quadratic form: x’ @ Q @ x where Q is a constant matrix.

This represents the scalar expression xᵀQx, commonly used for: - Portfolio variance: w’ @ Σ @ w - Regularization terms: x’ @ I @ x = ||x||² - Quadratic objectives in optimization

1.1 Parameters

Name Type Description Default
vector VectorVariable | VectorExpression VectorVariable or VectorExpression (the x). required
matrix np.ndarray 2D NumPy array (the Q matrix, should be square). required

1.2 Example

import numpy as np Q = np.array([[1, 0.5], [0.5, 2]]) x = VectorVariable(“x”, 2) qf = QuadraticForm(x, Q) qf.evaluate({“x[0]”: 1, “x[1]”: 1}) 4.0 # 11 + 20.511 + 2*1 = 1 + 1 + 2 = 4

1.3 Methods

Name Description
evaluate Evaluate the quadratic form xᵀQx.
get_variables Return all variables this expression depends on.

1.3.1 evaluate

core.matrices.QuadraticForm.evaluate(values)

Evaluate the quadratic form xᵀQx.

1.3.2 get_variables

core.matrices.QuadraticForm.get_variables()

Return all variables this expression depends on.