2928
|
1 /* |
|
2 |
|
3 Copyright (C) 1996, 1997 John W. Eaton |
|
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. |
2928
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include <config.h> |
|
26 #endif |
|
27 |
|
28 #include <string> |
|
29 |
|
30 #include "CollocWt.h" |
|
31 #include "lo-mappers.h" |
|
32 |
|
33 #include "defun-dld.h" |
|
34 #include "error.h" |
|
35 #include "oct-obj.h" |
|
36 #include "utils.h" |
|
37 |
|
38 DEFUN_DLD (colloc, args, , |
3368
|
39 "-*- texinfo -*-\n\ |
3499
|
40 @deftypefn {Loadable Function} {[@var{r}, @var{amat}, @var{bmat}, @var{q}] =} colloc (@var{n}, \"left\", \"right\")\n\ |
3368
|
41 Compute derivative and integral weight matrices for orthogonal\n\ |
|
42 collocation using the subroutines given in J. Villadsen and\n\ |
|
43 M. L. Michelsen, @cite{Solution of Differential Equation Models by\n\ |
|
44 Polynomial Approximation}.\n\ |
|
45 @end deftypefn") |
2928
|
46 { |
|
47 octave_value_list retval; |
|
48 |
|
49 int nargin = args.length (); |
|
50 |
|
51 if (nargin < 1 || nargin > 3) |
|
52 { |
5823
|
53 print_usage (); |
2928
|
54 return retval; |
|
55 } |
|
56 |
|
57 if (! args(0).is_scalar_type ()) |
|
58 { |
|
59 error ("colloc: first argument must be a scalar"); |
|
60 return retval; |
|
61 } |
|
62 |
|
63 double tmp = args(0).double_value (); |
|
64 |
|
65 if (error_state) |
|
66 return retval; |
|
67 |
|
68 if (xisnan (tmp)) |
|
69 { |
|
70 error ("colloc: NaN is invalid as NCOL"); |
|
71 return retval; |
|
72 } |
|
73 |
5275
|
74 octave_idx_type ncol = NINTbig (tmp); |
2928
|
75 if (ncol < 0) |
|
76 { |
|
77 error ("colloc: first argument must be non-negative"); |
|
78 return retval; |
|
79 } |
|
80 |
5275
|
81 octave_idx_type ntot = ncol; |
|
82 octave_idx_type left = 0; |
|
83 octave_idx_type right = 0; |
2928
|
84 |
|
85 for (int i = 1; i < nargin; i++) |
|
86 { |
|
87 if (args(i).is_defined ()) |
|
88 { |
|
89 if (! args(i).is_string ()) |
|
90 { |
|
91 error ("colloc: expecting string argument"); |
|
92 return retval; |
|
93 } |
|
94 |
3523
|
95 std::string s = args(i).string_value (); |
2928
|
96 |
|
97 if ((s.length () == 1 && (s[0] == 'R' || s[0] == 'r')) |
|
98 || s == "right") |
|
99 { |
|
100 right = 1; |
|
101 } |
|
102 else if ((s.length () == 1 && (s[0] == 'L' || s[0] == 'l')) |
|
103 || s == "left") |
|
104 { |
|
105 left = 1; |
|
106 } |
|
107 else |
|
108 { |
|
109 error ("colloc: unrecognized argument"); |
|
110 return retval; |
|
111 } |
|
112 } |
|
113 else |
|
114 { |
|
115 error ("colloc: unexpected empty argument"); |
|
116 return retval; |
|
117 } |
|
118 } |
|
119 |
|
120 ntot += left + right; |
|
121 if (ntot < 1) |
|
122 { |
|
123 error ("colloc: the total number of roots must be positive"); |
|
124 return retval; |
|
125 } |
|
126 |
|
127 CollocWt wts (ncol, left, right); |
|
128 |
|
129 ColumnVector r = wts.roots (); |
|
130 Matrix A = wts.first (); |
|
131 Matrix B = wts.second (); |
|
132 ColumnVector q = wts.quad_weights (); |
|
133 |
|
134 retval(3) = q; |
|
135 retval(2) = B; |
|
136 retval(1) = A; |
|
137 retval(0) = r; |
|
138 |
|
139 return retval; |
|
140 } |
|
141 |
|
142 /* |
|
143 ;;; Local Variables: *** |
|
144 ;;; mode: C++ *** |
|
145 ;;; End: *** |
|
146 */ |
|
147 |