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 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()
def main(): f_mesh = Mesh1D((0, 2, 4, 6, 8, 10), (12, 12, 12, 12, 12)) f = Function(lambda x: exp(-x), f_mesh) #mesh = f.get_mesh_adapt(max_order=1) g_mesh = Mesh1D((0, 10), (1,)) #mesh.plot(False) g = f.project_onto(g_mesh) error = (g-f).l2_norm() graph = [] while error > 1e-9: print error, g.dofs() graph.append((g.dofs(), error)) print " ", g._mesh._points print " ", g._mesh._orders cand_with_errors = g.get_candidates_with_errors(f) #for m, err in cand_with_errors[:10]: # print " ", err, m._points, m._orders m, _ = cand_with_errors[0] g_mesh = g_mesh.use_candidate(m) g = f.project_onto(g_mesh) error = (g-f).l2_norm() graph.append((g.dofs(), error)) print "Done.", error error = (g - f) print "error: ", error.l2_norm() print "f dofs: ", f.dofs() print "g dofs: ", g.dofs() f.plot(False) g.plot(False) g._mesh.plot(False) from pylab import figure, show, semilogy, grid figure() xx = [x[0] for x in graph] yy = [x[1] for x in graph] semilogy(xx, yy) grid() show()
try: from jsplot import plot, show except ImportError: from pylab import plot, show import numpy data = numpy.loadtxt("solution.gp") x = data[:, 0] y = data[:, 1] plot(x, y) show()