lesson 22/11, heavy ball method not translated yet

This commit is contained in:
elvis
2023-11-25 20:16:56 +01:00
parent b1c433832f
commit f36dec52dd
5 changed files with 3506 additions and 10 deletions

View File

@ -95,22 +95,22 @@ end
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function genericquad(Q, q, x::Union{Nothing, Real})
function genericquad(Q, q, x::Union{Nothing, AbstractVecOrMat})
# generic quadratic function f(x) = x' * Q * x / 2 + q' * x
if x === nothing # informative call
if minimum(eigvals(Q)) > 1e-14
xStar = Q \ -q
v = 0.5 * xStar' * Q * xStar + q' * xStar
v = 0.5 * dot(xStar, Q * xStar) + dot(q, xStar)
else
v = -Inf
end
return (v, zeros(size(q)), zeros(size(Q)))
else
if size(x) (2, 1)
if size(x, 1) 2 || size(x, 2) 1
throw(ArgumentError("genericquad: x is of wrong size"))
end
v = 0.5 * x' * Q * x + q' * x # f(x)
v = 0.5 * dot(x, Q * x) + dot(q, x) # f(x)
return (v, Q * x + q, Q)
end
end # genericquad