function U = lp_exact2d(kind, X, Y, par) % LP_EXACT2D A harmonic function on the unit square, used as ground truth. % % Every choice here satisfies Laplace's equation exactly, so taking its trace % on the boundary as Dirichlet data makes it the exact solution of the % Dirichlet problem, and the difference between a computed solution and this % function is the whole of the error. par is a per-kind shape parameter. if nargin < 4 par = 1; end switch kind case 'expsin' % exp(x) sin(y): entire, gentle, the standard test U = exp(X) .* sin(Y); case 'poly' % Re (x + iy)^k: a harmonic polynomial of degree k k = round(par); U = real((X + 1i*Y).^k); case 'wave' % exp(k*y) sin(k*x): oscillatory along one edge, growing across the % square by a factor exp(k), which is where its conditioning goes k = par; U = exp(k*Y) .* sin(k*X); case 'log' % log|z - z0| with z0 a distance par outside the right edge: harmonic % inside, but with a singularity just off the domain, so the solution % has structure on the length scale par near that edge z0 = (1 + par) + 0.5i; U = log(abs((X + 1i*Y) - z0)); otherwise error('lp_exact2d: unknown solution "%s"', kind); end end