Integrals with Python

William Park opengeometry at NOSPAM.yahoo.ca
Thu Jun 27 01:04:10 CEST 2002


Nathan Given <ngiven at lanl.gov> wrote:
> Matlab has quad, quadl, and quad8...
> 
> 
> does Numeric have anything like those?
> 
> 
> 
> Here is my current (lame) project...
> 
> I am comparing the Monte Carlo method for single integrals against the
> answers given by quad, quadl, and quad8 in Matlab.  I coded everything
> in matlab, and was able to do it just fine... the problem is that it was
> SLOW... so, someone suggested that I run python, so I converted all my
> code to python (except the quad, quadl, and quad8 parts), and was able
> to run my code and get the monte carlo answer much faster....
> 
> now, i am going to be doing some double integrals, and I was just
> wondering if python had some built in functions that will calculate some
> double integrals (and single integrals) for me... if there are different
> methods, great... I will be able to compare the monte carlo answer to
> different methods of calculating the integral...

Since the key routine in Monte-Carlo is evaluation of f(), your program
would remain the same for 1-D and 2-D.

As for different integration methods, there are all sorts of C/Fortran
routines for 1-D which you can translate to Python.  Long ago, I wrote 2
Simpson's rule in Python.  For 2-D, however, your choice is a bit limited.
I only know of few approximations based on nicely divisible domains.

-- 
William Park, Open Geometry Consulting, <opengeometry at yahoo.ca>
8-CPU Cluster, Hosting, NAS, Linux, LaTeX, python, vim, mutt, tin



More information about the Python-list mailing list