@@ -2,12 +2,26 @@ using LinearSolve
2
2
using Test
3
3
4
4
@testset " LinearSolve.jl" begin
5
- n = 10
6
- A = rand (n, n)
7
- b = rand (n)
5
+ using LinearAlgebra
6
+ n = 100
7
+ x = Array (range (start= - 1 ,stop= 1 ,length= n))
8
+ uu= @. sin (pi * x)
9
+
10
+ dx = 2 / (n- 1 )
11
+
12
+ AA = Tridiagonal (ones (n- 1 ),- 2 ones (n),ones (n- 1 ))/ (dx* dx)
13
+ bb = @. - (pi ^ 2 )* uu
14
+ id = Matrix (I,n,n)
15
+ R = id[2 : end - 1 ,:]
16
+
17
+ A = R * AA * R'
18
+ u = R * uu
19
+ b = A * u # R * bb
20
+
21
+ @test isapprox (A* u,b;atol= 1e-2 )
8
22
prob = LinearProblem (A, b)
9
23
10
- x = rand (n )
24
+ x = zero (b )
11
25
12
26
# Factorization
13
27
@test A * solve (prob, LUFactorization ();) ≈ b
@@ -18,10 +32,21 @@ using Test
18
32
@test A * solve (prob, KrylovJL (A, b)) ≈ b
19
33
20
34
# make algorithm callable - interoperable with DiffEq ecosystem
21
- @test A * LUFactorization ()(x,A,b) ≈ b
22
- @test A * KrylovJL ()(x,A,b) ≈ b
35
+ @test A * LUFactorization ()(x,A,b) ≈ b
36
+ @test A * QRFactorization ()(x,A,b) ≈ b
37
+ @test A * SVDFactorization ()(x,A,b) ≈ b
38
+ @test A * KrylovJL ()(x,A,b) ≈ b
23
39
24
40
# in place
25
- KrylovJL ()(x,A,b)
41
+ LUFactorization ()(x,A,b)
26
42
@test A * x ≈ b
43
+ QRFactorization ()(x,A,b)
44
+ @test A * x ≈ b
45
+ SVDFactorization ()(x,A,b)
46
+ @test A * x ≈ b
47
+ KrylovJL ()(x,A,b)
48
+ @test A * x ≈ b
49
+
50
+ # test on some ODEProblem
51
+ # using OrdinaryDiffEq
27
52
end
0 commit comments