7
|
1 // f-colloc.cc -*- C++ -*- |
1
|
2 /* |
|
3 |
497
|
4 Copyright (C) 1993, 1994 John W. Eaton |
1
|
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 |
|
10 Free Software Foundation; either version 2, or (at your option) any |
|
11 later version. |
|
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 |
|
19 along with Octave; see the file COPYING. If not, write to the Free |
|
20 Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
21 |
|
22 */ |
|
23 |
240
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include "config.h" |
1
|
26 #endif |
|
27 |
|
28 #include "CollocWt.h" |
|
29 |
|
30 #include "tree-const.h" |
|
31 #include "error.h" |
|
32 #include "utils.h" |
519
|
33 #include "defun-dld.h" |
1
|
34 |
519
|
35 DEFUN_DLD ("colloc", Fcolloc, Scolloc, 7, 4, |
|
36 "[R, A, B, Q] = colloc (N [, \"left\"] [, \"right\"]): collocation weights") |
1
|
37 { |
497
|
38 Octave_object retval; |
1
|
39 |
506
|
40 int nargin = args.length (); |
|
41 |
519
|
42 if (nargin < 2 || nargin > 4) |
|
43 { |
|
44 print_usage ("colloc"); |
|
45 return retval; |
|
46 } |
|
47 |
497
|
48 if (args(1).const_type () != tree_constant_rep::complex_scalar_constant |
|
49 && args(1).const_type () != tree_constant_rep::scalar_constant) |
1
|
50 { |
216
|
51 error ("colloc: first argument must be a scalar"); |
1
|
52 return retval; |
|
53 } |
|
54 |
497
|
55 int ncol = NINT (args(1).double_value ()); |
1
|
56 if (ncol < 0) |
|
57 { |
216
|
58 error ("colloc: first argument must be non-negative"); |
1
|
59 return retval; |
|
60 } |
|
61 |
|
62 int ntot = ncol; |
|
63 int left = 0; |
|
64 int right = 0; |
|
65 |
|
66 for (int i = 2; i < nargin; i++) |
|
67 { |
497
|
68 if (args(i).is_defined ()) |
1
|
69 { |
497
|
70 if (! args(i).is_string_type ()) |
1
|
71 { |
216
|
72 error ("colloc: expecting string argument"); |
1
|
73 return retval; |
|
74 } |
|
75 |
497
|
76 char *s = args(i).string_value (); |
519
|
77 if (s && (((*s == 'R' || *s == 'r') && strlen (s) == 1) |
|
78 || strcmp (s, "right") == 0)) |
1
|
79 { |
|
80 right = 1; |
|
81 } |
519
|
82 else if (s && (((*s == 'L' || *s == 'l') && strlen (s) == 1) |
|
83 || strcmp (s, "left") == 0)) |
1
|
84 { |
|
85 left = 1; |
|
86 } |
|
87 else |
|
88 { |
216
|
89 error ("colloc: unrecognized argument"); |
1
|
90 return retval; |
|
91 } |
|
92 } |
|
93 else |
|
94 { |
216
|
95 error ("colloc: unexpected NULL argument"); |
1
|
96 return retval; |
|
97 } |
|
98 } |
|
99 |
|
100 ntot += left + right; |
|
101 if (ntot < 1) |
216
|
102 { |
|
103 error ("colloc: the total number of roots must be positive"); |
|
104 return retval; |
|
105 } |
1
|
106 |
|
107 CollocWt wts (ncol, left, right); |
|
108 |
|
109 ColumnVector r = wts.roots (); |
|
110 Matrix A = wts.first (); |
|
111 Matrix B = wts.second (); |
|
112 ColumnVector q = wts.quad_weights (); |
|
113 |
497
|
114 retval.resize (4); |
1
|
115 |
516
|
116 retval(0) = r; |
|
117 retval(1) = A; |
|
118 retval(2) = B; |
|
119 retval(3) = q; |
1
|
120 |
|
121 return retval; |
|
122 } |
|
123 |
|
124 /* |
|
125 ;;; Local Variables: *** |
|
126 ;;; mode: C++ *** |
|
127 ;;; page-delimiter: "^/\\*" *** |
|
128 ;;; End: *** |
|
129 */ |
|
130 |