# Elliptic PDE: Illustrating the Maximum Principle¶

MIT License Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
In [3]:
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
import matplotlib.pyplot as plt
import numpy as np

import sympy as sym


## Checking the Solution Symbolically¶

In [9]:
sx = sym.Symbol("x")
sy = sym.Symbol("y")
sr = sym.sqrt(sx**2 + sy**2)
sphi = sym.atan2(sy, sx)
ssol = sr**2 * sym.cos(2*sphi)

sym.simplify(sym.diff(ssol, sx, 2) + sym.diff(ssol, sy, 2))

Out[9]:
$\displaystyle 0$

## Plotting the Solution¶

In [4]:
step = 0.04
maxval = 1.0

r = np.linspace(0, 1.25, 50)
p = np.linspace(0, 2*np.pi, 50)
R, P = np.meshgrid(r, p)
X, Y = R*np.cos(P), R*np.sin(P)

Z = R**2 * np.cos(2*P)

fig = plt.figure()

<mpl_toolkits.mplot3d.art3d.Poly3DCollection at 0x7f8e188827d0>