1
|
1 /* |
|
2 |
1884
|
3 Copyright (C) 1996 John W. Eaton |
1
|
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. |
1
|
20 |
|
21 */ |
|
22 |
240
|
23 #ifdef HAVE_CONFIG_H |
1192
|
24 #include <config.h> |
1
|
25 #endif |
|
26 |
1728
|
27 #include <string> |
|
28 |
1
|
29 #include "CollocWt.h" |
|
30 |
1352
|
31 #include "defun-dld.h" |
|
32 #include "error.h" |
|
33 #include "help.h" |
1740
|
34 #include "mappers.h" |
|
35 #include "oct-obj.h" |
1
|
36 #include "utils.h" |
|
37 |
2465
|
38 DEFUN_DLD (colloc, args, , |
519
|
39 "[R, A, B, Q] = colloc (N [, \"left\"] [, \"right\"]): collocation weights") |
1
|
40 { |
2086
|
41 octave_value_list retval; |
1
|
42 |
506
|
43 int nargin = args.length (); |
|
44 |
712
|
45 if (nargin < 1 || nargin > 3) |
519
|
46 { |
|
47 print_usage ("colloc"); |
|
48 return retval; |
|
49 } |
|
50 |
712
|
51 if (! args(0).is_scalar_type ()) |
1
|
52 { |
216
|
53 error ("colloc: first argument must be a scalar"); |
1
|
54 return retval; |
|
55 } |
|
56 |
712
|
57 double tmp = args(0).double_value (); |
636
|
58 |
|
59 if (error_state) |
|
60 return retval; |
|
61 |
1086
|
62 if (xisnan (tmp)) |
|
63 { |
|
64 error ("colloc: NaN is invalid as NCOL"); |
|
65 return retval; |
|
66 } |
|
67 |
636
|
68 int ncol = NINT (tmp); |
1
|
69 if (ncol < 0) |
|
70 { |
216
|
71 error ("colloc: first argument must be non-negative"); |
1
|
72 return retval; |
|
73 } |
|
74 |
|
75 int ntot = ncol; |
|
76 int left = 0; |
|
77 int right = 0; |
|
78 |
712
|
79 for (int i = 1; i < nargin; i++) |
1
|
80 { |
497
|
81 if (args(i).is_defined ()) |
1
|
82 { |
610
|
83 if (! args(i).is_string ()) |
1
|
84 { |
216
|
85 error ("colloc: expecting string argument"); |
1
|
86 return retval; |
|
87 } |
|
88 |
1755
|
89 string s = args(i).string_value (); |
636
|
90 |
1755
|
91 if ((s.length () == 1 && (s[0] == 'R' || s[0] == 'r')) |
|
92 || s == "right") |
1
|
93 { |
|
94 right = 1; |
|
95 } |
1755
|
96 else if ((s.length () == 1 && (s[0] == 'L' || s[0] == 'l')) |
|
97 || s == "left") |
1
|
98 { |
|
99 left = 1; |
|
100 } |
|
101 else |
|
102 { |
216
|
103 error ("colloc: unrecognized argument"); |
1
|
104 return retval; |
|
105 } |
|
106 } |
|
107 else |
|
108 { |
1755
|
109 error ("colloc: unexpected empty argument"); |
1
|
110 return retval; |
|
111 } |
|
112 } |
|
113 |
|
114 ntot += left + right; |
|
115 if (ntot < 1) |
216
|
116 { |
|
117 error ("colloc: the total number of roots must be positive"); |
|
118 return retval; |
|
119 } |
1
|
120 |
|
121 CollocWt wts (ncol, left, right); |
|
122 |
|
123 ColumnVector r = wts.roots (); |
|
124 Matrix A = wts.first (); |
|
125 Matrix B = wts.second (); |
|
126 ColumnVector q = wts.quad_weights (); |
|
127 |
636
|
128 retval(3) = q; |
|
129 retval(2) = B; |
|
130 retval(1) = A; |
516
|
131 retval(0) = r; |
1
|
132 |
|
133 return retval; |
|
134 } |
|
135 |
|
136 /* |
|
137 ;;; Local Variables: *** |
|
138 ;;; mode: C++ *** |
|
139 ;;; End: *** |
|
140 */ |
|
141 |