(f, x_args)
return X, Y
Samples a 2d function f over specified intervals and returns two
    arrays (X, Y) suitable for plotting with matlab (matplotlib)
    syntax. See examples\mplot2d.py.

    f is a function of one variable, such as x**2.
    x_args is an interval given in the form (var, min, max, n)
Samples a 2d function f over specified intervals and returns two
    arrays (X, Y) suitable for plotting with matlab (matplotlib)
    syntax. See examples\mplot2d.py.
Samples a 2d function f over specified intervals and returns two arrays ( X Y ) suitable for plotting with matlab ( matplotlib ) syntax . See examples \ mplot2d . py .
def sample2d(f, x_args):
    """
    Samples a 2d function f over specified intervals and returns two
    arrays (X, Y) suitable for plotting with matlab (matplotlib)
    syntax. See examples\mplot2d.py.

    f is a function of one variable, such as x**2.
    x_args is an interval given in the form (var, min, max, n)
    """
    try:
        f = sympify(f)
    except SympifyError:
        raise ValueError("f could not be interpretted as a SymPy function")
    try:
        x, x_min, x_max, x_n = x_args
    except AttributeError:
        raise ValueError("x_args must be a tuple of the form (var, min, max, n)")

    x_l = float(x_max - x_min)
    x_d = x_l/float(x_n)
    X = np.arange(float(x_min), float(x_max) + x_d, x_d)

    Y = np.empty(len(X))
    for i in range(len(X)):
        try:
            Y[i] = float(f.subs(x, X[i]))
        except TypeError:
            Y[i] = None
    return X, Y
def sample2d ( f , x_args ) : try : f = sympify ( f ) except SympifyError : raise ValueError ( "f could not be interpretted as a SymPy function" ) try : x , x_min , x_max , x_n = x_args except AttributeError : raise ValueError ( "x_args must be a tuple of the form (var, min, max, n)" ) x_l = float ( x_max - x_min ) x_d = x_l / float ( x_n ) X = np . arange ( float ( x_min ) , float ( x_max ) + x_d , x_d ) Y = np . empty ( len ( X ) ) for i in range ( len ( X ) ) : try : Y [ i ] = float ( f . subs ( x , X [ i ] ) ) except TypeError : Y [ i ] = None return X , Y