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