% Script file to play with the polynomials from Table 1 of
%
%    Adam M. Oberman, "A Convergent Monotone Difference Scheme for Motion of
%    Level Sets by Mean Curvature," Numerische Mathematik, 99: 365-379
%    (2004), DOI: 10.1007/s00211-004-0566-1.
%
% Uses Matlab's symbolic toolbox to determine the analytic one-Laplacian of
% the polynomials.  These analytic values can then be used to compute errors
% in polynomialCircleTest and polynomialGridTest.

syms x y real

p1 = 6*x + 1.25*y + 4.5*x^2/2 + 2.8*x*y - 5.2*y^2/2;
p2 = x - 0.01*y + 0.5*x^2/2 + 3.1*x*y - 2*y^2/2;

dp1dx = diff(p1, x)
dp1dy = diff(p1, y)
dp1dx2 = diff(dp1dx, x)
dp1dy2 = diff(dp1dy, y)
dp1dxdy = diff(dp1dx, y)

gradp1 = [ dp1dx; dp1dy ];
laplace1p1 = ((dp1dy^2 * dp1dx2 + dp1dx^2 * dp1dy2...
               - 2 * dp1dx * dp1dy * dp1dxdy ) ...
              / (gradp1' * gradp1));
simple(laplace1p1)

dp2dx = diff(p2, x)
dp2dy = diff(p2, y)
dp2dx2 = diff(dp2dx, x)
dp2dy2 = diff(dp2dy, y)
dp2dxdy = diff(dp2dx, y)

gradp2 = [ dp2dx; dp2dy ];
laplace1p2 = ((dp2dy^2 * dp2dx2 + dp2dx^2 * dp2dy2...
               - 2 * dp2dx * dp2dy * dp2dxdy ) ...
              / (gradp2' * gradp2));
pretty(simple(laplace1p2))
