|
| 1 | +############# |
| 2 | +# This demonstrates the Triangle harmonic transform and inverse transform, |
| 3 | +# explaining precisely the normalization and points |
| 4 | +# |
| 5 | +# Note we use the duffy map |
| 6 | +# x == (s+1)/2 |
| 7 | +# y== (t+1)/2*(1-(s+1)/2) |
| 8 | +############# |
| 9 | + |
| 10 | + |
| 11 | +using ApproxFun, FastTransforms |
| 12 | + |
| 13 | +jacobinorm(n,a,b) = if n ≠ 0 |
| 14 | + sqrt((2n+a+b+1))*exp((lgamma(n+a+b+1)+lgamma(n+1)-log(2)*(a+b+1)-lgamma(n+a+1)-lgamma(n+b+1))/2) |
| 15 | + else |
| 16 | + sqrt(exp(lgamma(a+b+2)-log(2)*(a+b+1)-lgamma(a+1)-lgamma(b+1))) |
| 17 | + end |
| 18 | +njacobip(n,a,b,x) = jacobinorm(n,a,b) * jacobip(n,a,b,x) |
| 19 | + |
| 20 | +P = (ℓ,m,x,y) -> (2*(1-x))^m*njacobip(ℓ-m,2m,0,2x-1)*njacobip(m,-0.5,-0.5,2y/(1-x)-1) |
| 21 | + |
| 22 | + |
| 23 | + |
| 24 | +p_T = chebyshevpoints(40) |
| 25 | +f = (x,y) -> exp(x + cos(y)) |
| 26 | + f̃ = (s,t) -> f((s+1)/2, (t+1)/2*(1-(s+1)/2)) |
| 27 | + |
| 28 | + F = f̃.(p_T, p_T') |
| 29 | + for j = 1:size(F,2) |
| 30 | + F[:,j] = chebyshevtransform(F[:,j]) |
| 31 | + end |
| 32 | + for k = 1:size(F,1) |
| 33 | + F[k,:] = chebyshevtransform(F[k,:]) |
| 34 | + end |
| 35 | + |
| 36 | + F̌ = cheb2tri(F, 0.0, -0.5, -0.5) |
| 37 | + |
| 38 | + |
| 39 | +f̃ = function(x,y) |
| 40 | + ret = 0.0 |
| 41 | + for j=1:size(F,2), k=1:size(F,1)-j+1 |
| 42 | + ret += F̌[k,j] * P(k+j-2,j-1,x,y) |
| 43 | + end |
| 44 | + ret |
| 45 | + end |
| 46 | + |
| 47 | +f̃(0.1,0.2) ≈ f(0.1,0.2) |
0 commit comments