(points, order, syms)
return f
Generates a polynomial using a Vandermonde system
Generates a polynomial using a Vandermonde system
Generates a polynomial using a Vandermonde system
def gen_poly(points, order, syms):
    """Generates a polynomial using a Vandermonde system"""
    num_pts = len(points)
    if num_pts == 0:
        raise ValueError("Must provide points")
    dim = len(points[0]) - 1
    if dim > len(syms):
        raise ValueError("Must provide at lease %d symbols for the polynomial" % dim)
    V, tmp_syms, terms = vandermonde(order, dim)
    if num_pts < V.shape[0]:
        raise ValueError(
            "Must provide %d points for order %d, dimension "
            "%d polynomial, given %d points" %
            (V.shape[0], order, dim, num_pts))
    elif num_pts > V.shape[0]:
        print("gen_poly given %d points but only requires %d, "\
            "continuing using the first %d points" % \
            (num_pts, V.shape[0], V.shape[0]))
        num_pts = V.shape[0]

    subs_dict = {}
    for j in range(dim):
        for i in range(num_pts):
            subs_dict[tmp_syms[i][j]] = points[i][j]
    V_pts = V.subs(subs_dict)
    V_inv = V_pts.inv()

    coeffs = V_inv.multiply(Matrix([points[i][-1] for i in xrange(num_pts)]))

    f = 0
    for j, term in enumerate(terms):
        t = 1
        for k in term:
            t *= syms[k]
        f += coeffs[j]*t
    return f
def gen_poly ( points , order , syms ) : num_pts = len ( points ) if num_pts == 0 : raise ValueError ( "Must provide points" ) dim = len ( points [ 0 ] ) - 1 if dim > len ( syms ) : raise ValueError ( "Must provide at lease %d symbols for the polynomial" % dim ) V , tmp_syms , terms = vandermonde ( order , dim ) if num_pts < V . shape [ 0 ] : raise ValueError ( "Must provide %d points for order %d, dimension " "%d polynomial, given %d points" % ( V . shape [ 0 ] , order , dim , num_pts ) ) elif num_pts > V . shape [ 0 ] : print ( "gen_poly given %d points but only requires %d, " "continuing using the first %d points" % ( num_pts , V . shape [ 0 ] , V . shape [ 0 ] ) ) num_pts = V . shape [ 0 ] subs_dict = { } for j in range ( dim ) : for i in range ( num_pts ) : subs_dict [ tmp_syms [ i ] [ j ] ] = points [ i ] [ j ] V_pts = V . subs ( subs_dict ) V_inv = V_pts . inv ( ) coeffs = V_inv . multiply ( Matrix ( [ points [ i ] [ - 1 ] for i in xrange ( num_pts ) ] ) ) f = 0 for j , term in enumerate ( terms ) : t = 1 for k in term : t *= syms [ k ] f += coeffs [ j ] * t return f