コード例 #1
0
ファイル: least_squares.py プロジェクト: jjakeman/pyheat
def lagrange_interpolation_1d( x, abscissa, values ):
    """
    evaluate lagrange interpolant at a set of points x
    """
    hier_indices = numpy.arange( abscissa.shape[0] )
    basis = lagrange_polynomial_1d( x, abscissa, hier_indices )
    return numpy.dot( values,  basis )
コード例 #2
0
fig = pylab.figure( 3 )
ax = p3.Axes3D( fig )
coords = SG.grid_point_coordinates()
ax.scatter3D( coords[0,:], coords[1,:], coords[2,:],  s=20, c = 'k', 
              marker = 'o' )


#plot 1d basis functions
num_dims = 1
quadrature_rule = [ClenshawCurtisQuadratureRule()]
ranges = [[-1,1]]
domain = TensorProductDomain( num_dims, ranges = ranges )
tpqr = TensorProductQuadratureRule( num_dims, domain = domain,
                                    quadrature_rules = quadrature_rule )
from interpolation.lagrange_interpolation import lagrange_polynomial_1d
x = numpy.linspace( -1, 1, 100 )
num_levels = 3
fig = pylab.figure( 4 )
for l in xrange( 1, 1 + num_levels ):
    subspace_index  = SubspaceIndex( numpy.array([[0,l]]) )
    abscissa = tpqr.abscissa( subspace_index )[0]
    hier_indices = tpqr.hier_pos_data( subspace_index )[0]
    basis = lagrange_polynomial_1d( x, abscissa, hier_indices )

    pylab.subplot( num_levels, 1, l) 
    for i in xrange( basis.shape[0] ):
        pylab.plot( x, basis[i,:], 'k' )
    pylab.plot( abscissa, numpy.zeros( abscissa.shape[0] ), 'ok' )
    pylab.ylim([-0.5,1.2])
pylab.show()