Indexed text attachment
verify-pde.py
Source for Partial Differential Equations in Higher Categories
View paper · Download original file
Lines 1581–1640 of 1640. Source text is displayed literally.
1581 else:1582 b = m2_1583 return 0.5 * (a + b)1584 1585 1586Tl = 12.01587shift1 = (peak(Tl, k1 * k1 * Tl - math.log(Ak) / k1) - k1 * k1 * Tl) - (peak(-Tl, -k1 * k1 * Tl) + k1 * k1 * Tl)1588shift2 = (peak(Tl, k2 * k2 * Tl) - k2 * k2 * Tl) - (peak(-Tl, -k2 * k2 * Tl - math.log(Ak) / k2) + k2 * k2 * Tl)1589check('X6 two solitons: the exact solution solves the equation, conserves mass 2(k1 + k2), and after the collision the fast soliton is ahead by'1590 ' (2/k1) log((k1+k2)/(k1-k2)) and the slow one behind by (2/k2) log((k1+k2)/(k1-k2))', r2s < 1e-5 and max(abs(m_ - 2 * (k1 + k2)) for m_ in masses) < 1e-81591 and abs(shift1 + math.log(Ak) / k1) < 1e-5 and abs(shift2 - math.log(Ak) / k2) < 1e-5, 'residual %.1e; shifts %.5f, %.5f' % (r2s, shift1, shift2))1592hq = 0.0251593xq = [-30 + hq * (i + 1) for i in range(2799)]1594spec = [tri_eigs([2 / hq ** 2 - two(x, t) for x in xq], [-1 / hq ** 2] * 2798, 2) for t in (0.0, 1.5)]1595check('X7 the flow is isospectral: the operator -d^2/dx^2 - u(., t) with the two-soliton potential has the eigenvalues -k1^2/4 and -k2^2/4 at'1596 ' every time', all(abs(sp[0] + k1 * k1 / 4) < 1e-3 and abs(sp[1] + k2 * k2 / 4) < 1e-3 for sp in spec), 'at t = 0: %.5f, %.5f; at t = 1.5: %.5f, %.5f' % (*spec[0], *spec[1]))1597cat = lambda x: 1.3 * math.cosh((x - 0.2) / 1.3)1598check('X8 calculus of variations: the catenary satisfies the Euler-Lagrange equation u u\'\' = 1 + u\'^2 of the area functional, and u/sqrt(1+u\'^2) is constant',1599 all(abs(cat(x) * d2(cat, x) - 1 - d1(cat, x) ** 2) < 1e-6 and abs(cat(x) / math.sqrt(1 + d1(cat, x) ** 2) - 1.3) < 1e-9 for x in (-0.8, 0.1, 1.4)))1600 1601 1602def ellK(m):1603 a, b = 1.0, math.sqrt(1 - m * m)1604 for _ in range(40):1605 a, b = 0.5 * (a + b), math.sqrt(a * b)1606 return PI / (2 * a)1607 1608 1609lb = 2.01610okb, lams = True, []1611for Amp in (0.2, 1.0, 2.0):1612 lam = (2 * ellK(math.sin(Amp / 2)) / lb) ** 21613 y = [Amp, 0.0]1614 for _ in range(4000):1615 y = rk4(lambda yy: [yy[1], -lam * math.sin(yy[0])], y, lb / 4000)1616 okb = okb and abs(y[1]) < 1e-8 and abs(y[0] + Amp) < 1e-81617 lams.append(lam / (PI / lb) ** 2)1618check('X9 buckling, u\'\' + lambda sin u = 0 with u\' = 0 at both ends: the first branch leaves the trivial solution at lambda = pi^2/l^2 and bends'1619 ' to the right, with lambda/lambda_1 = (2K(sin(A/2))/pi)^2 = 1 + A^2/8 + ...', okb and lams[0] < lams[1] < lams[2] and abs(lams[0] - 1 - 0.2 ** 2 / 8) < 1e-4,1620 'lambda/lambda_1 at amplitude 0.2, 1, 2: %.5f, %.5f, %.5f' % tuple(lams))1621gg, hh = 9.81, 3.01622 1623 1624def ww(kk):1625 om_ = math.sqrt(gg * kk * math.tanh(kk * hh))1626 pot = lambda x, z, t: math.cosh(kk * (z + hh)) * math.sin(kk * x - om_ * t)1627 harm = d2(lambda x: pot(x, -0.7, 0.3), 0.4) + d2(lambda z: pot(0.4, z, 0.3), -0.7)1628 surf = d2(lambda t: pot(0.4, 0.0, t), 0.3) + gg * d1(lambda z: pot(0.4, z, 0.3), 0.0)1629 bott = d1(lambda z: pot(0.4, z, 0.3), -hh)1630 return max(abs(harm), abs(surf), abs(bott)) / math.cosh(kk * hh), om_ / kk1631 1632 1633r1_, cmid = ww(0.9)1634cshal, cdeep = math.sqrt(gg * math.tanh(0.003 * hh) / 0.003), math.sqrt(gg * math.tanh(20.0 * hh) / 20.0)1635check('X10 linear water waves: the potential cosh(k(z+h)) sin(kx - omega t) is harmonic, has no flow through the bottom, and satisfies the surface'1636 ' condition exactly when omega^2 = g k tanh(kh); the speed is sqrt(gh) in shallow water and sqrt(g/k) in deep water',1637 r1_ < 1e-5 and abs(cshal - math.sqrt(gg * hh)) < 1e-3 and abs(cdeep - math.sqrt(gg / 20.0)) < 1e-12)1638 1639footer()1640