You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Now if you apply Jacobi iteration multiple times with the same matrix for just a few iterations, it makes sense to initialize the iterable only once and reuse it afterwards:
30
30
31
-
```julia
32
-
A =sprand(10_000, 10_000, 10/10_000) +20I
33
-
b1 =rand(10_000)
34
-
b2 =rand(10_000)
35
-
x =rand(10_000)
31
+
```jldoctest
32
+
julia> using LinearAlgebra, SparseArrays, IterativeSolvers
36
33
37
-
my_iterable = IterativeSolvers.jacobi_iterable(x, A, b1, maxiter =4)
34
+
julia> A = sprand(10_000, 10_000, 10 / 10_000) + 20I;
38
35
39
-
for item in my_iterable
40
-
println("Iteration for rhs 1")
41
-
end
36
+
julia> b1 = rand(10_000);
42
37
43
-
@shownorm(b1 - A * x) /norm(b1)
38
+
julia> b2 = rand(10_000);
44
39
45
-
# Copy the next right-hand side into the iterable
46
-
copyto!(my_iterable.b, b2)
40
+
julia> x = rand(10_000);
47
41
48
-
for item in my_iterable
49
-
println("Iteration for rhs 2")
50
-
end
42
+
julia> my_iterable = IterativeSolvers.jacobi_iterable(x, A, b1, maxiter = 4);
43
+
44
+
julia> for item in my_iterable
45
+
println("Iteration for rhs 1")
46
+
end
47
+
Iteration for rhs 1
48
+
Iteration for rhs 1
49
+
Iteration for rhs 1
50
+
Iteration for rhs 1
51
+
52
+
julia> relative_residual = norm(b1 - A * x) / norm(b1);
53
+
54
+
julia> # Copy the next right-hand side into the iterable
55
+
copyto!(my_iterable.b, b2);
56
+
57
+
julia> for item in my_iterable
58
+
println("Iteration for rhs 2")
59
+
end
60
+
Iteration for rhs 2
61
+
Iteration for rhs 2
62
+
Iteration for rhs 2
63
+
Iteration for rhs 2
51
64
52
-
@shownorm(b2 - A * x) /norm(b2)
65
+
julia> relative_residual ≈ norm(b2 - A * x) / norm(b2)
0 commit comments