def __eq__(self, o): if isinstance(o, Function): for a, b, order in self._mesh.iter_elems(): fekete_points = _fekete.get_fekete_points_phys(order, a, b) for p in fekete_points: if not feq(self(p), o(p)): return False for a, b, order in o._mesh.iter_elems(): fekete_points = _fekete.get_fekete_points_phys(order, a, b) for p in fekete_points: if not feq(self(p), o(p)): return False return True else: return False
def __pow__(self, o): if isinstance(o, (int, long)): pts = self._mesh._points orders = empty(len(self._mesh._orders), dtype="int") values = [] for n, (a, b, order) in enumerate(self._mesh.iter_elems()): order = o*order x = _fekete.get_fekete_points_phys(order, a, b) vals = _fekete.eval_poly(x, self._values[n], a, b)**o values.append(vals) orders[n] = order mesh = Mesh1D(pts, orders) return Function(values, mesh) else: return NotImplemented
def __pow__(self, o): if isinstance(o, (int, long)): pts = self._mesh._points orders = empty(len(self._mesh._orders), dtype="int") values = [] for n, (a, b, order) in enumerate(self._mesh.iter_elems()): order = o * order x = _fekete.get_fekete_points_phys(order, a, b) vals = _fekete.eval_poly(x, self._values[n], a, b)**o values.append(vals) orders[n] = order mesh = Mesh1D(pts, orders) return Function(values, mesh) else: return NotImplemented
def plot(self, call_show=True): try: from jsplot import plot, show except ImportError: from pylab import plot, show odd = False for a, b, order in self.iter_elems(): fekete_points = _fekete.get_fekete_points_phys(order, a, b) if odd: format = "y-" else: format = "k-" odd = not odd plot([a, a, b, b], [0, order, order, 0], format, lw=2) if call_show: show()
def project_onto_union(self, mesh): """ The same as project_onto, only "mesh" is a subset of self._mesh. """ if mesh == self._mesh: return self values = [] n = 0 for a, b, order in mesh.iter_elems(): if a >= self._mesh._points[n+1]: n += 1 fekete_points = _fekete.get_fekete_points_phys(order, a, b) elem_values = [] # Note: this is not a projection (it only evaluates obj in # fekete points), so the result is not the best # approximation possible: elem_values = self.get_values_in_element(n, fekete_points) values.append(elem_values) return Function(values, mesh)
def project_onto_union(self, mesh): """ The same as project_onto, only "mesh" is a subset of self._mesh. """ if mesh == self._mesh: return self values = [] n = 0 for a, b, order in mesh.iter_elems(): if a >= self._mesh._points[n + 1]: n += 1 fekete_points = _fekete.get_fekete_points_phys(order, a, b) elem_values = [] # Note: this is not a projection (it only evaluates obj in # fekete points), so the result is not the best # approximation possible: elem_values = self.get_values_in_element(n, fekete_points) values.append(elem_values) return Function(values, mesh)
def __init__(self, obj, mesh=None): if not isinstance(mesh, Mesh1D): raise Exception("You need to specify a mesh.") self._mesh = mesh if isinstance(obj, (tuple, list, ndarray)): self._values = obj else: self._values = [] for a, b, order in mesh.iter_elems(): fekete_points = _fekete.get_fekete_points_phys(order, a, b) # Note: this is not a projection (it only evaluates obj in # fekete points), so the result is not the best # approximation possible: elem_values = [obj(p) for p in fekete_points] self._values.append(array(elem_values)) self._poly_coeffs = {} self._fe_sol = None self.logger = _logger_Function
def plot(self, call_show=True): try: from jsplot import plot, show except ImportError: from pylab import plot, show odd = False for n, (a, b, order) in enumerate(self._mesh.iter_elems()): fekete_points = _fekete.get_fekete_points_phys(order, a, b) vals = self._values[n] assert len(vals) == len(fekete_points) x = arange(a, b, 0.1) y = [self(_x) for _x in x] if odd: format = "g-" else: format = "r-" odd = not odd plot(x, y, format) plot(fekete_points, vals, "ko") if call_show: show()