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