area and volume integrals with quadpack
- Subject: area and volume integrals with quadpack
- From: Edwin Woollett
- Date: Fri, 16 Dec 2011 16:10:29 -0800
A basic implementation which just uses quad_qags
(to be followed by functions which allow options):
----------------------------------------------------------
(%i2) load(qarea);
(%o2) "c:/work2/qarea.mac"
(%i3) qarea(x*y^2,[x,0,1],[y,0,1]);
(%o3) 0.16666666666667
(%i4) qarea(x*y^2,[x,0,1],[y,0,x]);
(%o4) 0.066666666666667
(%i6) qarea(x*y^2,[x,0,1],[y,0,1]);
(%o6) 0.16666666666667
(%i7) qarea(x*y^2,[x,0,1],[y,0,x]);
(%o7) 0.066666666666667
(%i8) qvolume(x*y^2*z^3,[x,0,1],[y,0,1],[z,0,1]);
(%o8) 0.041666666666667
(%i9) qvolume(x*y^2*z^3,[x,0,1],[y,0,x],[z,0,y]);
(%o9) 0.003968253968254
(%i10) qvolume(1/sqrt(x + y^2 + z^3),[x,0,1],[y,0,1],[z,0,1]);
(%o10) 1.088500610145352
(%i11) qarea(1+sin(5*x*y +y^2),[x,-1,1],[y,-sqrt(1-x^2),sqrt(1-x^2)]);
(%o11) 3.43677885014651
---------------------------------
code:
/* qarea.mac */
codelist :
[[1,"too many subintervals done"],
[2,"excessive roundoff error detected"],
[3,"extremely bad integrand behavior observed"],
[4, "integration failed to converge"],
[5, "integral is probably divergent or slowly convergent"],
[6, "the input is invalid"]]$
qgsz(ez,vz,vz1,vz2) := quad_qags(ez,vz,vz1,vz2)$
qarea(ex,uL,vL) :=
block([u,u1,u2,v,v1,v2,rL,uverr],
[u,u1,u2] : uL,
[v,v1,v2] : vL,
rL : qgsz(qgsz(ex,v,v1,v2)[1],u,u1,u2),
if not listp(rL) then
(print(" returns noun form "),return(false)),
uverr : rL[4],
if uverr = 0 then rL[1]
else (print(" error = ",part(codelist,uverr,2)),
false))$
--------------------------------------
Ted Woollett