###
### this example evaluates the quadrature function for
### the spherical polynomials. it computes the integral
### of the product for all pairs of orthogonal polynomials
### from order 0 to order 5. the results are compared to
### the diagonal matrix of the inner products for the
### polynomials
###
### construct a list of the spherical polynomials
### of orders 0 to 5
###
p.list <- spherical.polynomials( 5 )
###
### function to construct the polynomial products by column
###
by.column.products <- function( c, p.list, p.p.list )
{
###
### function to construct the polynomial products by row
###
by.row.products <- function( r, c, p.list )
{
row.column.product <- p.list[[r]] * p.list[[c]]
return (row.column.product )
}
row.list <- lapply( 1:6, by.row.products, c, p.list )
return( row.list )
}
###
### construct the two dimensional list of pair products
### of polynomials
###
p.p.products <- lapply( 1:6, by.column.products, p.list )
###
### function construct the polynomial functions by column
###
by.column.functions <- function( c, p.p.products )
{
###
### function to construct the polynomial functions by row
###
by.row.functions <- function( r, c, p.p.products )
{
row.column.function <- as.function( p.p.products[[r]][[c]] )
return( row.column.function )
}
row.list <- lapply( 1:6, by.row.functions, c, p.p.products )
return( row.list )
}
###
### compute the two dimensional list of functions
### corresponding to the polynomial products in
### the two dimensional list p.p.products
###
p.p.functions <- lapply( 1:6, by.column.functions, p.p.products )
###
### get the rule table for the order 6 polynomial
###
rules <- spherical.quadrature.rules( 6 )
order.6.rule <- rules[[6]]
###
### function to compute the integral of the polynomials by column
###
by.column.integrals <- function( c, p.p.functions )
{
###
### function to compute the integral of the polynomials by row
###
by.row.integrals <- function( r, c, p.p.functions )
{
row.column.integral <- spherical.quadrature(
p.p.functions[[r]][[c]], order.6.rule )
return( row.column.integral )
}
row.vector <- sapply( 1:6, by.row.integrals, c, p.p.functions )
return( row.vector )
}
###
### construct the square symmetric matrix containing
### the definite integrals over the default limits
### corresponding to the two dimensional list of
### polynomial functions
###
p.p.integrals <- sapply( 1:6, by.column.integrals, p.p.functions )
###
### construct the diagonal matrix with the inner products
### of the orthogonal polynomials on the diagonal
###
p.p.inner.products <- diag( spherical.inner.products( 5 ) )
print( p.p.integrals )
print( p.p.inner.products )Run the code above in your browser using DataLab