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 |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
3
|
21 |
|
22 */ |
|
23 |
238
|
24 #ifdef HAVE_CONFIG_H |
1192
|
25 #include <config.h> |
3
|
26 #endif |
|
27 |
3503
|
28 #include <iostream> |
238
|
29 |
3
|
30 #include "CollocWt.h" |
1847
|
31 #include "f77-fcn.h" |
227
|
32 #include "lo-error.h" |
3
|
33 |
|
34 extern "C" |
|
35 { |
4552
|
36 F77_RET_T |
5275
|
37 F77_FUNC (jcobi, JCOBI) (octave_idx_type&, octave_idx_type&, octave_idx_type&, octave_idx_type&, double&, |
4552
|
38 double&, double*, double*, double*, |
|
39 double*); |
3
|
40 |
4552
|
41 F77_RET_T |
5275
|
42 F77_FUNC (dfopr, DFOPR) (octave_idx_type&, octave_idx_type&, octave_idx_type&, octave_idx_type&, octave_idx_type&, octave_idx_type&, |
4552
|
43 double*, double*, double*, double*, |
|
44 double*); |
3
|
45 } |
|
46 |
|
47 // Error handling. |
|
48 |
|
49 void |
|
50 CollocWt::error (const char* msg) |
|
51 { |
227
|
52 (*current_liboctave_error_handler) ("fatal CollocWt error: %s", msg); |
3
|
53 } |
|
54 |
|
55 CollocWt& |
|
56 CollocWt::set_left (double val) |
|
57 { |
|
58 if (val >= rb) |
227
|
59 { |
|
60 error ("left bound greater than right bound"); |
|
61 return *this; |
|
62 } |
3
|
63 |
|
64 lb = val; |
|
65 initialized = 0; |
|
66 return *this; |
|
67 } |
|
68 |
|
69 CollocWt& |
|
70 CollocWt::set_right (double val) |
|
71 { |
|
72 if (val <= lb) |
227
|
73 { |
|
74 error ("right bound less than left bound"); |
|
75 return *this; |
|
76 } |
3
|
77 |
|
78 rb = val; |
|
79 initialized = 0; |
|
80 return *this; |
|
81 } |
|
82 |
|
83 void |
|
84 CollocWt::init (void) |
|
85 { |
1360
|
86 // Check for possible errors. |
3
|
87 |
|
88 double wid = rb - lb; |
|
89 if (wid <= 0.0) |
227
|
90 { |
|
91 error ("width less than or equal to zero"); |
|
92 return; |
|
93 } |
3
|
94 |
5275
|
95 octave_idx_type nt = n + inc_left + inc_right; |
1870
|
96 |
3
|
97 if (nt < 0) |
227
|
98 { |
|
99 error ("total number of collocation points less than zero"); |
|
100 return; |
|
101 } |
3
|
102 else if (nt == 0) |
|
103 return; |
|
104 |
1938
|
105 Array<double> dif1 (nt); |
|
106 double *pdif1 = dif1.fortran_vec (); |
|
107 |
|
108 Array<double> dif2 (nt); |
|
109 double *pdif2 = dif2.fortran_vec (); |
|
110 |
|
111 Array<double> dif3 (nt); |
|
112 double *pdif3 = dif3.fortran_vec (); |
|
113 |
|
114 Array<double> vect (nt); |
|
115 double *pvect = vect.fortran_vec (); |
3
|
116 |
|
117 r.resize (nt); |
|
118 q.resize (nt); |
|
119 A.resize (nt, nt); |
|
120 B.resize (nt, nt); |
|
121 |
|
122 double *pr = r.fortran_vec (); |
|
123 |
1360
|
124 // Compute roots. |
3
|
125 |
3887
|
126 F77_FUNC (jcobi, JCOBI) (nt, n, inc_left, inc_right, Alpha, Beta, |
1938
|
127 pdif1, pdif2, pdif3, pr); |
3
|
128 |
5275
|
129 octave_idx_type id; |
3
|
130 |
1360
|
131 // First derivative weights. |
3
|
132 |
|
133 id = 1; |
5275
|
134 for (octave_idx_type i = 1; i <= nt; i++) |
3
|
135 { |
3887
|
136 F77_FUNC (dfopr, DFOPR) (nt, n, inc_left, inc_right, i, id, pdif1, |
1938
|
137 pdif2, pdif3, pr, pvect); |
3
|
138 |
5275
|
139 for (octave_idx_type j = 0; j < nt; j++) |
1938
|
140 A (i-1, j) = vect.elem (j); |
3
|
141 } |
|
142 |
1360
|
143 // Second derivative weights. |
3
|
144 |
|
145 id = 2; |
5275
|
146 for (octave_idx_type i = 1; i <= nt; i++) |
3
|
147 { |
3887
|
148 F77_FUNC (dfopr, DFOPR) (nt, n, inc_left, inc_right, i, id, pdif1, |
1938
|
149 pdif2, pdif3, pr, pvect); |
3
|
150 |
5275
|
151 for (octave_idx_type j = 0; j < nt; j++) |
1938
|
152 B (i-1, j) = vect.elem (j); |
3
|
153 } |
|
154 |
1360
|
155 // Gaussian quadrature weights. |
3
|
156 |
|
157 id = 3; |
|
158 double *pq = q.fortran_vec (); |
3887
|
159 F77_FUNC (dfopr, DFOPR) (nt, n, inc_left, inc_right, id, id, pdif1, |
1938
|
160 pdif2, pdif3, pr, pq); |
3
|
161 |
|
162 initialized = 1; |
|
163 } |
|
164 |
3504
|
165 std::ostream& |
|
166 operator << (std::ostream& os, const CollocWt& a) |
3
|
167 { |
|
168 if (a.left_included ()) |
|
169 os << "left boundary is included\n"; |
|
170 else |
|
171 os << "left boundary is not included\n"; |
|
172 |
|
173 if (a.right_included ()) |
|
174 os << "right boundary is included\n"; |
|
175 else |
|
176 os << "right boundary is not included\n"; |
|
177 |
|
178 os << "\n"; |
|
179 |
|
180 os << a.Alpha << " " << a.Beta << "\n\n" |
|
181 << a.r << "\n\n" |
|
182 << a.q << "\n\n" |
|
183 << a.A << "\n" |
|
184 << a.B << "\n"; |
|
185 |
|
186 return os; |
|
187 } |
|
188 |
|
189 /* |
|
190 ;;; Local Variables: *** |
|
191 ;;; mode: C++ *** |
|
192 ;;; End: *** |
|
193 */ |