Skip to content

Commit dd5bce3

Browse files
Create disk.jl
1 parent 12b6199 commit dd5bce3

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

examples/disk.jl

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#############
2+
# In this example, we explore integration of a harmonic function:
3+
#
4+
# f(x,y) = (x^2-y^2+1)/[(x^2-y^2+1)^2+(2xy+1)^2],
5+
#
6+
# over the unit disk. In this case, we know from complex analysis that the
7+
# integral of a holomorphic function is equal to π × f(0,0).
8+
# We analyze the function on an N×M tensor product grid defined by:
9+
#
10+
# rₙ = cos[(n+1/2)π/2N], for 0 ≤ n < N, and
11+
#
12+
# θₘ = 2π m/M, for 0 ≤ m < M;
13+
#
14+
# we convert the function samples to Chebyshev×Fourier coefficients using
15+
# `plan_disk_analysis`; and finally, we transform the Chebyshev×Fourier
16+
# coefficients to disk harmonic coefficients using `plan_disk2cxf`.
17+
#
18+
# For the storage pattern of the arrays, please consult the documentation.
19+
#############
20+
21+
using FastTransforms, LinearAlgebra
22+
23+
f = (x,y) -> (x^2-y^2+1)/((x^2-y^2+1)^2+(2x*y+1)^2)
24+
25+
N = 15
26+
M = 4N-3
27+
28+
r = [sinpi((N-n-0.5)/(2N)) for n in 0:N-1]
29+
θ = 2*(0:M-1)/M # mod π.
30+
31+
P = plan_disk2cxf(Float64, N)
32+
PA = plan_disk_analysis(Float64, N, M)
33+
34+
# On the mapped tensor product grid, our function samples are:
35+
F = [f(r*cospi(θ), r*sinpi(θ)) for r in r, θ in θ]
36+
37+
# Its Zernike coefficients are:
38+
U = P\(PA*F)
39+
40+
# The Zernike coefficients are useful for integration. The integral of f(x,y)
41+
# over the disk should be π/2 by harmonicity. The coefficient of Z_0^0
42+
# multiplied by √π is:
43+
U[1, 1]*sqrt(π)
44+
45+
# Using an orthonormal basis, the integral of [f(x,y)]^2 over the disk is
46+
# approximately the square of the 2-norm of the coefficients:
47+
norm(U)^2

0 commit comments

Comments
 (0)