using Krylov
using LinearAlgebra, Printf
m = 5
n = 8
λ = 1.0e-3
A = rand(m, n)
b = A * ones(n)
xy_exact = [A λ*I] \ b # In Julia, this is the min-norm solution!
(x, y, stats) = craig(A, b, λ=λ, atol=0.0, rtol=1.0e-20, verbose=1)
show(stats)
# Check that we have a minimum-norm solution.
# When λ > 0 we solve min ‖(x,s)‖ s.t. Ax + λs = b, and we get s = λy.
@printf("Primal feasibility: %7.1e\n", norm(b - A * x - λ^2 * y) / norm(b))
@printf("Dual feasibility: %7.1e\n", norm(x - A' * y) / norm(x))
@printf("Error in x: %7.1e\n", norm(x - xy_exact[1:n]) / norm(xy_exact[1:n]))
if λ > 0.0
@printf("Error in y: %7.1e\n", norm(λ * y - xy_exact[n+1:n+m]) / norm(xy_exact[n+1:n+m]))
end
CRAIG: system of 5 equations in 8 variables
k ‖r‖ ‖x‖ ‖A‖ κ(A) α β timer
0 8.51e+00 0.00e+00 0.00e+00 0.00e+00 ✗ ✗ ✗ ✗ ✗ ✗ ✗ ✗ 0.47s
1 1.95e-01 2.77e+00 3.08e+00 3.08e+00 3.1e+00 7.0e-02 0.89s
2 6.31e-02 2.77e+00 3.21e+00 4.54e+00 8.8e-01 2.9e-01 1.06s
3 4.53e-02 2.78e+00 3.34e+00 5.84e+00 7.5e-01 5.4e-01 1.06s
4 9.88e-03 2.78e+00 3.47e+00 7.19e+00 9.0e-01 2.0e-01 1.06s
5 5.32e-11 2.78e+00 3.60e+00 8.32e+00 9.7e-01 5.2e-09 1.06s
SimpleStats
niter: 5
solved: true
inconsistent: false
indefinite: false
residuals: []
Aresiduals: []
κ₂(A): []
timer: 1.06s
status: solution good enough for the tolerances given
Primal feasibility: 6.3e-12
Dual feasibility: 2.4e-16
Error in x: 6.2e-12
Error in y: 5.8e-12