3
|
1 // CollocWt.cc -*- C++ -*- |
|
2 /* |
|
3 |
|
4 Copyright (C) 1992, 1993 John W. Eaton |
|
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 |
|
20 Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef __GNUG__ |
|
25 #pragma implementation |
|
26 #endif |
|
27 |
|
28 #include <iostream.h> |
|
29 #include "CollocWt.h" |
|
30 #include "f77-uscore.h" |
|
31 |
|
32 extern "C" |
|
33 { |
|
34 int F77_FCN (jcobi) (int*, int*, int*, int*, double*, double*, |
|
35 double*, double*, double*, double*); |
|
36 |
|
37 int F77_FCN (dfopr) (int*, int*, int*, int*, int*, int*, |
|
38 double*, double*, double*, double*, double*); |
|
39 } |
|
40 |
|
41 // Error handling. |
|
42 |
|
43 void |
|
44 CollocWt::error (const char* msg) |
|
45 { |
|
46 cerr << "Fatal CollocWt error. " << msg << "\n"; |
|
47 exit(1); |
|
48 } |
|
49 |
|
50 CollocWt::CollocWt (void) |
|
51 { |
|
52 n = 0; |
|
53 inc_left = 0; |
|
54 inc_right = 0; |
|
55 lb = 0.0; |
|
56 rb = 1.0; |
|
57 |
|
58 Alpha = 0.0; |
|
59 Beta = 0.0; |
|
60 |
|
61 initialized = 0; |
|
62 } |
|
63 |
|
64 CollocWt::CollocWt (int nc, int il, int ir) |
|
65 { |
|
66 n = nc; |
|
67 inc_left = il; |
|
68 inc_right = ir; |
|
69 lb = 0.0; |
|
70 rb = 1.0; |
|
71 |
|
72 Alpha = 0.0; |
|
73 Beta = 0.0; |
|
74 |
|
75 initialized = 0; |
|
76 } |
|
77 |
|
78 CollocWt::CollocWt (int nc, int ir, int il, double l, double r) |
|
79 { |
|
80 n = nc; |
|
81 inc_left = il; |
|
82 inc_right = ir; |
|
83 lb = l; |
|
84 rb = r; |
|
85 |
|
86 Alpha = 0.0; |
|
87 Beta = 0.0; |
|
88 |
|
89 initialized = 0; |
|
90 } |
|
91 |
|
92 CollocWt::CollocWt (int nc, double a, double b, int il, int ir) |
|
93 { |
|
94 n = nc; |
|
95 inc_left = il; |
|
96 inc_right = ir; |
|
97 lb = 0.0; |
|
98 rb = 1.0; |
|
99 |
|
100 Alpha = a; |
|
101 Beta = b; |
|
102 |
|
103 initialized = 0; |
|
104 } |
|
105 |
|
106 CollocWt::CollocWt (int nc, double a, double b, int ir, int il, |
|
107 double l, double r) |
|
108 { |
|
109 n = nc; |
|
110 inc_left = il; |
|
111 inc_right = ir; |
|
112 lb = l; |
|
113 rb = r; |
|
114 |
|
115 Alpha = a; |
|
116 Beta = b; |
|
117 |
|
118 initialized = 0; |
|
119 } |
|
120 |
|
121 CollocWt::CollocWt (const CollocWt& a) |
|
122 { |
|
123 n = a.n; |
|
124 inc_left = a.inc_left; |
|
125 inc_right = a.inc_right; |
|
126 lb = a.lb; |
|
127 rb = a.rb; |
|
128 r = a.r; |
|
129 q = a.q; |
|
130 A = a.A; |
|
131 B = a.B; |
|
132 |
|
133 nt = n + inc_left + inc_right; |
|
134 |
|
135 initialized = a.initialized; |
|
136 } |
|
137 |
|
138 CollocWt& |
|
139 CollocWt::operator = (const CollocWt& a) |
|
140 { |
|
141 n = a.n; |
|
142 inc_left = a.inc_left; |
|
143 inc_right = a.inc_right; |
|
144 lb = a.lb; |
|
145 rb = a.rb; |
|
146 r = a.r; |
|
147 q = a.q; |
|
148 A = a.A; |
|
149 B = a.B; |
|
150 |
|
151 nt = a.nt; |
|
152 |
|
153 initialized = a.initialized; |
|
154 |
|
155 return *this; |
|
156 } |
|
157 |
|
158 CollocWt& |
|
159 CollocWt::resize (int ncol) |
|
160 { |
|
161 n = ncol; |
|
162 initialized = 0; |
|
163 return *this; |
|
164 } |
|
165 |
|
166 CollocWt& |
|
167 CollocWt::add_left (void) |
|
168 { |
|
169 inc_left = 1; |
|
170 initialized = 0; |
|
171 return *this; |
|
172 } |
|
173 |
|
174 CollocWt& |
|
175 CollocWt::delete_left (void) |
|
176 { |
|
177 inc_left = 0; |
|
178 initialized = 0; |
|
179 return *this; |
|
180 } |
|
181 |
|
182 CollocWt& |
|
183 CollocWt::set_left (double val) |
|
184 { |
|
185 if (val >= rb) |
|
186 error ("left bound greater than right bound"); |
|
187 |
|
188 lb = val; |
|
189 initialized = 0; |
|
190 return *this; |
|
191 } |
|
192 |
|
193 CollocWt& |
|
194 CollocWt::add_right (void) |
|
195 { |
|
196 inc_right = 1; |
|
197 initialized = 0; |
|
198 return *this; |
|
199 } |
|
200 |
|
201 CollocWt& |
|
202 CollocWt::delete_right (void) |
|
203 { |
|
204 inc_right = 0; |
|
205 initialized = 0; |
|
206 return *this; |
|
207 } |
|
208 |
|
209 CollocWt& |
|
210 CollocWt::set_right (double val) |
|
211 { |
|
212 if (val <= lb) |
|
213 error ("right bound less than left bound"); |
|
214 |
|
215 rb = val; |
|
216 initialized = 0; |
|
217 return *this; |
|
218 } |
|
219 |
|
220 CollocWt& |
|
221 CollocWt::set_alpha (double val) |
|
222 { |
|
223 Alpha = val; |
|
224 initialized = 0; |
|
225 return *this; |
|
226 } |
|
227 |
|
228 CollocWt& |
|
229 CollocWt::set_beta (double val) |
|
230 { |
|
231 Beta = val; |
|
232 initialized = 0; |
|
233 return *this; |
|
234 } |
|
235 |
|
236 void |
|
237 CollocWt::init (void) |
|
238 { |
|
239 // Check for possible errors. |
|
240 |
|
241 double wid = rb - lb; |
|
242 if (wid <= 0.0) |
|
243 error ("width less than or equal to zero"); |
|
244 |
|
245 nt = n + inc_left + inc_right; |
|
246 if (nt < 0) |
|
247 error ("total number of collocation points less than zero"); |
|
248 else if (nt == 0) |
|
249 return; |
|
250 |
|
251 double *dif1 = new double [nt]; |
|
252 double *dif2 = new double [nt]; |
|
253 double *dif3 = new double [nt]; |
|
254 double *vect = new double [nt]; |
|
255 |
|
256 r.resize (nt); |
|
257 q.resize (nt); |
|
258 A.resize (nt, nt); |
|
259 B.resize (nt, nt); |
|
260 |
|
261 double *pr = r.fortran_vec (); |
|
262 |
|
263 // Compute roots. |
|
264 |
|
265 F77_FCN (jcobi) (&nt, &n, &inc_left, &inc_right, &Alpha, &Beta, |
|
266 dif1, dif2, dif3, pr); |
|
267 |
|
268 int id; |
|
269 int i, j; |
|
270 |
|
271 // First derivative weights. |
|
272 |
|
273 id = 1; |
|
274 for (i = 1; i <= nt; i++) |
|
275 { |
|
276 F77_FCN (dfopr) (&nt, &n, &inc_left, &inc_right, &i, &id, dif1, |
|
277 dif2, dif3, pr, vect); |
|
278 |
|
279 for (j = 0; j < nt; j++) |
|
280 A (i-1, j) = vect[j]; |
|
281 } |
|
282 |
|
283 // Second derivative weights. |
|
284 |
|
285 id = 2; |
|
286 for (i = 1; i <= nt; i++) |
|
287 { |
|
288 F77_FCN (dfopr) (&nt, &n, &inc_left, &inc_right, &i, &id, dif1, |
|
289 dif2, dif3, pr, vect); |
|
290 |
|
291 for (j = 0; j < nt; j++) |
|
292 B (i-1, j) = vect[j]; |
|
293 } |
|
294 |
|
295 // Gaussian quadrature weights. |
|
296 |
|
297 id = 3; |
|
298 double *pq = q.fortran_vec (); |
|
299 F77_FCN (dfopr) (&nt, &n, &inc_left, &inc_right, &i, &id, dif1, |
|
300 dif2, dif3, pr, pq); |
|
301 |
|
302 delete dif1; |
|
303 delete dif2; |
|
304 delete dif3; |
|
305 delete vect; |
|
306 |
|
307 initialized = 1; |
|
308 } |
|
309 |
|
310 ostream& |
|
311 operator << (ostream& os, const CollocWt& a) |
|
312 { |
|
313 if (a.left_included ()) |
|
314 os << "left boundary is included\n"; |
|
315 else |
|
316 os << "left boundary is not included\n"; |
|
317 |
|
318 if (a.right_included ()) |
|
319 os << "right boundary is included\n"; |
|
320 else |
|
321 os << "right boundary is not included\n"; |
|
322 |
|
323 os << "\n"; |
|
324 |
|
325 os << a.Alpha << " " << a.Beta << "\n\n" |
|
326 << a.r << "\n\n" |
|
327 << a.q << "\n\n" |
|
328 << a.A << "\n" |
|
329 << a.B << "\n"; |
|
330 |
|
331 return os; |
|
332 } |
|
333 |
|
334 /* |
|
335 ;;; Local Variables: *** |
|
336 ;;; mode: C++ *** |
|
337 ;;; page-delimiter: "^/\\*" *** |
|
338 ;;; End: *** |
|
339 */ |