"""Worked example with nonzero separation constants (Sec. 6, "Example: nonzero separation constants"). Region Omega = {nu > 0, mu < mu0} for b=3, c=1, mu0=6; V=0 on mu=mu0, V=V0 on nu=0 (Arscott 1963, Sec. 6). Checks, in the Moon--Spencer notation of the paper: 1. Arscott's map (1.1) reproduces eq. (mapping) under mu=b+(b-c)sinh^2(alpha), lambda=c+(b-c)cos^2(beta), nu=c-(b-c)sinh^2(gamma), (x,y,z)=(z_A, y_A, x_A+(b+c)/2), c_A=b-c [numerically, 30 digits]. 2. With s=c+(b-c)cos^2(theta) the unified equation becomes Mathieu's equation, a=4 alpha2-2 alpha3(b+c), q=alpha3(b-c) [symbolically]. 3. Roots q of Ce_2n(alpha0,q)=0 (Arscott (6.2)): (i) Fourier series with a from a continued fraction, (ii) direct integration of Arscott (4.2a,b) by mpmath's Taylor ODE solver (q_00 only). 4. Single-mode solution V = V0 F(mu)F(nu)F(lambda)/[F(b)F(0)F(c)]: Laplacian, V on mu0, axis values, smoothness. 5. First partial sums of the constant-data series (Arscott (6.5)-(6.10)) on the axis. Requires sympy and mpmath. Runs in about four minutes. """ import sympy as sp import mpmath as mp mp.mp.dps = 30 b, c, mu0 = mp.mpf(3), mp.mpf(1), mp.mpf(6) cA = b - c alpha0 = mp.asinh(mp.sqrt((mu0 - b)/cA)) def ok(name, err, tol): assert err < tol, (name, err); print(f'PASS: {name} (max error {mp.nstr(err, 3)})') # 1. dictionary rnd = mp.rand err = 0 for _ in range(20): al, be, ga = rnd()*1.5, (rnd()-0.5)*6, rnd()*1.5 xA = cA/2*(mp.cosh(2*al) + mp.cos(2*be) - mp.cosh(2*ga)) yA = 2*cA*mp.cosh(al)*mp.cos(be)*mp.sinh(ga); zA = 2*cA*mp.sinh(al)*mp.sin(be)*mp.cosh(ga) mu = b + cA*mp.sinh(al)**2; la = c + cA*mp.cos(be)**2; nu = c - cA*mp.sinh(ga)**2 X2 = 4*(mu-b)*(b-nu)*(b-la)/(b-c); Y2 = 4*(mu-c)*(c-nu)*(la-c)/(b-c); Z = mu+nu+la-b-c err = max(err, abs(X2 - zA**2), abs(Y2 - yA**2), abs(Z - xA - (b+c)/2)) ok('Arscott (1.1) = eq. (mapping) under the dictionary', err, mp.mpf(10)**-25) # 2. Mathieu reduction th, B, C, A2, A3 = sp.symbols('theta b c alpha2 alpha3', positive=True) f = sp.Function('f')(th); s = C + (B-C)*sp.cos(th)**2; ds = sp.diff(s, th) Fp = sp.diff(f, th)/ds; Fpp = sp.diff(Fp, th)/ds lhs = (s-B)*(s-C)*Fpp + sp.Rational(1, 2)*(2*s-B-C)*Fp + (A3*s - A2)*f mathieu = sp.diff(f, th, 2) + (4*A2 - 2*A3*(B+C) - 2*A3*(B-C)*sp.cos(2*th))*f assert sp.simplify(sp.expand_trig(sp.expand(-4*lhs - mathieu))) == 0 print('PASS: unified equation (k=0) = -(1/4) x Mathieu equation, a=4 alpha2-2 alpha3(b+c), q=alpha3(b-c)') # 3. roots def ce_coeffs(n2, q, N=60): """a_{n2}(q) from the continued fraction, A_{2r} by backward ratios; 2A0^2+sum A^2=1, ce(0)>0.""" q = mp.mpf(q) def ratios(a): v = mp.mpf(0); vs = {} for r in range(N, 1, -1): v = q/(a - 4*r*r - q*v); vs[r] = v return vs G = lambda a: a - 2*q*q/(a - 4 - q*ratios(a)[2]) guess = {0: -q/2 if q < 2 else -2*q + 2*mp.sqrt(q), 2: 4}[n2] if n2 in (0, 2) else n2**2 a = mp.findroot(G, guess) vs = ratios(a); A = [mp.mpf(1), 2*q/(a - 4 - q*vs[2])] for r in range(2, N+1): A.append(A[-1]*vs[r]) nrm = mp.sqrt(2*A[0]**2 + mp.fsum(t**2 for t in A[1:])); A = [t/nrm for t in A] if mp.fsum(A) < 0: A = [-t for t in A] return a, A Ce = lambda A, al: mp.fsum(A[r]*mp.cosh(2*r*al) for r in range(len(A))) def root(n2, guess): return mp.findroot(lambda q: Ce(ce_coeffs(n2, q)[1], alpha0), mp.mpf(guess)) REF = {(0, 0): '0.76972332982002', (0, 1): '4.48907139375517', (2, 0): '3.07050098196381'} # ODE shooting (double) Q = {k: root(k[0], v) for k, v in REF.items()} for k in Q: print(f' q_{k[0]},{k[1]} = {mp.nstr(Q[k], 20)}') ok('roots (6.2) by Fourier series agree with double-precision ODE shooting', max(abs(Q[k]-mp.mpf(v)) for k, v in REF.items()), 1e-12) # (ii) independent: shoot a with B'' + (a-2q cos2b)B = 0, B(0)=1, B'(0)=0, B'(pi/2)=0 (lowest), then A at alpha0 mp.mp.dps = 15 def shoot_a(q, a0): def Bp(a): sol = mp.odefun(lambda t, y: [y[1], -(a - 2*q*mp.cos(2*t))*y[0]], 0, [1, 0]); return sol(mp.pi/2)[1] return mp.findroot(Bp, a0) def A_alpha0(q): a = shoot_a(q, ce_coeffs(0, q)[0] + mp.mpf('0.01')) sol = mp.odefun(lambda t, y: [y[1], (a - 2*q*mp.cosh(2*t))*y[0]], 0, [1, 0]); return sol(alpha0)[0] q00_ode = mp.findroot(A_alpha0, Q[(0, 0)] + mp.mpf('0.001')) mp.mp.dps = 30 ok('q_00 by mpmath ODE shooting (no Fourier series)', abs(q00_ode - Q[(0, 0)]), 1e-10) # 4. single-mode solution. F(s) = sum A_2r T_r(2(s-c)/(b-c)-1) is entire, so V is a symmetric function of the # three roots of the confocal cubic, hence analytic in (x,y,z). q00 = Q[(0, 0)]; a00, A00 = ce_coeffs(0, q00, N=50) al3 = q00/cA; al2 = (a00 + 2*al3*(b+c))/4 print(f' a = {mp.nstr(a00, 15)}, alpha3 = {mp.nstr(al3, 15)}, alpha2 = {mp.nstr(al2, 15)}') F = lambda s: mp.fsum(A00[r]*mp.chebyt(r, 2*(s-c)/(b-c) - 1) for r in range(len(A00))) res = max(abs((s-b)*(s-c)*mp.diff(F, s, 2) + (2*s-b-c)/2*mp.diff(F, s) + (al3*s-al2)*F(s)) for s in (mp.mpf(-1), 2, 4, 6)) ok('F solves the unified equation with these alpha2, alpha3', res, 1e-20) def roots3(x, y, z): return mp.polyroots([4, -4*(z+b+c), 4*(z*b+z*c+b*c) - x**2 - y**2, -4*z*b*c + x**2*c + y**2*b], maxsteps=200, extraprec=60) norm = F(b)*F(0)*F(c) def V1(x, y, z): r = roots3(x, y, z); return mp.re(F(r[0])*F(r[1])*F(r[2]))/norm err = 0 for p in [(0.3, 0.2, 1.0), (1.0, -0.5, 2.5), (-2.0, 1.0, 3.5), (0.0, 0.0, 4.0), (0.5, 0.0, 3.0)]: lap = sum(mp.diff(V1, p, tuple(2 if k == j else 0 for k in range(3))) for j in range(3)); err = max(err, abs(lap)) ok('single mode: Cartesian Laplacian (incl. points on x=0 and y=0)', err, 1e-15) ok('single mode: V = 0 on mu = mu0 (Arscott (6.2))', abs(F(mu0)), 1e-20) PAPER_AXIS = {2: '0.5296034918', 4: '0.2077175586', 5: '0.0914804716'} # values quoted in the text ok('single mode on the axis: V/V0 = F(z)/F(0), values quoted in the text', max(max(abs(V1(0, 0, z) - F(z)/F(0)), abs(F(z)/F(0) - mp.mpf(v))) for z, v in PAPER_AXIS.items()), 1e-10) # smoothness across mu=b (x=0) and nu=c (y=0): V(x) - V(0) = O(x^2), not O(|x|) for p, k in [((0, 0.5, 1.0), 0), ((0, 0.5, 4.0), 0), ((0.5, 0, 0.5), 1), ((0.5, 0, 3.0), 1)]: r = [] for h in (mp.mpf('1e-3'), mp.mpf('1e-6')): q_ = list(map(mp.mpf, p)); q_[k] += h; r.append((V1(*q_) - V1(*p))/h**2) assert abs(r[0] - r[1]) < 1e-5, r print('PASS: single mode is O(h^2) across x=0 (mu=b and lambda=b charts) and y=0 (lambda=c and nu=c charts)') # 5. constant data: coefficients from Arscott (6.9) with the Green-identity numerator # int int u w = -(pi/q) A'(alpha0) A_0, w = cosh 2alpha - cos 2beta; axis values V(0,0,z) = sum c_k F_k(b)F_k(c)F_k(z)/F_k(0) mp.mp.dps = 25 modes = [(0, '0.76972332982002'), (2, '3.07050098196381'), (0, '4.48907139375517'), (4, '6.98380226098009'), (2, '8.50439109264880'), (0, '11.52841914045671'), (6, '12.21966661010451'), (4, '14.36502417891770'), (2, '17.32347629044788'), (8, '18.61145617761571'), (0, '21.86052168956306'), (6, '22.08980829113376'), (4, '24.76908024122514'), (10, '26.158330004397'), (2, '29.49095251672119')] # all 15 roots with q < 30 def ce_gen(n2, q, N=50): M = mp.zeros(N, N) for r in range(N): M[r, r] = (2*r)**2 if r+1 < N: M[r, r+1] = M[r+1, r] = q*(mp.sqrt(2) if r == 0 else 1) E, U = mp.eigsy(M); i = sorted(range(N), key=lambda j: E[j])[n2//2] A = [U[j, i] for j in range(N)]; A[0] /= mp.sqrt(2) if mp.fsum(A) < 0: A = [-t for t in A] return E[i], A tot = {1: 0, 3: 0, 5: 0} for n2, qs in modes: q = mp.findroot(lambda q: Ce(ce_gen(n2, q)[1], alpha0), mp.mpf(qs)) a, A = ce_gen(n2, q) Fk = lambda s: mp.fsum(A[r]*mp.chebyt(r, 2*(s-c)/(b-c) - 1) for r in range(len(A))) Ca = lambda t: Ce(A, t); Bf = lambda t: mp.fsum(A[r]*mp.cos(2*r*t) for r in range(len(A))) dA = mp.diff(Ca, alpha0) Nq = -(mp.pi/q)*dA*A[0] Dq = mp.quad(lambda t: Ca(t)**2*mp.cosh(2*t), [0, alpha0])*mp.pi - mp.quad(lambda t: Ca(t)**2, [0, alpha0])*mp.quad(lambda t: Bf(t)**2*mp.cos(2*t), [-mp.pi, mp.pi]) for z in tot: tot[z] += Nq/Dq*Fk(b)*Fk(c)*Fk(mp.mpf(z))/Fk(0) REF30 = {1: 0.913512392, 3: 0.634083649, 5: 0.201476858} # pbvp/solution.py, q < 30 (checks240.out) ok('15-mode partial sums on the axis reproduce the double-precision code', max(abs(tot[z] - REF30[z]) for z in tot), 1e-8) print(' V/V0 on the axis, 15 modes:', {z: mp.nstr(v, 9) for z, v in tot.items()}) print('All checks passed.')