In [ ]:
from IPython.core.display import HTML

with open('../common/creativecommons.html', 'r') as f:
    html = f.read()
    
with open('../common/custom.css', 'r') as f:
    styles = f.read()
    
HTML(styles)

In [ ]:
import numpy as np
import matplotlib.pyplot as plt

from sympy import init_printing, symbols, pi
from sympy.plotting import plot3d_parametric_surface

init_printing()

In [ ]:
r, h, u = symbols('r h u')
V = (r**2 * h * pi) / 3
V

In [ ]:
circ = V.diff(r)
circ

In [ ]:
area = V.diff(h)
area

Gradient


In [ ]:
x, y = np.mgrid[-100:101:25., -100:101:25.]

V = 2 * x ** 2 + 3 * y ** 2

Ex, Ey = np.gradient(V)
Ex = - Ex
Ey = - Ey

fig, ax = plt.subplots(figsize=(4, 4))
ax.contourf(x, y, V, cmap=plt.cm.Greys_r)
_ = ax.quiver(x, y, Ex, Ey, color='b')
# fig.savefig('gradient.png')

Divergence (Fake!)

Horizontally non-divergent (u=U_ox, v=U_oy)


In [ ]:
dx = 0.5
x = np.arange(-4, 4 + dx, dx)
y = x.copy()

X, Y = np.meshgrid(x, y)
f = X ** 2 - Y ** 2
Dx, Dy = np.gradient(f)

fig, ax = plt.subplots(figsize=(4, 4))
ax.contourf(x, y, f, cmap=plt.cm.Greys)
_ = ax.quiver(x, y, Dy, Dx, color='b')

# fig.savefig('divergence.png')

Curl (Fake!)

z-component of curl = constant

(u=-U_oy, v=U_ox)


In [ ]:
fig, ax = plt.subplots(figsize=(4, 4))
_ = ax.quiver(x, y, Dx, Dy, color='b')
# fig.savefig('curl.png')

In [ ]:
HTML(html)