def legrende_polynomials(max_n, v):
    """
    Returns the legendre polynomials
    Based on the algorithm here:
    http://uk.mathworks.com/help/symbolic/mupad_ref/orthpoly-legendre.html
    """
    poly = [1, v] + [0] * (max_n - 1)
    for n in range(2, max_n + 1):
        poly[n] = (2 * n - 1) / n * v * poly[n - 1] - (n - 1) / n * poly[n - 2]
    return poly