def HermiteP(n, x):
    """
    Hermite polynomial of rank n Hn(x)

    Parameters
    ----------
    n: order of the LG beam
    x: matrix of x

    Returns
    -------
    Hermite polynomial
    """
    if n == 0:
        return 1
    elif n == 1:
        return 2 * x
    else:
        return 2 * x * HermiteP(n - 1, x) - 2 * (n - 1) * HermiteP(n - 2, x)