using Plots, ComplexPhasePortrait, ApproxFun, SingularIntegralEquations, DifferentialEquations, LinearAlgebra
gr();
Dr. Sheehan Olver
Use fundamental theorem of algebra: a polynomial is a constant times a product of terms like z−λk, where λk are the roots. In this case, the roots are a times the quartic-root of −1, hence this gives us: z4+a4=(z−aeiπ/4)(z−ae3iπ/4)(z−ae5iπ/4)(z−ae7iπ/4)
Let's check our work: we compare the numerically calculated residue to the formula we have derived:
a = 2.0
γ = Circle(a*exp(im*π/4), 0.1)
f = Fun(z -> z^3*sin(z)/(z^4+a^4), γ)
sum(f)/(2π*im), sin(a*exp(im*π/4))/4
(0.5378838853348212 + 0.07544036746694016im, 0.5378838853348215 + 0.0754403674669402im)
We have (z2−1)2=(z−1)2(z+1)2
We again check our work:
γ = Circle(1, 0.1)
f = Fun(z -> (z+1)/(z^2-1)^2, γ)
sum(f)/(2π*im) # almost equals -1/4
-0.2500000000000023 - 1.1916485920484316e-16im
We thus need only evaluate the extra term at z=a: Resz=az2ezz3−a3=ea3
Let's check:
a = 2.0
γ = Circle(a, 0.1)
f = Fun(z -> z^2*exp(z)/(z^3-a^3), γ)
sum(f)/(2π*im), exp(a)/3
(2.4630186996435506 + 4.738982805534393e-16im, 2.46301869964355)
θ = Fun(0 .. 2π)
sum(1/(5-4cos(θ))) -2π/3
8.881784197001252e-16
Use cos2θ=e2iθ+e−2iθ2=z2+z−22 to get ∫2π0cos2θdθ5+4cosθ=−i4∮(z4+1)dzz2(z+1/2)(z+2)=π2(Resz=−1/2+Resz=0)z4+1z2(z+2)(z+1/2)=π6
θ = Fun(0 .. 2π)
sum(cos(2θ)/(5-4cos(θ)))/π
0.1666666666666669
Because the integrand is analytic and O(z−2) in the upper half plane, we can use the residue theorem in the upper half plane using 1(z2+1)(z2+4)=1(z+i)(z−i)(z+2i)(z−2i)
This has two poles in the upper half plane:
phaseplot(-3..3, -3..4, z-> 1/((z^2+1)*(z^2+4)))
We can check the result numerically:
x = Fun( Line())
sum(1/((x^2+1)*(x^2+4)))
0.523598775598299
π/6
0.5235987755982988
Again, decays like O(z−2) in upper half plane so we can use residue calculus. This integrand has poles at z=i and z=3i:
phaseplot(-4..4, -4..4, z-> (z^2 - z + 2) / (z^4 + 10z^2 +9))
The residues are (−1−i)/16 and (3−7i)/48 giving the answer 5π12
Trick question: it's undefined because the integral doesn't decay fast enough. But what if I had asked for ∫−∞−∞1x+idx?
We can't use residue theorem since it doesn't decay fast enough, but we can use, with a contour CR={Reitheta:0≤θ≤π} ∮[−M,M]∪CR1z+i=0
Indeed:
x = Fun(-1000 .. 1000)
sum(1/(x+im))
-8.881784197001252e-16 - 3.13959265425659im
This can be deformed in the upper half plane with a pole at −1+i√32, using residue calculus gives us −2π√3sin1e√3
x = Fun(-100 .. 100)
sum(sin(2x)/(x^2+x+1))
-0.5400548830723747
-2π/sqrt(3) * sin(1)/exp(sqrt(3))
-0.5400553569742235
M = 200
x = Fun(-M .. M)
sum(cos(x)/(x^2+4)) # converges if we make M even bigger
0.21254026836702827
π/(2*exp(2))
0.21258416579381814
using Residue calculus. You need to appeal to Jordan's lemma to argue that it can still be done even with only O(x−1) decay.
M = 2000
x = Fun(-M .. M)
sum(x*sin(x)/(x^2+1)) # Converges if we make M even bigger
1.1560943440671996
π/ℯ
1.1557273497909217
We have for f(x)=eiax−eibxx2 ℜf(x)=cosax−cosbxx2
Note that, since cosx=1+x2/2+O(x4), the integrand is fine near zero: cosax−cosbxx2=(a−b)2+O(x2)
M = 10
ε = 1.0
plot(Segment(-M, -ε) ∪ Segment(ε, M);label="[-M,e] U [e,M]")
plot!(Arc(0.,ε, (π,0.)); label="C_e")
plot!(Arc(0., M, (0,π)); label = "C_M")
Note that ∮γf(z)dz=0, ∫Cϵeiaz−eibzz2dz=∫0π(b−a)eiθ+O(ϵ)eiθdθ→(a−b)π
ε =0.001
M = 600.0
x = Fun(Segment(-M , -ε) ∪ Segment(ε, M))
a = 2.3; b = 3.8
sum((cos(a*x) - cos(b*x))/x^2) # Converges if we make M bigger
4.703235784846408
π*(b-a)
4.71238898038469
Use binomial formula ∫2π0(cosθ)ndθ=12ni∮(z+z−1)ndzz=12nin∑k=0n!k!(n−k)!∮zkzk−ndzz=12nin∑k=0n!k!(n−k)!∮z2k−n−1dz
We only have a residue of 2k−n−1=−1, that is, if 2k=n. If n is odd, this can't happen (duh! the integral is symmetric with respect to θ). If it's even, then we have ∫2π0(cosθ)ndθ=π2n−1n!2(n/2)!
θ = Fun(0 .. 2π)
n = 4;
sum(cos(θ)^n)
2.356194490192353
π*factorial(1.0n)/(2^(n-1)*2*factorial(n/2))
2.356194490192345
By integrating around a rectangular contour with vertices at ±R and πi±R and letting R→∞, show that: ∫∞0sechxdx=π2
Recall sechx=2e−x+ex. This shows that sech(−x)=sechx But we also have sech(x+iπ)=2e−x−iπ+ex+iπ=2−e−x−ex=−sechx Thus we have 4∫∞0sechxdx=[∫∞−∞+∫−∞+iπ∞+iπ]sechzdz
We can approximate this using [∫R−R+∫R+iπR+∫−R+iπR+iπ+∫−R+iπ]sechzdz=2πiResz=iπ2sechz=2π
Finally, we need to show that the limit as R→∞ tends to the right value. In this case, it follows since |∫R+iπRsechzdz|≤2πe−R1−e−2R→0
Show that the Fourier transform of sechx satisfies ∫∞−∞eikxsechxdx=πsechπk2
Define f(z)=eikzsechz=2e(1+ik)ze2z+1
k = 2.0
f = z -> exp(im*k*z)*sech(z)
-exp(-k*π)f(2.0)
0.00032444937189257726 + 0.0003756543878221788im
f(2.0+im*π)
0.0003244493718925772 + 0.00037565438782217884im
In other words, we have (1+e−kπ)∫∞−∞f(x)dx=(∫∞−∞+∫−∞+iπ∞+iπ)f(z)dz
Again, the only pole inside is at z=iπ2, where the residue is −ie−πk2. Thus we have ∫∞−∞f(x)dx=2πe−πk21+e−kπ=πsechπk2
We have ρ(A)⊆B(1,3)∪B(2,3)∪B(4,1)
Here's a depiction:
drawdisk!(z0, R) = plot!(θ-> real(z0) + R[1]*cos(θ), θ-> imag(z0) + R[1]*sin(θ), 0, 2π, fill=(0,:red), α = 0.2, legend=false)
A = [1 2 -1; -2 2 1; 0 1 4]
λ = eigvals(A)
p = plot()
drawdisk!(1,3)
drawdisk!(2,3)
drawdisk!(4,1)
scatter!(complex.(λ); label="eigenvalues")
scatter!(complex.(diag(A)); label="diagonals")
p
λ = eigvals(A)
p = plot()
drawdisk!(1,2)
drawdisk!(2,3)
drawdisk!(4,2)
scatter!(complex.(λ); label="eigenvalues")
scatter!(complex.(diag(A)); label="diagonals")
p
Because the spectrum live in the intersection of the two estimates, the sharpest bound is ρ(A)⊆B(2,3)
λ = eigvals(A)
p = plot()
drawdisk!(2,3)
scatter!(complex.(λ); label="eigenvalues")
scatter!(complex.(diag(A)); label="diagonals")
p
Thus we can take 2+3eiθ as the contour.
Note that in the scalar case u″=au we have the solution u(t)=u0cosh√at+v0sinh√at√a
Here we verify the formulae numerically:
n = 5
A = randn(n,n)
A = A+ A' + 10I
λ, Q = eigen(A)
norm(A - Q*Diagonal(λ)*Q')
3.323277889766459e-14
Time-stepping solution:
u₀ = randn(n)
v₀ = randn(n)
uv = solve(ODEProblem((uv,_,t) -> [uv[n+1:end]; A*uv[1:n]], [u₀; v₀], (0.,2.)); reltol=1E-10);
t = 2.0
uv(t)[1:n]
5-element Array{Float64,1}: 431.3487825666393 842.6721648972994 -510.6730776173628 -1275.0672015889802 -852.8144701538115
Solution via diagonalization:
Q*Diagonal(cosh.(sqrt.(λ) .* t))*Q'*u₀ + Q*Diagonal(sinh.(sqrt.(λ) .* t) ./ sqrt.(λ))*Q'*v₀
5-element Array{Float64,1}: 431.34878253723247 842.672164825094 -510.67307756879427 -1275.0672015062562 -852.8144700629356
Solution via elliptic integrals. We chose the ellipse to surround all the spectrum of our particular A with eigenvalues:
periodic_rule(n) = 2π/n*(0:(n-1)), 2π/n*ones(n)
function ellipse_rule(n, a, b)
θ = periodic_rule(n)[1]
a*cos.(θ) + b*im*sin.(θ), 2π/n*(-a*sin.(θ) + im*b*cos.(θ))
end
function ellipse_f(f, A, n, z₀, a, b)
z,w = ellipse_rule(n,a,b)
z .+= z₀
ret = zero(A)
for j=1:n
ret += w[j]*f(z[j])*inv(z[j]*I - A)
end
ret/(2π*im)
end
n = 50
ellipse_f(z -> cosh(sqrt(z)*t), A, n, 10.0, 7.0, 2.0)*u₀ +
ellipse_f(z -> sinh(sqrt(z)*t)/sqrt(z), A, n, 10.0, 7.0, 2.0)*v₀
5-element Array{Complex{Float64},1}: 431.3489776293208 - 2.1947119676805203e-14im 842.6728232388965 - 8.751061717472864e-15im -510.67355346183 + 2.8015565557209588e-14im -1275.067724375493 - 6.622136600059223e-14im -852.8154291281783 + 2.365862961710633e-14im
I put the restriction in because of the √z term, which look like it is not analytic on (−∞,0]. However, this restriction was NOT necessary, since in fact cosh√zt and sinh√zt√z are entire:
phaseplot(-6..6, -3..3, z -> cosh(sqrt(z)))
phaseplot(-3..3, -3..3, z -> sinh(sqrt(z))/sqrt(z))
This follows from Taylor series, though I prefer the following argument: we have coshz=ez+e−z2
Here's a numerical example:
n = 5
A = randn(n,n)
λ, V = eigen(A)
norm(A - V*Diagonal(λ)*inv(V))
5.93500670014108e-15
u₀ = randn(n)
v₀ = randn(n)
uv = solve(ODEProblem((uv,_,t) -> [uv[n+1:end]; A*uv[1:n]], [u₀; v₀], (0.,2.)); reltol=1E-10);
t = 2.0
uv(t)[1:n]
5-element Array{Float64,1}: 3.803344206258081 0.9252585031733016 -1.193805803087017 5.72798765024654 1.7188451287601578
V*Diagonal(cosh.(sqrt.(λ) .* t))*inv(V)*u₀ +
V*Diagonal(sinh.(sqrt.(λ) .* t) ./ sqrt.(λ))*inv(V)*v₀
5-element Array{Complex{Float64},1}: 3.803344206066801 + 8.317464758586041e-16im 0.9252585029740441 + 2.2092966791530562e-16im -1.1938058030645906 + 9.308804664865466e-17im 5.727987650140507 + 7.402447551422406e-16im 1.7188451286631823 - 1.5268203762514324e-16im
Here's the solution using an elliptic integral:
n = 100
ellipse_f(z -> cosh(sqrt(z)*t), A, n, 0.0, 3.0, 3.0)*u₀ +
ellipse_f(z -> sinh(sqrt(z)*t)/sqrt(z), A, n, 0.0, 3.0, 3.0)*v₀
5-element Array{Complex{Float64},1}: 3.8033442060667997 - 1.0942835705045212e-16im 0.9252585029740352 + 2.0727119042774893e-16im -1.1938058030645888 - 2.8947259388740214e-16im 5.7279876501405145 - 1.9746496661590837e-16im 1.7188451286631805 + 8.925757831726994e-17im
We have 1nn−1∑j=0g(θj)=∞∑k=0gk1nn−1∑j=0eikθj
From lecture 4, we have |fk|≤Mrr−|k| for any 1≤r<R, where Mr is the supremum of f in an annulus {z:r−1<|z|<r}. Thus from the previous part we have (using geometric series) |1nn−1∑j=0g(θj)−12π∫2π0g(θ)dθ|≤∞∑K=1|fKn|+|f−Kn|≤2M∞∑K=1r−Kn=2Mrr−n1−r−n.
Note that f(z)=2z/(4z−z2−1) satisfies f(eiθ)=g(θ). This has two poles at 2±√3:
f = z -> 2z/(4z-z^2-1)
f(exp(0.1im)) - 1/(2-cos(0.1))
1.1102230246251565e-16 + 0.0im
Here's a phase plot showing the location of poles:
phaseplot(-5..5, -5..5, f)
2+sqrt(3), 2- sqrt(3), 1/(2+sqrt(3))
(3.732050807568877, 0.2679491924311228, 0.2679491924311227)
Note that 2+√3=1/(2−√3) so in the previous result, we take R=2+√3. For any 1≤r<2+√3 we have Mr=24−r−r−1
Thus we get the upper bounds 44−r−r−1r−n1−r−n
Let's see how sharp it is:
periodic_rule(n) = 2π/n*(0:(n-1)), 2π/n*ones(n)
g = θ -> 1/(2 - cos(θ))
Q = sum(Fun(g, 0 .. 2π))
err = Float64[ (
(θ, w) = periodic_rule(n);
sum(w.*g.(θ)) - Q
) for n=1:30];
N = length(err)
scatter(abs.(err), yscale=:log10, label="true error", title="Trapezium error bounds", legend=:bottomleft)
r = 1.1
scatter!(4/(4-r-inv(r)) .* r.^(-(1:N)) ./ (1 .- r.^(-(1:N))), label = "r = $r")
r = 3.0
scatter!(4/(4-r-inv(r)) .* r.^(-(1:N)) ./ (1 .- r.^(-(1:N))), label = "r = $r")
r = 2+sqrt(3) - 0.01
scatter!(4/(4-r-inv(r)) .* r.^(-(1:N)) ./ (1 .- r.^(-(1:N))), label = "r = $r")