Mercurial > hg > octave-lyh
annotate liboctave/CollocWt.cc @ 10351:5150ceb4dbb4
base charMatrix and boolMatrix on Array<char>
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Tue, 23 Feb 2010 14:15:34 +0100 |
parents | 12884915a8e4 |
children | d909c4c14b63 |
rev | line source |
---|---|
3 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1993, 1994, 1995, 1996, 1997, 2000, 2002, 2003, 2004, |
4 2005, 2007 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 | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
3 | 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 | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
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&, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
38 double&, double*, double*, double*, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
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&, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
43 double*, double*, double*, double*, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
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 | |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
105 Array<double> dif1 (nt, 1); |
1938 | 106 double *pdif1 = dif1.fortran_vec (); |
107 | |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
108 Array<double> dif2 (nt, 1); |
1938 | 109 double *pdif2 = dif2.fortran_vec (); |
110 | |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
111 Array<double> dif3 (nt, 1); |
1938 | 112 double *pdif3 = dif3.fortran_vec (); |
113 | |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
114 Array<double> vect (nt, 1); |
1938 | 115 double *pvect = vect.fortran_vec (); |
3 | 116 |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
117 r.resize (nt, 1); |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
118 q.resize (nt, 1); |
3 | 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, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
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, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
137 pdif2, pdif3, pr, pvect); |
3 | 138 |
5275 | 139 for (octave_idx_type j = 0; j < nt; j++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
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, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
149 pdif2, pdif3, pr, pvect); |
3 | 150 |
5275 | 151 for (octave_idx_type j = 0; j < nt; j++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
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, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
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 } |