Skip to content

Commit fb09670

Browse files
committed
Create vectoreigenproblem.jl
1 parent e018f60 commit fb09670

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

examples/vectoreigenproblem.jl

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using ClassicalOrthogonalPolynomials, Plots
2+
3+
#####
4+
# -u'' - a*w = λb*u
5+
# -w'' - u = λb*u
6+
# u(0) = 0
7+
# w(0) = 0
8+
# w'(1) + λ*w(1) + u(1)
9+
####
10+
11+
T = chebyshevt(0..1) # solution basis is T_n
12+
C = ultraspherical(2,0..1) # RHS basis is C_n^(2)
13+
z = axes(T,1)
14+
a = 1 .+ z
15+
b = z
16+
17+
n = 20
18+
= (C\diff(T,2))[1:n-2,1:n] # 2nd derivative discretisation
19+
A = (C\(a .* T))[1:n-2,1:n] # multiplication by a
20+
B = (C\(b .* T))[1:n-2,1:n] # multiplication by b
21+
R = (C\T)[1:n-2,1:n]
22+
23+
𝐞₀ = T[0, 1:n] # evaluate at 0
24+
𝐞₁ = T[1, 1:n] # evaluate at 1
25+
𝐝₁ = diff(T)[1,1:n] # evaluate derivative at 1
26+
𝐳 = zeros(n)
27+
Z = zeros(n-2,n)
28+
29+
bcs = [𝐞₀' 𝐳';
30+
𝐳' 𝐞₀';
31+
𝐞₁' 𝐝₁';
32+
𝐞₀' -𝐞₁']
33+
34+
35+
ops = [--A;
36+
-R -D²]
37+
38+
39+
M = [𝐳' 𝐳'; # first bc is zero
40+
𝐳' 𝐳'; # second bc is zero
41+
𝐳' 𝐞₁'; # 3rd bc is λ*w(1)
42+
𝐳' 𝐳'; # 4th bc is zero
43+
B Z; # λ*b *u
44+
Z B] # λ*b *w
45+
46+
47+
λ, 𝐮 = eigen([bcs; ops], M)
48+
49+
@test 8 real(λ[3]) 9 # a reasonable eigenvalue
50+
51+
u,w = T[:,1:n]*real(𝐮[:,3][1:n]), T[:,1:n]*real(𝐮[:,3][n+1:end])
52+
53+
plot(u); plot!(w)

0 commit comments

Comments
 (0)