Personal tools
You are here: Home Documentation SincLib Quadrature
Document Actions

Quadrature

by admin last modified 2007-05-04 10:55

A short description of the theory behind sinc quadrature and the SincLib implementation.

Theory

We reproduce the following theorem from Lund and Bower's book to illustrate the theoretical underpinning of the sinc quadrature method:

quadrature-theorem.png

Note that we have exponential convergence and a relatively simple formula for computing quadrature.

Implementation

Here's a snippet of the implementation of sinc quadrature:
import scipy
from sinc.base.SincBaseLib import *

log = logging.getLogger('SincMethods.Quadrature')

class Quadrature( SincBase ):

@staticmethod
def defaults():
""" The defaults of the quadrature class. """
opts = SincBase.defaults()
opts['integrand'] = ['i','integrand','The function to integrate',None,'func']
opts['problem_file'] = ['p','problemFile','The file describing the quadrature to' + \
' perform.',None]
opts['answer'] = ['w','answer','The true answer to the integral.',0.0, 'expr']
return opts

def update( self ):
""" Updates the integrand-independent variables. """
super( Quadrature, self ).update()
self.nodes = cSincLib.genSincNodes( self.psi, self.M, self.N, self.h )
self.df2 = self.f2( self.nodes )

def compute(self):
""" Computes the integral of the given integrand using sinc quadrature. """
integral = self.integrand( self.nodes ) * self.df2
self.soln = scipy.sum( integral ) * self.h
return self.soln

# The rest of the entry is truncated
In order to take advantage of the underlying library, we declare the Quadrature object to be a subclass of the SincBase object.  SincBase picks out the appropriate transforms and sets up the constants appropriate for the problem.

Next, examine the defaults method.  This function defines all the command line parameters and defaults for the class.  The options which should be returned are a dictionary of lists.  The key of the dictionary is the variable name the option will be saved to in the class.  The value list consists of 5 elements: the short name, the long name, the description, default, and variable type.  The first three have to do with command line options.

Notice that we start off by copying all the options from SincBase.  This is often a good idea, because SincBase defines most of the standard constants needed for sinc numerical analysis.

The two other important functions are update and compute.  Update is run when the problem is first created.  It only needs to be run when one of the problem parameters, such as M or the conformal transform, is changed.  Compute needs to be re-run whenever the integrand function changes.

Update defines two quantities.  First, the sinc nodes are generated using the function cSincLib.genSincNodes and the values of $f_2$ at sinc nodes are pre-computed.  There are many useful sinc-related functions defined in sinc.base.sinclib, and also implemented in C for speed in sinc.base.cSincLib.  The function f2 is defined as in the table here.

Finally, the sinc quadrature formula is:

quadrature-formula.png

This value is computed in the function compute.  First, we evaluate the f at the sinc nodes, then multiply it by the values of f2 at the respective sinc nodes; this produces a vector of size (M+N+1):
integral = self.integrand( self.nodes ) * self.df2
Then, we sum up with the function sum, and multiply by h:
self.soln = scipy.sum( integral ) * self.h



Powered by Plone, the Open Source Content Management System