3
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
3
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
1315
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
3
|
20 |
|
21 */ |
|
22 |
4192
|
23 #if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) |
1296
|
24 #pragma implementation |
|
25 #endif |
|
26 |
238
|
27 #ifdef HAVE_CONFIG_H |
1192
|
28 #include <config.h> |
3
|
29 #endif |
|
30 |
3503
|
31 #include <iostream> |
238
|
32 |
3
|
33 #include "CollocWt.h" |
1847
|
34 #include "f77-fcn.h" |
227
|
35 #include "lo-error.h" |
3
|
36 |
|
37 extern "C" |
|
38 { |
4552
|
39 F77_RET_T |
|
40 F77_FUNC (jcobi, JCOBI) (int&, int&, int&, int&, double&, |
|
41 double&, double*, double*, double*, |
|
42 double*); |
3
|
43 |
4552
|
44 F77_RET_T |
|
45 F77_FUNC (dfopr, DFOPR) (int&, int&, int&, int&, int&, int&, |
|
46 double*, double*, double*, double*, |
|
47 double*); |
3
|
48 } |
|
49 |
|
50 // Error handling. |
|
51 |
|
52 void |
|
53 CollocWt::error (const char* msg) |
|
54 { |
227
|
55 (*current_liboctave_error_handler) ("fatal CollocWt error: %s", msg); |
3
|
56 } |
|
57 |
|
58 CollocWt& |
|
59 CollocWt::set_left (double val) |
|
60 { |
|
61 if (val >= rb) |
227
|
62 { |
|
63 error ("left bound greater than right bound"); |
|
64 return *this; |
|
65 } |
3
|
66 |
|
67 lb = val; |
|
68 initialized = 0; |
|
69 return *this; |
|
70 } |
|
71 |
|
72 CollocWt& |
|
73 CollocWt::set_right (double val) |
|
74 { |
|
75 if (val <= lb) |
227
|
76 { |
|
77 error ("right bound less than left bound"); |
|
78 return *this; |
|
79 } |
3
|
80 |
|
81 rb = val; |
|
82 initialized = 0; |
|
83 return *this; |
|
84 } |
|
85 |
|
86 void |
|
87 CollocWt::init (void) |
|
88 { |
1360
|
89 // Check for possible errors. |
3
|
90 |
|
91 double wid = rb - lb; |
|
92 if (wid <= 0.0) |
227
|
93 { |
|
94 error ("width less than or equal to zero"); |
|
95 return; |
|
96 } |
3
|
97 |
1870
|
98 int nt = n + inc_left + inc_right; |
|
99 |
3
|
100 if (nt < 0) |
227
|
101 { |
|
102 error ("total number of collocation points less than zero"); |
|
103 return; |
|
104 } |
3
|
105 else if (nt == 0) |
|
106 return; |
|
107 |
1938
|
108 Array<double> dif1 (nt); |
|
109 double *pdif1 = dif1.fortran_vec (); |
|
110 |
|
111 Array<double> dif2 (nt); |
|
112 double *pdif2 = dif2.fortran_vec (); |
|
113 |
|
114 Array<double> dif3 (nt); |
|
115 double *pdif3 = dif3.fortran_vec (); |
|
116 |
|
117 Array<double> vect (nt); |
|
118 double *pvect = vect.fortran_vec (); |
3
|
119 |
|
120 r.resize (nt); |
|
121 q.resize (nt); |
|
122 A.resize (nt, nt); |
|
123 B.resize (nt, nt); |
|
124 |
|
125 double *pr = r.fortran_vec (); |
|
126 |
1360
|
127 // Compute roots. |
3
|
128 |
3887
|
129 F77_FUNC (jcobi, JCOBI) (nt, n, inc_left, inc_right, Alpha, Beta, |
1938
|
130 pdif1, pdif2, pdif3, pr); |
3
|
131 |
|
132 int id; |
|
133 |
1360
|
134 // First derivative weights. |
3
|
135 |
|
136 id = 1; |
1321
|
137 for (int i = 1; i <= nt; i++) |
3
|
138 { |
3887
|
139 F77_FUNC (dfopr, DFOPR) (nt, n, inc_left, inc_right, i, id, pdif1, |
1938
|
140 pdif2, pdif3, pr, pvect); |
3
|
141 |
1321
|
142 for (int j = 0; j < nt; j++) |
1938
|
143 A (i-1, j) = vect.elem (j); |
3
|
144 } |
|
145 |
1360
|
146 // Second derivative weights. |
3
|
147 |
|
148 id = 2; |
1321
|
149 for (int i = 1; i <= nt; i++) |
3
|
150 { |
3887
|
151 F77_FUNC (dfopr, DFOPR) (nt, n, inc_left, inc_right, i, id, pdif1, |
1938
|
152 pdif2, pdif3, pr, pvect); |
3
|
153 |
1321
|
154 for (int j = 0; j < nt; j++) |
1938
|
155 B (i-1, j) = vect.elem (j); |
3
|
156 } |
|
157 |
1360
|
158 // Gaussian quadrature weights. |
3
|
159 |
|
160 id = 3; |
|
161 double *pq = q.fortran_vec (); |
3887
|
162 F77_FUNC (dfopr, DFOPR) (nt, n, inc_left, inc_right, id, id, pdif1, |
1938
|
163 pdif2, pdif3, pr, pq); |
3
|
164 |
|
165 initialized = 1; |
|
166 } |
|
167 |
3504
|
168 std::ostream& |
|
169 operator << (std::ostream& os, const CollocWt& a) |
3
|
170 { |
|
171 if (a.left_included ()) |
|
172 os << "left boundary is included\n"; |
|
173 else |
|
174 os << "left boundary is not included\n"; |
|
175 |
|
176 if (a.right_included ()) |
|
177 os << "right boundary is included\n"; |
|
178 else |
|
179 os << "right boundary is not included\n"; |
|
180 |
|
181 os << "\n"; |
|
182 |
|
183 os << a.Alpha << " " << a.Beta << "\n\n" |
|
184 << a.r << "\n\n" |
|
185 << a.q << "\n\n" |
|
186 << a.A << "\n" |
|
187 << a.B << "\n"; |
|
188 |
|
189 return os; |
|
190 } |
|
191 |
|
192 /* |
|
193 ;;; Local Variables: *** |
|
194 ;;; mode: C++ *** |
|
195 ;;; End: *** |
|
196 */ |