From 4e5eb819488a23af86270bad0c2eb722aebe37ae Mon Sep 17 00:00:00 2001 From: Maxence Gollier Date: Sun, 21 Jul 2024 12:56:16 +0200 Subject: [PATCH] add qless tutorial --- docs/src/tutorials/qless.md | 58 +++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 docs/src/tutorials/qless.md diff --git a/docs/src/tutorials/qless.md b/docs/src/tutorials/qless.md new file mode 100644 index 0000000..08f6404 --- /dev/null +++ b/docs/src/tutorials/qless.md @@ -0,0 +1,58 @@ +```@example qless1 +using QRMumps, LinearAlgebra, SparseArrays, Printf + +irn = [1, 3, 5, 2, 3, 5, 1, 4, 4, 5, 2, 1, 3] +jcn = [1, 1, 1, 2, 3, 3, 4, 4, 5, 5, 6, 7, 7] +val = [1.0, 2.0, 3.0, 1.0, 1.0, 2.0, 4.0, 1.0, 5.0, 1.0, 3.0, 6.0, 1.0] + +A = sparse(irn, jcn, val, 5, 7) +b = [40.0, 10.0, 44.0, 98.0, 87.0] +y_star = [0.0, 1.0, 2.0, 3.0, 4.0] +y₁ = similar(b,7) +y₂ = similar(b) + +qrm_init() + +spmat = qrm_spmat_init(A) +spfct = qrm_spfct_init(spmat) +qrm_analyse!(spmat, spfct; transp='t') +qrm_set(spfct, "qrm_keeph", 0) +qrm_factorize!(spmat, spfct, transp='t') + +qrm_solve!(spfct, b, y₁; transp='t') +qrm_solve!(spfct, y₁, y₂; transp='n') + +error_norm = norm(y₂ - y_star) + +@printf("Error norm ‖y* - y‖ = %10.5e\n", error_norm) +``` + +```@example qless2 +using QRMumps, LinearAlgebra, SparseArrays, Printf + +irn = [1, 1, 1, 2, 3, 3, 4, 4, 5, 5, 6, 7, 7] +jcn = [1, 3, 5, 2, 3, 5, 1, 4, 4, 5, 2, 1, 3] +val = [1.0, 2.0, 3.0, 1.0, 1.0, 2.0, 4.0, 1.0, 3.0, 1.0, 3.0, 2.0, 1.0] + +A = sparse(irn, jcn, val, 7, 5) +b = [22.0, 2.0, 13.0, 8.0, 17.0, 6.0, 5.0] +x_star = [1.0, 2.0, 3.0, 4.0, 5.0] + +qrm_init() + +spmat = qrm_spmat_init(A) +spfct = qrm_spfct_init(spmat) + +qrm_set(spfct, "qrm_keeph", 0) + +qrm_analyse!(spmat, spfct) +qrm_factorize!(spmat, spfct) + +z = A'*b +x₁ = qrm_solve(spfct, z; transp = 't') +x₂ = qrm_solve(spfct, x₁; transp = 'n') + +error_norm = norm(x₂ - x_star) + +@printf("Error norm ‖x* - x‖ = %10.5e\n", error_norm) +``` \ No newline at end of file