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