In [22]:
dx = 1
def S1(y):
    if abs(y) <= 0.5:
        return 1
    else:
        return 0
def S2(y):
    absy = abs(y)
    if absy < 1:
        return 1 - absy
    else:
        return 0
def W1(y):
    absy = abs(y)
    if absy <= 1:
        return 1-absy
    else:
        return 0
def W2(y):
    absy = abs(y)
    if absy < 0.5:
        return 0.75 - y*y
    elif absy < 1.5:
        return 1/8 * (3 - 2*absy)**2
    else:
        return 0

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

In [24]:
x = 2.10

xg = np.linspace(0, 5, 1000)
xgrid = np.arange(0, 5, dx)
plt.plot(xg, [S1(XG-x)/dx for XG in xg])
plt.plot(xgrid, [W1(XGRID-x)/dx for XGRID in xgrid])


Out[24]:
[<matplotlib.lines.Line2D at 0x7f1bea5859b0>]

In [25]:
plt.plot(xg, [S2(XG-x) for XG in xg])
plt.plot(xgrid, [W2(XGRID-x) for XGRID in xgrid])


Out[25]:
[<matplotlib.lines.Line2D at 0x7f1bea0e99b0>]