A quadratic form is a type of polynomial in many variables where all the terms have an exponent of two.
Definition of quadratic form : A quadratic form in variables is given by the expression . The quadratic form can also be expressed in terms of matrix vector product as where and . Obviously is a symmetric matrix.
Is matrix unique for the quadratic form? It seems to be yes.
Hypothesis
: Let
be a quadratic form with asymmmetric matrix
. Then
, where
The following Julia code tries to take out any exceptions to the hypothesis.
using Symbolics
@variables x y z
for i in 1:10
C = rand(1:10,3,3)
B = (A+A')/2
q = [x y z]*C*[x y z]'
eq = simplify(q[1],expand=true)
q1 = [x y z]*B*[x y z]'
eq1 = simplify(q1[1],expand=true)
println(isequal(eq,eq1)) # always true
end
Hypothesis seems to be true.
Let be the number of variables in a quadratic form . Then the number of terms in is . If is given then .
Julia function to calculate
given
can be f(p) = Int64(trunc((-1 + sqrt(1+8p))/2))
.
A quadratic expression is
Positive definite if .
Positive semi-definite if
Negative definite if .
Negative semi-definite if
Indefinite if , for some and , for some
Definiteness of a matrix can be characterized by eigen values of as
Positive definite if .
Positive semi-definite if .
Negative definite if .
Negative semi-definite if
Indefinite if , for some and , for some
The following code in Julia detemines the definiteness of a matrix
in terms of eigenvalues.
using LinearAlgebra
function getDefiniteness(A)
#@assert isequal(A,A') "Matrix is not symmetric"
ishermitian(A) || throw(ArgumentError("Matrix must be Hermitian"))
if isposdef(A)
return "Matrix is positive definite"
end
if isposdef(-A)
return "Matrix is negative definite"
end
#x,y = eigmin(A),eigmax(A)
z = eigvals(A)
x,y = z[1],z[end]
if iszero(x)
return "Matrix is positive semi definite"
end
if y > 0.0 && x < 0.0
return "Matrix is indefinite"
end
if iszero(y)
return "Matrix is negative semi definite"
end
#=
if x < 0 && y < 0 #all([x, y] .< 0)
return "Matrix is negative definite"
end
=#
end
A = rand(5,5)
A = (A+A')/2
A = [-1 0;0 -1.0]
getDefiniteness(A)
By diagonalizing the symmetric matrix associated with a quadratic form, it is possible to eliminate cross terms.
The Principal Axes Theorem is a mathematical concept related to quadratic forms, which states that a quadratic form given by can be diagonalized by an orthonormal set of eigenvectors of , which is called the set of principal axes. The theorem is based on the spectral theorem related to a symmetric matrix, which states that , where is a diagonal matrix containing the eigenvalues of in its diagonal and is the eigen matrix of . By substituting , the quadratic form can be expressed as , where are the eigenvalues of .
The minimum and maximum of a quadratic form subjected to the constraint can be calculated by principal axes theorem.
Let .
Minimum of is the minimum of eigenvalues of .
Maximum of
is the maximum of eigenvalues of
.
julia> using LinearAlgebra
julia> A = rand(1:10,4,4)
4×4 Matrix{Int64}:
5 6 2 7
9 8 5 4
2 7 5 10
9 10 8 2
julia> A = (A+A')/2
4×4 Matrix{Float64}:
5.0 7.5 2.0 8.0
7.5 8.0 6.0 7.0
2.0 6.0 5.0 9.0
8.0 7.0 9.0 2.0
julia> minim,maxim = eigmin(A),eigmax(A)
(-7.833772750196167, 25.006216466801746)
function eigminmax(H::Hermitian) #suggested by stevenj
T = hessenberg(H).H # real SymTridiagonal reduction
return eigmin(T), eigmax(T)
end
julia> A = Hermitian(rand(100,100));
julia> @btime a,b = eigminmax(A)
920.200 μs (32 allocations: 145.23 KiB)
(-5.668761039486605, 49.66411909262399)
julia> @btime x,y = eigmin(A),eigmax(A)
1.602 ms (25 allocations: 229.81 KiB)
(-5.668761039486608, 49.66411909262401)
Discussion here : https://discourse.julialang.org/t/exploring-quadratic-forms-with-julia/104138
Top comments (0)