From help-octave-request at bevo dot che dot wisc dot edu Mon Nov 3 22:49:49 1997 Subject: Ack! How to compute double integral? From: jmr at everest dot radiology dot uiowa dot edu (Joe Reinhardt) To: help-octave at bevo dot che dot wisc dot edu Date: 03 Nov 1997 22:48:50 -0600 --Multipart_Mon_Nov__3_22:48:50_1997-1 Content-Type: text/plain; charset=US-ASCII I am trying to compute an M-dimensional 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. I attached some sample code for 2-D showing that my technique fails. The outer quad() call only evaluates one value of "y". 1) Is there a way to compute M-dimensional integrals in Octave? 2) I used global variables to pass parameters from integrand to integrand. Is there a better way to do this? Thanks! --Multipart_Mon_Nov__3_22:48:50_1997-1 Content-Type: application/octet-stream Content-Disposition: attachment; filename="test.m" Content-Transfer-Encoding: 7bit function ans = test(xmin, xmax, ymin, ymax) global xmin_g = xmin; global xmax_g = xmax; # compute area of unit circle ans = quad("yint", ymin, ymax); endfunction function ans = yint(y) global xmin_g; global xmax_g; global y_g = y; printf("yint: y = %f\n", y); if (abs(y) <= 1) ans = quad("xint", xmin_g, xmax_g); else ans = 0; endif endfunction function ans = xint(x) global y_g; printf("xint: x = %f, y_g = %f\n", x, y_g); r = sqrt(x*x + y_g*y_g); if (r <= 1) ans = 1; else ans = 0; endif endfunction --Multipart_Mon_Nov__3_22:48:50_1997-1 Content-Type: text/plain; charset=US-ASCII -- Joe Reinhardt joe-reinhardt at uiowa dot edu Department of Biomedical Engineering 1402 Engineering Building University of Iowa Iowa City, IA 52242 Phone: 319-335-5634 Fax: 319-335-5631 --Multipart_Mon_Nov__3_22:48:50_1997-1--