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" |
227
|
31 #include "lo-error.h" |
3
|
32 |
|
33 extern "C" |
|
34 { |
|
35 int F77_FCN (jcobi) (int*, int*, int*, int*, double*, double*, |
|
36 double*, double*, double*, double*); |
|
37 |
|
38 int F77_FCN (dfopr) (int*, int*, int*, int*, int*, int*, |
|
39 double*, double*, double*, double*, double*); |
|
40 } |
|
41 |
|
42 // Error handling. |
|
43 |
|
44 void |
|
45 CollocWt::error (const char* msg) |
|
46 { |
227
|
47 (*current_liboctave_error_handler) ("fatal CollocWt error: %s", msg); |
3
|
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) |
227
|
186 { |
|
187 error ("left bound greater than right bound"); |
|
188 return *this; |
|
189 } |
3
|
190 |
|
191 lb = val; |
|
192 initialized = 0; |
|
193 return *this; |
|
194 } |
|
195 |
|
196 CollocWt& |
|
197 CollocWt::add_right (void) |
|
198 { |
|
199 inc_right = 1; |
|
200 initialized = 0; |
|
201 return *this; |
|
202 } |
|
203 |
|
204 CollocWt& |
|
205 CollocWt::delete_right (void) |
|
206 { |
|
207 inc_right = 0; |
|
208 initialized = 0; |
|
209 return *this; |
|
210 } |
|
211 |
|
212 CollocWt& |
|
213 CollocWt::set_right (double val) |
|
214 { |
|
215 if (val <= lb) |
227
|
216 { |
|
217 error ("right bound less than left bound"); |
|
218 return *this; |
|
219 } |
3
|
220 |
|
221 rb = val; |
|
222 initialized = 0; |
|
223 return *this; |
|
224 } |
|
225 |
|
226 CollocWt& |
|
227 CollocWt::set_alpha (double val) |
|
228 { |
|
229 Alpha = val; |
|
230 initialized = 0; |
|
231 return *this; |
|
232 } |
|
233 |
|
234 CollocWt& |
|
235 CollocWt::set_beta (double val) |
|
236 { |
|
237 Beta = val; |
|
238 initialized = 0; |
|
239 return *this; |
|
240 } |
|
241 |
|
242 void |
|
243 CollocWt::init (void) |
|
244 { |
|
245 // Check for possible errors. |
|
246 |
|
247 double wid = rb - lb; |
|
248 if (wid <= 0.0) |
227
|
249 { |
|
250 error ("width less than or equal to zero"); |
|
251 return; |
|
252 } |
3
|
253 |
|
254 nt = n + inc_left + inc_right; |
|
255 if (nt < 0) |
227
|
256 { |
|
257 error ("total number of collocation points less than zero"); |
|
258 return; |
|
259 } |
3
|
260 else if (nt == 0) |
|
261 return; |
|
262 |
|
263 double *dif1 = new double [nt]; |
|
264 double *dif2 = new double [nt]; |
|
265 double *dif3 = new double [nt]; |
|
266 double *vect = new double [nt]; |
|
267 |
|
268 r.resize (nt); |
|
269 q.resize (nt); |
|
270 A.resize (nt, nt); |
|
271 B.resize (nt, nt); |
|
272 |
|
273 double *pr = r.fortran_vec (); |
|
274 |
|
275 // Compute roots. |
|
276 |
|
277 F77_FCN (jcobi) (&nt, &n, &inc_left, &inc_right, &Alpha, &Beta, |
|
278 dif1, dif2, dif3, pr); |
|
279 |
|
280 int id; |
|
281 int i, j; |
|
282 |
|
283 // First derivative weights. |
|
284 |
|
285 id = 1; |
|
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 A (i-1, j) = vect[j]; |
|
293 } |
|
294 |
|
295 // Second derivative weights. |
|
296 |
|
297 id = 2; |
|
298 for (i = 1; i <= nt; i++) |
|
299 { |
|
300 F77_FCN (dfopr) (&nt, &n, &inc_left, &inc_right, &i, &id, dif1, |
|
301 dif2, dif3, pr, vect); |
|
302 |
|
303 for (j = 0; j < nt; j++) |
|
304 B (i-1, j) = vect[j]; |
|
305 } |
|
306 |
|
307 // Gaussian quadrature weights. |
|
308 |
|
309 id = 3; |
|
310 double *pq = q.fortran_vec (); |
|
311 F77_FCN (dfopr) (&nt, &n, &inc_left, &inc_right, &i, &id, dif1, |
|
312 dif2, dif3, pr, pq); |
|
313 |
|
314 delete dif1; |
|
315 delete dif2; |
|
316 delete dif3; |
|
317 delete vect; |
|
318 |
|
319 initialized = 1; |
|
320 } |
|
321 |
|
322 ostream& |
|
323 operator << (ostream& os, const CollocWt& a) |
|
324 { |
|
325 if (a.left_included ()) |
|
326 os << "left boundary is included\n"; |
|
327 else |
|
328 os << "left boundary is not included\n"; |
|
329 |
|
330 if (a.right_included ()) |
|
331 os << "right boundary is included\n"; |
|
332 else |
|
333 os << "right boundary is not included\n"; |
|
334 |
|
335 os << "\n"; |
|
336 |
|
337 os << a.Alpha << " " << a.Beta << "\n\n" |
|
338 << a.r << "\n\n" |
|
339 << a.q << "\n\n" |
|
340 << a.A << "\n" |
|
341 << a.B << "\n"; |
|
342 |
|
343 return os; |
|
344 } |
|
345 |
|
346 /* |
|
347 ;;; Local Variables: *** |
|
348 ;;; mode: C++ *** |
|
349 ;;; page-delimiter: "^/\\*" *** |
|
350 ;;; End: *** |
|
351 */ |