[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Ack! How to compute double integral?
From: 
John W. Eaton 
Subject: 
Ack! How to compute double integral? 
Date: 
Mon, 3 Nov 1997 23:13:08 0600 
On 3Nov1997, Joe Reinhardt <address@hidden> wrote:
 I am trying to compute an Mdimensional integral using quad(). The
 documentation says quad only does integration over a single variable,
 so I tried nesting subroutine calls over each of my variables.

 This method doesn't seem to work.
It won't work because Octave's quad function is ultimately implemented
with some Fortran subroutines that can't be called recursively.
 I attached some sample code for 2D showing that my technique fails.
 The outer quad() call only evaluates one value of "y".

 1) Is there a way to compute Mdimensional integrals in Octave?
Yes, you can use an Mfile specifically designed for multidimensional
integration. Here is some information that was posted to this list
some time ago:
Date: Wed, 29 Nov 95 07:49:41 CST
From: address@hidden (Vinayak Dutt)
Subject: Re: How to quad("sin(a*sin(x))*sin(x)",0,pi/2)?
To: address@hidden
Francesco Potorti wrote:
#
# I found the following in the matlab archives, form the
# contribution/integration directory or some like that, if I am not
# wrong. They should be public domain. I also have the sources.
#
# ===================================================================
# Index for integration
# ===================================================================
#
# nit: <directory>
#
# ===================================================================
#
# Numerical Integration Toolbox
#
# MATLAB Toolbox for 1D, 2D, and nD Numerical Integration
#
# The original 1D routines were obtained from NETLIB and were
# written by
# Howard Wilson
# Department of Engineering Mechanics
# University of Alabama
# Box 870278
# Tuscaloosa, Alabama 354870278
# Phone 205 3481617
# Email address: HWILSON @ UA1VM.UA.EDU
#
# The rest of the routines were written by
# Bryce Gardner
# Ray W. Herrick Laboratories
# Purdue University
# West Lafayette, IN 47906
# Phone: 3174940231
# Fax: 3174940787
# Email: address@hidden
#
# These are the general purpose integration routines:
#
# quadg.m  High accuracy replacement for QUAD and QUAD8 (1D)
# quad2dg.m  2D integration over a rectangular region
# quad2dggen.m  2D integration over a general region
# quadndg.m  nD integration over a nD hyperrectangular region
I had fixed these routines sometime back (to work well in Octave)
and have used them myself and found them quite useful. Gaussian
Quadrature works a lot faster too :)
I had checked with Gardner some time back and he did not have any
problems if Octave ftp sites kept his software.
If anyone is interested, I can mail the fixed version of that MATLAB
package.
I don't remember whether Vinayak ever made his versions available.
Perhaps something like these functions will eventually be distributed
as part of Octave. Would someone like to volunteer to make that
happen?
 2) I used global variables to pass parameters from integrand to
 integrand. Is there a better way to do this?
Nope, not with quad. I don't know about the set of Mfiles for
quadrature mentioned in the message above. They may allow for passing
additional parameters.
Thanks,
jwe