5
5
FLOATDEFUNK and QUANC8 */
7
7
/* Get the fasl file for DBLINT */
9
9
/* Get the fasl file for QUANC8 */
12
12
/* Use DBLINT to get the double integral of exp(x-y^2) over the region
13
13
bounded by y=1 and y=2+x^(3/2) and x=0 to x=1 */
15
15
/* Define the integrand as a function of two variables */
17
F(X,Y):=(MODE_DECLARE([X,Y],FLOAT),EXP(X-Y^2));
17
f(x,y):=(mode_declare([x,y],float),exp(x-y^2));
19
19
/* Define the lower and upper limits on the inner (y in this case)
20
20
integral as a function of the outer variable (x in this case) */
22
R(X):=(MODE_DECLARE(X,FLOAT),1.0);
23
S1(X):=(MODE_DECLARE(X,FLOAT),2.0+X^(3/2));
22
r(x):=(mode_declare(x,float),1.0);
23
s1(x):=(mode_declare(x,float),2.0+x^(3/2));
25
25
/* Now translate these functions for the sake of efficiency */
29
29
/* Call the DBLINT function with quoted arguments for function names, and
30
30
floating point values for the endpoints of the outer (x) integration
33
DBLINT_ANSWER:DBLINT('F,'R,'S1,0.0,1.0);
33
dblint_answer:dblint('f,'r,'s1,0.0,1.0);
35
35
/* Now generate the exact integral over y using RISCH */
37
INTY:RISCH(EXP(X-Y^2),Y);
37
inty:risch(exp(x-y^2),y);
39
39
/* Now get the integrand of the x integral */
41
XINT:EV(INTY,Y:2+X^(3/2))-EV(INTY,Y:1);
41
xint:ev(inty,y:2+x^(3/2))-ev(inty,y:1);
43
43
/* Try to do the x integral exactly */
48
48
/* Still no luck with closed-form */
49
49
/* The integral over x can't be done in closed-form, so let's use a
50
50
one-dimensional integrator to do it numerically. First, we must
51
51
define the integrand as a floating point function. FLOATDEFUNK
52
52
does this very conveniently on the expression */
54
FLOATDEFUNK(fUN,[X],XINT);
54
floatdefunk(fun,[x],xint);
56
56
/* Now translate the function fun */
59
59
/* Now call QUANC8 on the translated function (see SHARE1;QQ USAGE for
62
QUANC8_ANSWER:QUANC8(FUN,0.0,1.0);
62
quanc8_answer:quanc8(fun,0.0,1.0);
64
64
/* Compare the answers from DBLINT and QUANC8 */
66
(DBLINT_ANSWER-QUANC8_ANSWER)/DBLINT_ANSWER;
66
(dblint_answer-quanc8_answer)/dblint_answer;
68
68
/* It appears to be small enough relative error for most uses */
69
69
"end of dblint.dm1"$