@@ -4,49 +4,54 @@ using Test
4
4
@testset " LinearSolve.jl" begin
5
5
using LinearAlgebra
6
6
n = 100
7
- x = Array (range (start= - 1 ,stop= 1 ,length= n))
8
- uu= @. sin (pi * x)
9
-
10
7
dx = 2 / (n- 1 )
11
8
12
- AA = Tridiagonal (ones (n- 1 ),- 2 ones (n),ones (n- 1 ))/ (dx* dx)
13
- bb = @. - (pi ^ 2 )* uu
9
+ xx = Array (range (start= - 1 ,stop= 1 ,length= n))
10
+ AA = Tridiagonal (ones (n- 1 ),- 2 ones (n),ones (n- 1 ))/ (dx* dx) # rank-deficient sys
11
+ uu = @. sin (pi * xx)
12
+ bb = AA * uu # @. -(pi^2)*uu
13
+
14
14
id = Matrix (I,n,n)
15
15
R = id[2 : end - 1 ,:]
16
16
17
- A = R * AA * R'
17
+ x = R * xx
18
+ A = R * AA * R' # full rank system
18
19
u = R * uu
19
20
b = A * u # R * bb
20
21
21
- @test isapprox (A* u,b;atol= 1e-2 )
22
- prob = LinearProblem (A, b)
23
-
24
- x = zero (b)
22
+ x = zero (b)
23
+ prob = LinearProblem (A, b;u0= x)
25
24
26
25
# Factorization
27
- @test A * solve (prob, LUFactorization ();) ≈ b
28
- @test A * solve (prob, QRFactorization ();) ≈ b
29
- @test A * solve (prob, SVDFactorization ();) ≈ b
30
-
31
- # Krylov
32
- @test A * solve (prob, KrylovJL (A, b)) ≈ b
33
-
34
- # make algorithm callable - interoperable with DiffEq ecosystem
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
39
-
40
- # in place
41
- LUFactorization ()(x,A,b)
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
26
+ for alg in (:LUFactorization , :QRFactorization , :SVDFactorization ,
27
+ :KrylovJL )
28
+ @eval begin
29
+ @test $ A * solve ($ prob, $ alg ();) ≈ $ b
30
+ $ alg ()($ x,$ A,$ b)
31
+ @test $ A * $ x ≈ $ b
32
+ end
33
+ end
49
34
50
35
# test on some ODEProblem
51
- # using OrdinaryDiffEq
36
+ using OrdinaryDiffEq
37
+ using DiffEqProblemLibrary. ODEProblemLibrary
38
+ ODEProblemLibrary. importodeproblems ()
39
+
40
+ # add this problem to DiffEqProblemLibrary
41
+ # kx = 1
42
+ # kt = 1
43
+ # ut(x,t) = sin(kx*pi*x)*cos(kt*pi*t)
44
+ # ic(x) = ut(x,0.0)
45
+ # f(x,t) = ut(x,t)*(kx*pi)^2 - sin(kx*pi*x)*sin(kt*pi*t)*(kt*pi)
46
+ # u0 = ic.(x)
47
+ # dudt!(du,u,p,t) = -A*u + f.(x,t)
48
+ # dt = 0.01
49
+ # tspn = (0.0,1.0)
50
+ # func = ODEFunction(dudt!)
51
+ # prob = ODEProblem(func,u0,tspn)
52
+
53
+ prob = ODEProblemLibrary. prob_ode_linear
54
+ sol = solve (prob, Rodas5 (linsolve= SVDFactorization ()); saveat= 0.1 )
55
+ @show sol. retcode
56
+
52
57
end
0 commit comments