3
|
1 // Quad.cc -*- C++ -*- |
|
2 /* |
|
3 |
1011
|
4 Copyright (C) 1992, 1993, 1994, 1995 John W. Eaton |
3
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
|
10 Free Software Foundation; either version 2, or (at your option) any |
|
11 later version. |
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
|
19 along with Octave; see the file COPYING. If not, write to the Free |
1315
|
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
3
|
21 |
|
22 */ |
|
23 |
1296
|
24 #if defined (__GNUG__) |
|
25 #pragma implementation |
|
26 #endif |
|
27 |
238
|
28 #ifdef HAVE_CONFIG_H |
1192
|
29 #include <config.h> |
3
|
30 #endif |
|
31 |
|
32 #include "Quad.h" |
1847
|
33 #include "f77-fcn.h" |
3
|
34 #include "sun-utils.h" |
|
35 |
|
36 static integrand_fcn user_fcn; |
|
37 |
260
|
38 // XXX FIXME XXX -- would be nice to not have to have this global |
|
39 // variable. |
|
40 // Nonzero means an error occurred in the calculation of the integrand |
|
41 // function, and the user wants us to quit. |
|
42 int quad_integration_error = 0; |
|
43 |
3
|
44 extern "C" |
|
45 { |
1253
|
46 int F77_FCN (dqagp, DQAGP) (const double (*)(double*, int&), |
|
47 const double&, const double&, |
|
48 const int&, const double*, |
|
49 const double&, const double&, double&, |
|
50 double&, int&, int&, const int&, |
|
51 const int&, int&, int*, double*); |
3
|
52 |
1253
|
53 int F77_FCN (dqagi, DQAGI) (const double (*)(double*, int&), |
|
54 const double&, const int&, |
|
55 const double&, const double&, double&, |
|
56 double&, int&, int&, const int&, |
|
57 const int&, int&, int*, double*); |
3
|
58 } |
|
59 |
|
60 static double |
1251
|
61 user_function (double *x, int& ierr) |
3
|
62 { |
|
63 #if defined (sun) && defined (__GNUC__) |
|
64 double xx = access_double (x); |
|
65 #else |
|
66 double xx = *x; |
|
67 #endif |
|
68 |
260
|
69 quad_integration_error = 0; |
|
70 |
|
71 double retval = (*user_fcn) (xx); |
|
72 |
|
73 if (quad_integration_error) |
1251
|
74 ierr = -1; |
260
|
75 |
|
76 return retval; |
3
|
77 } |
|
78 |
|
79 double |
|
80 DefQuad::integrate (int& ier, int& neval, double& abserr) |
|
81 { |
|
82 int npts = singularities.capacity () + 2; |
|
83 double *points = singularities.fortran_vec (); |
|
84 double result = 0.0; |
|
85 int leniw = 183*npts - 122; |
|
86 int lenw = 2*leniw - npts; |
|
87 int *iwork = new int [leniw]; |
|
88 double *work = new double [lenw]; |
|
89 user_fcn = f; |
|
90 int last; |
|
91 |
289
|
92 double abs_tol = absolute_tolerance (); |
|
93 double rel_tol = relative_tolerance (); |
|
94 |
1253
|
95 F77_FCN (dqagp, DQAGP) (user_function, lower_limit, upper_limit, |
|
96 npts, points, abs_tol, rel_tol, result, |
|
97 abserr, neval, ier, leniw, lenw, last, |
|
98 iwork, work); |
3
|
99 |
|
100 delete [] iwork; |
|
101 delete [] work; |
|
102 |
|
103 return result; |
|
104 } |
|
105 |
|
106 double |
|
107 IndefQuad::integrate (int& ier, int& neval, double& abserr) |
|
108 { |
|
109 double result = 0.0; |
|
110 int leniw = 128; |
|
111 int lenw = 8*leniw; |
|
112 int *iwork = new int [leniw]; |
|
113 double *work = new double [lenw]; |
|
114 user_fcn = f; |
|
115 int last; |
|
116 |
|
117 int inf; |
|
118 switch (type) |
|
119 { |
|
120 case bound_to_inf: |
|
121 inf = 1; |
|
122 break; |
1360
|
123 |
3
|
124 case neg_inf_to_bound: |
|
125 inf = -1; |
|
126 break; |
1360
|
127 |
3
|
128 case doubly_infinite: |
|
129 inf = 2; |
|
130 break; |
1360
|
131 |
3
|
132 default: |
|
133 assert (0); |
|
134 break; |
|
135 } |
|
136 |
289
|
137 double abs_tol = absolute_tolerance (); |
|
138 double rel_tol = relative_tolerance (); |
|
139 |
1253
|
140 F77_FCN (dqagi, DQAGI) (user_function, bound, inf, abs_tol, rel_tol, |
|
141 result, abserr, neval, ier, leniw, lenw, |
|
142 last, iwork, work); |
3
|
143 |
|
144 delete [] iwork; |
|
145 delete [] work; |
|
146 |
|
147 return result; |
|
148 } |
|
149 |
|
150 /* |
|
151 ;;; Local Variables: *** |
|
152 ;;; mode: C++ *** |
|
153 ;;; page-delimiter: "^/\\*" *** |
|
154 ;;; End: *** |
|
155 */ |