code: def chebyshevcostfactory(target):
      def chebyshevcost(trial, M=61):
          """The costfunction for order-n Chebyshev fitting.
          M evaluation points between [-1, 1], and two end points"""
  
          result = 0.0
          x = -1.0
          dx = 2.0 / (M - 1)
          for i in range(M):
              px = polyeval(trial, x)
              if px < -1 or px > 1:
                  result += (1 - px) * (1 - px)
              x += dx
  
          px = polyeval(trial, 1.2) - polyeval(target, 1.2)
          if px < 0:
              result += px * px
  
          px = polyeval(trial, -1.2) - polyeval(target, -1.2)
          if px < 0:
              result += px * px
  
          return result
  
      return chebyshevcost
  
label_desc: Use image node_id 1 for calling a global function with example usage: chebyshevcostfactory(target) and returns: chebyshevcost, result