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)

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 )
samples a 2d function f over specified intervals and returns two arrays suitable for plotting with matlab syntax .