Skip to content

Commit 26fac4b

Browse files
New example: inverse eigenvalue problem
1 parent b519a2b commit 26fac4b

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

Extras/Inverse eigenvalue problem.jl

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using ApproxFun, LinearAlgebra, DualNumbers
2+
import ApproxFun: bandwidth
3+
4+
#
5+
# Consider the following Sturm--Liouville problem with polynomial p, q, and w.
6+
#
7+
# [(-𝒟)(p𝒟) + q] u = λ w u, (u±bu')(±1) = 0.
8+
#
9+
# For which value of b, the Neumann part of the Robin boundary conditions,
10+
# is λ₀ equal to 1?
11+
#
12+
# To answer this question, we use a dual number to observe the sensitivity in λ₀
13+
# with respect to perturbations in b. The `realpart` of the objective function
14+
#
15+
# f(λ) = λ - 1,
16+
#
17+
# extracts the difference, whereas the `dualpart` evaluates to f'(λ).
18+
#
19+
20+
n = 100
21+
λ = dual(0.0,0.0)
22+
b = dual(eps(), 1.0)
23+
v = zeros(Dual{Float64}, n)
24+
v[1] = 1
25+
v .+= 0.003.*randn(Float64, n)
26+
for _ in 1:8
27+
d = Segment(-1..1)
28+
S = Ultraspherical(0.5, d)
29+
NS = NormalizedPolynomialSpace(S)
30+
D = Derivative(S)
31+
p = Fun(x->1+x^2, S)
32+
q = Fun(x->x^3, S)
33+
L = -D*(p*D)+q
34+
w = Fun(x->1+x/4, S)
35+
M = Multiplication(w, S)
36+
C = Conversion(domainspace(L), rangespace(L))
37+
B = [Evaluation(S, -1, 0) - b*Evaluation(S, -1, 1); Evaluation(S, 1, 0) + b*Evaluation(S, 1, 1)]
38+
QS = QuotientSpace(B)
39+
Q = Conversion(QS, S)
40+
D1 = Conversion(S, NS)
41+
D2 = Conversion(NS, S)
42+
R = D1*Q
43+
P = cache(PartialInverseOperator(C, (0, bandwidth(L, 1) + bandwidth(R, 1) + bandwidth(C, 2))))
44+
A = R'D1*P*L*D2*R
45+
B = R'D1*M*D2*R
46+
SA = Symmetric(A[1:n,1:n], :L)
47+
SB = Symmetric(B[1:n,1:n], :L)
48+
for _ = 1:7
49+
global λ = dot(v, SA*v)/dot(v, SB*v)
50+
ldiv!(ldlt!(SA-λ*SB), v)
51+
global v = v/norm(v)
52+
println("\tThis is λ: ", λ)
53+
end
54+
global b -= (realpart(λ)-1)/dualpart(λ)
55+
println("This is b: ", b)
56+
end

0 commit comments

Comments
 (0)