|
| 1 | +using ApproxFun, Plots |
| 2 | + |
| 3 | +# In this example, we numerically compute with Galerkin orthogonal polynomials. |
| 4 | +# If H is a separable Hilbert space and B contains ν linear functional constraints, |
| 5 | +# then the Galerkin orthogonal polynomials are those orthogonal polynomials with |
| 6 | +# respect to H_B := \{ u \in H : Bu = 0 \}. |
| 7 | +# For example, if H = L^2([-1,1]) and we wish to enforce that u(-1) = u'(-1) = |
| 8 | +# u'(1) = 0, then the 2-normalized orthonormal polynomials may be created by |
| 9 | +# taking the QR factorization of the connection coefficients between the |
| 10 | +# normalized Legendre polynomials \sqrt{n+1/2}P_n(x) and a degree-graded |
| 11 | +# polynomial basis that satisfies the constraints. |
| 12 | + |
| 13 | +N = 501 |
| 14 | + |
| 15 | +NS = NormalizedLegendre() |
| 16 | +B = [Evaluation(NS, -1, 0); Evaluation(NS, -1, 1); Evaluation(NS, 1, 1)] |
| 17 | +ν = size(B, 1) |
| 18 | +QS = QuotientSpace(B) |
| 19 | +A = Conversion(QS, NS) |
| 20 | +Q, R = qr(A[1:N+ν,1:N]) |
| 21 | + |
| 22 | +p = Vector{Fun}(undef, N) |
| 23 | +for n = 1:N |
| 24 | + en = [zeros(n-1);1.0;zeros(N+ν-n)] |
| 25 | + p[n] = Conversion(NS, Legendre())*Fun(NS, (Q*en)[1:n+ν]) |
| 26 | + pad!(p[n], 3n+50) |
| 27 | +end |
| 28 | + |
| 29 | +# The mass matrix with entries M_{i,j} = \int_{-1}^1 p_i(x) p_j(x) dx, |
| 30 | +# is numerically the identity, as we expect. |
| 31 | + |
| 32 | +M = [innerproduct(p[i], p[j]) for i = 1:N, j = 1:N] |
| 33 | +@show norm(M-I) ≤ 4*norm(M)*eps() |
| 34 | +@show opnorm(M-I) ≤ 4*sqrt(N)*opnorm(M)*eps() |
| 35 | + |
| 36 | +# Although the polynomials now satisfy deg(p_n) = n+ν instead of deg(p_n) = n, |
| 37 | +# the index appears to determine the number of roots of the Galerkin orthogonal |
| 38 | +# polynomials. In particular, p_n has exactly n roots in (-1,1). |
| 39 | + |
| 40 | +pl = plot(p[1]; legend = false) |
| 41 | +for n in 2:10 |
| 42 | + plot!(p[n]) |
| 43 | +end |
| 44 | +plot(pl) |
| 45 | + |
| 46 | +# This need not be the case! If the second constraint is modified to impose |
| 47 | +# u'(0) = 0, then the odd-index polynomials have one more root than their index |
| 48 | +# and the even-index polynomials have one fewer. |
| 49 | + |
| 50 | +B = [Evaluation(NS, -1, 0); Evaluation(NS, 0, 1); Evaluation(NS, 1, 1)] |
| 51 | +QS = QuotientSpace(B) |
| 52 | +A = Conversion(QS, NS) |
| 53 | +Q, R = qr(A[1:N+ν,1:N]) |
| 54 | + |
| 55 | +q = Vector{Fun}(undef, N) |
| 56 | +for n = 1:N |
| 57 | + en = [zeros(n-1);1.0;zeros(N+ν-n)] |
| 58 | + q[n] = Conversion(NS, Legendre())*Fun(NS, (Q*en)[1:n+ν]) |
| 59 | + pad!(q[n], 3n+50) |
| 60 | +end |
| 61 | + |
| 62 | +pl = plot(q[1]; legend = false) |
| 63 | +for n in 2:10 |
| 64 | + plot!(q[n]) |
| 65 | +end |
| 66 | +plot(pl) |
| 67 | + |
| 68 | +# More information on Galerkin orthogonal polynomials is available in |
| 69 | +# |
| 70 | +# P. W. Livermore. Galerkin orthogonal polynomials, J. Comp. Phys., 229:2046–2060, 2010. |
| 71 | +# |
| 72 | +# The banded QR factorization of the connection coefficients is a linear |
| 73 | +# complexity algorithm to represent the Galerkin orthogonal polynomials in H_B |
| 74 | +# in terms of the polynomial basis for H. This is described in |
| 75 | +# |
| 76 | +# J. L. Aurentz and R. M. Slevinsky. On symmetrizing the ultraspherical spectral method for self-adjoint problems, arXiv:1903.08538, 2019. |
| 77 | +# |
0 commit comments