7
|
1 // f-colloc.cc -*- C++ -*- |
1
|
2 /* |
|
3 |
1009
|
4 Copyright (C) 1993, 1994, 1995 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" |
544
|
33 #include "help.h" |
519
|
34 #include "defun-dld.h" |
1
|
35 |
701
|
36 DEFUN_DLD_BUILTIN ("colloc", Fcolloc, Scolloc, 7, 4, |
519
|
37 "[R, A, B, Q] = colloc (N [, \"left\"] [, \"right\"]): collocation weights") |
1
|
38 { |
497
|
39 Octave_object retval; |
1
|
40 |
506
|
41 int nargin = args.length (); |
|
42 |
712
|
43 if (nargin < 1 || nargin > 3) |
519
|
44 { |
|
45 print_usage ("colloc"); |
|
46 return retval; |
|
47 } |
|
48 |
712
|
49 if (! args(0).is_scalar_type ()) |
1
|
50 { |
216
|
51 error ("colloc: first argument must be a scalar"); |
1
|
52 return retval; |
|
53 } |
|
54 |
712
|
55 double tmp = args(0).double_value (); |
636
|
56 |
|
57 if (error_state) |
|
58 return retval; |
|
59 |
|
60 int ncol = NINT (tmp); |
1
|
61 if (ncol < 0) |
|
62 { |
216
|
63 error ("colloc: first argument must be non-negative"); |
1
|
64 return retval; |
|
65 } |
|
66 |
|
67 int ntot = ncol; |
|
68 int left = 0; |
|
69 int right = 0; |
|
70 |
712
|
71 for (int i = 1; i < nargin; i++) |
1
|
72 { |
497
|
73 if (args(i).is_defined ()) |
1
|
74 { |
610
|
75 if (! args(i).is_string ()) |
1
|
76 { |
216
|
77 error ("colloc: expecting string argument"); |
1
|
78 return retval; |
|
79 } |
|
80 |
497
|
81 char *s = args(i).string_value (); |
636
|
82 |
519
|
83 if (s && (((*s == 'R' || *s == 'r') && strlen (s) == 1) |
|
84 || strcmp (s, "right") == 0)) |
1
|
85 { |
|
86 right = 1; |
|
87 } |
519
|
88 else if (s && (((*s == 'L' || *s == 'l') && strlen (s) == 1) |
|
89 || strcmp (s, "left") == 0)) |
1
|
90 { |
|
91 left = 1; |
|
92 } |
|
93 else |
|
94 { |
216
|
95 error ("colloc: unrecognized argument"); |
1
|
96 return retval; |
|
97 } |
|
98 } |
|
99 else |
|
100 { |
216
|
101 error ("colloc: unexpected NULL argument"); |
1
|
102 return retval; |
|
103 } |
|
104 } |
|
105 |
|
106 ntot += left + right; |
|
107 if (ntot < 1) |
216
|
108 { |
|
109 error ("colloc: the total number of roots must be positive"); |
|
110 return retval; |
|
111 } |
1
|
112 |
|
113 CollocWt wts (ncol, left, right); |
|
114 |
|
115 ColumnVector r = wts.roots (); |
|
116 Matrix A = wts.first (); |
|
117 Matrix B = wts.second (); |
|
118 ColumnVector q = wts.quad_weights (); |
|
119 |
636
|
120 retval(3) = q; |
|
121 retval(2) = B; |
|
122 retval(1) = A; |
516
|
123 retval(0) = r; |
1
|
124 |
|
125 return retval; |
|
126 } |
|
127 |
|
128 /* |
|
129 ;;; Local Variables: *** |
|
130 ;;; mode: C++ *** |
|
131 ;;; page-delimiter: "^/\\*" *** |
|
132 ;;; End: *** |
|
133 */ |
|
134 |