ConjugateGradientMethod.cg!
— Methodcg!(x, A, b, [iterpart=1.0])
cg!(x, A, b, [iternum=size(A,1)])
Solves the least squares problem $\min\|Ax - b\|^2$ using conjugate gradient method. x
is used as an initial value and is replaced with the result.
iternum
specifies the number of iterations to stop after (minimum 1).
Examples
julia> x = zeros(2);
julia> cg!(x, [1 2; 3 4], [1, 2])
2-element Array{Float64,1}:
5.551115123125783e-17
0.5000000000000012
ConjugateGradientMethod.cg
— Methodcg(A, b, [iterpart=1.0])
cg(A, b, [iternum=size(A,1)])
Solves the least squares problem $\min\|Ax - b\|^2$ using conjugate gradient method. To use initial value see cg!
.
iternum
specifies the number of iterations to stop after (minimum 1). iterpart
= iternum
/ $size(A,1)$
Examples
julia> cg([1 2; 3 4], [1, 2])
2-element Array{Float64,1}:
5.551115123125783e-17
0.5000000000000012
ConjugateGradientMethod.checkdims
— MethodConjugateGradientMethod.checkdims(x, A, b)
checks if arguments have correct dimensions for cg method.
ConjugateGradientMethod.close!
— MethodConjugateGradientMethod.close!(x) = nothing
function that is called after arrays inside cg method are no longer needed.
can be redefined by user to free memory.
ConjugateGradientMethod.dot
— MethodConjugateGradientMethod.dot(x, y) = LinearAlgebra.dot(x, y)
dot product function, used in cg method.
ConjugateGradientMethod.mul!
— MethodConjugateGradientMethod.mul!(y, A, x) = LinearAlgebra.mul!(y, A, x)
matrix-vector multilpication function, used in cg method.
ConjugateGradientMethod.zerox
— MethodConjugateGradientMethod.zerox(length)
used in cg
function (not cg!
).
ConjugateGradientMethod.@cg
— Macro@cg [1.0] A \ b
Solves the least squares problem $\min\|Ax - b\|^2$ using conjugate gradient method.
Between @cg and rdiv call iterpart
can be specified.
Examples
julia> @cg [1 2; 3 4] \ [1, 2]
2-element Array{Float64,1}:
5.551115123125783e-17
0.5000000000000012
julia> @cg 0.5 [1 2; 3 4] \ [1, 2]
2-element Array{Float64,1}:
0.2343820224719101
0.33483146067415726