Skip to content

Commit 0d9f684

Browse files
committed
add examples
1 parent d526c20 commit 0d9f684

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

README.md

+19
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ The `LinearMap` object combines well with methods of the following packages:
287287
using LinearMaps
288288
import Arpack, IterativeSolvers, TSVD
289289

290+
# Example 1, 1-dimensional Laplacian with periodic boundary conditions
290291
function leftdiff!(y::AbstractVector, x::AbstractVector) # left difference assuming periodic boundary conditions
291292
N = length(x)
292293
length(y) == N || throw(DimensionMismatch())
@@ -313,4 +314,22 @@ Arpack.svds(D; nsv=3)
313314
Σ, L = IterativeSolvers.svdl(D; nsv=3)
314315

315316
TSVD.tsvd(D, 3)
317+
318+
# Example 2, 1-dimensional Laplacian
319+
A = LinearMap(100; issymmetric=true, ismutating=true) do C, B
320+
C[1] = -2B[1] + B[2]
321+
for i in 2:length(B)-1
322+
C[i] = B[i-1] - 2B[i] + B[i+1]
323+
end
324+
C[end] = B[end-1] - 2B[end]
325+
return C
326+
end
327+
328+
Arpack.eigs(-A; nev=3, which=:SR)
329+
330+
# Example 3, 2-dimensional Laplacian
331+
Δ = kronsum(A, A)
332+
333+
Arpack.eigs(Δ; nev=3, which=:LR)
334+
eigsolve(x -> Δ*x, size(Δ, 1), 3, :LR)
316335
```

0 commit comments

Comments
 (0)