def test_lag1st_to_trig(self):
# scalar case
dest_weight = core.change_projection_base(self.src_weights, self.src_test_funcs, self.trig_test_funcs[0])
dest_approx_handle_s = core.back_project_from_base(dest_weight, self.trig_test_funcs[0])
# standard case
dest_weights = core.change_projection_base(self.src_weights, self.src_test_funcs, self.trig_test_funcs)
dest_approx_handle = core.back_project_from_base(dest_weights, self.trig_test_funcs)
error = np.sum(np.power(
np.subtract(self.real_func_handle(self.z_values), dest_approx_handle(self.z_values)),
2))
if show_plots:
pw = pg.plot(title="change projection base")
i1 = pw.plot(x=self.z_values, y=self.real_func_handle(self.z_values), pen="r")
i2 = pw.plot(x=self.z_values, y=self.src_approx_handle(self.z_values),
pen=pg.mkPen("g", style=pg.QtCore.Qt.DashLine))
i3 = pw.plot(x=self.z_values, y=dest_approx_handle_s(self.z_values), pen="b")
i4 = pw.plot(x=self.z_values, y=dest_approx_handle(self.z_values), pen="c")
legend = pw.addLegend()
legend.addItem(i1, "f(x) = x")
legend.addItem(i2, "2x Lagrange1st")
legend.addItem(i3, "sin(x)")
legend.addItem(i4, "sin(wx) with w in [1, {0}]".format(dest_weights.shape[0]))
app.exec_()
# should fit pretty nice
self.assertLess(error, 1e-2)
评论列表
文章目录