def test_projection_on_lag1st(self):
weights = []
# convenience wrapper for non array input -> constant function
weight = core.project_on_base(self.funcs[0], self.initial_functions[1])
self.assertTrue(np.allclose(weight, 1.5*self.funcs[0](self.nodes[1])))
# linear function -> should be fitted exactly
weights.append(core.project_on_base(self.funcs[1], self.initial_functions))
self.assertTrue(np.allclose(weights[-1], self.funcs[1](self.nodes)))
# quadratic function -> should be fitted somehow close
weights.append(core.project_on_base(self.funcs[2], self.initial_functions))
self.assertTrue(np.allclose(weights[-1], self.funcs[2](self.nodes), atol=.5))
# trig function -> will be crappy
weights.append(core.project_on_base(self.funcs[3], self.initial_functions))
if show_plots:
# since test function are lagrange1st order, plotting the results is fairly easy
for idx, w in enumerate(weights):
pw = pg.plot(title="Weights {0}".format(idx))
pw.plot(x=self.z_values, y=self.real_values[idx+1], pen="r")
pw.plot(x=self.nodes, y=w, pen="b")
app.exec_()
评论列表
文章目录