@@ -31,55 +31,44 @@ Now if you apply Jacobi iteration multiple times with the same matrix for just a
31
31
``` jldoctest
32
32
julia> using LinearAlgebra, SparseArrays, IterativeSolvers
33
33
34
- julia> A = sprand(10_000, 10_000, 10 / 10_000) + 20I ;
34
+ julia> A = spdiagm(-1 => -ones(3), 0 => 2*ones(4), 1 => -ones(3)) ;
35
35
36
- julia> b1 = rand(10_000) ;
36
+ julia> b1 = [1.0, 2, 3, 4] ;
37
37
38
- julia> b2 = rand(10_000) ;
38
+ julia> b2 = [-1.0, 1, -1, 1] ;
39
39
40
- julia> x = rand(10_000) ;
40
+ julia> x = [0.0, -1, 1, 0] ;
41
41
42
- julia> my_iterable = IterativeSolvers.jacobi_iterable(x, A, b1, maxiter = 4);
42
+ julia> my_iterable = IterativeSolvers.jacobi_iterable(x, A, b1, maxiter = 2);
43
+
44
+ julia> norm(b1 - A * x) / norm(b1)
45
+ 1.2909944487358056
43
46
44
47
julia> for item in my_iterable
45
48
println("Iteration for rhs 1")
46
49
end
47
50
Iteration for rhs 1
48
51
Iteration for rhs 1
49
- Iteration for rhs 1
50
- Iteration for rhs 1
51
52
52
- julia> relative_residual = norm(b1 - A * x) / norm(b1);
53
+ julia> norm(b1 - A * x) / norm(b1)
54
+ 0.8228507357554791
53
55
54
56
julia> # Copy the next right-hand side into the iterable
55
57
copyto!(my_iterable.b, b2);
56
58
59
+ julia> norm(b2 - A * x) / norm(b2)
60
+ 2.6368778887161235
61
+
57
62
julia> for item in my_iterable
58
63
println("Iteration for rhs 2")
59
64
end
60
65
Iteration for rhs 2
61
66
Iteration for rhs 2
62
- Iteration for rhs 2
63
- Iteration for rhs 2
64
67
65
- julia> relative_residual ≈ norm(b2 - A * x) / norm(b2)
66
- false
68
+ julia> norm(b2 - A * x) / norm(b2)
69
+ 1.610815496107484
67
70
```
68
71
69
- This would output:
70
-
71
- ```
72
- Iteration for rhs 1
73
- Iteration for rhs 1
74
- Iteration for rhs 1
75
- Iteration for rhs 1
76
- norm(b1 - A * x) / norm(b1) = 0.08388528015119746
77
- Iteration for rhs 2
78
- Iteration for rhs 2
79
- Iteration for rhs 2
80
- Iteration for rhs 2
81
- norm(b2 - A * x) / norm(b2) = 0.0003681972775644809
82
- ```
83
72
84
73
## Other use cases
85
74
Other use cases include:
0 commit comments