def test_absolute_value(): f1 = Function(np.linspace(0, 10, 100), lambda x: np.exp(1j * x)) f2 = Function(np.linspace(0, 10, 100), lambda x: 1) f3 = Function(f1.get_domain(), lambda x: -x) f4 = Function(f1.get_domain(), lambda x: x) assert_equal(f1.abs(), f2) assert_equal(f3.abs(), f4)
def Lp(f: Function, p=2, domain=None): r""" Computes the Lp-norm of a function. The Lp-Norm of a function is defined as ::math.. (\int |f(x)|^{p} dx)^(1/p) for any :math:`1 \leq p \le \infty` and any function f which p-th power is lebesgue integrable :param f: :param p: :param domain: :return: """ assert 1 <= p if domain is None: domain = f.get_domain() return Integral.integrate((f.abs()) ** p) ** (1 / p)