Mercurial > octave-nkf
annotate libinterp/corefcn/colloc.cc @ 20617:ba2b07c13913
use new string_value method to handle value extraction errors
* __dispatch__.cc, balance.cc, colloc.cc, conv2.cc, data.cc, debug.cc,
graphics.cc, input.cc, matrix_type.cc, oct-hist.cc, schur.cc,
spparms.cc, symtab.cc, sysdep.cc, toplev.cc, utils.cc:
Use new string_value method.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 09 Oct 2015 10:06:39 -0400 |
parents | f90c8372b7ba |
children |
rev | line source |
---|---|
2928 | 1 /* |
2 | |
19731
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19074
diff
changeset
|
3 Copyright (C) 1996-2015 John W. Eaton |
2928 | 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 | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
2928 | 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 | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
2928 | 20 |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
25 #endif | |
26 | |
27 #include <string> | |
28 | |
29 #include "CollocWt.h" | |
30 #include "lo-mappers.h" | |
31 | |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
32 #include "defun.h" |
2928 | 33 #include "error.h" |
34 #include "oct-obj.h" | |
35 #include "utils.h" | |
36 | |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
37 DEFUN (colloc, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
38 "-*- texinfo -*-\n\ |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
39 @deftypefn {Built-in Function} {[@var{r}, @var{amat}, @var{bmat}, @var{q}] =} colloc (@var{n}, \"left\", \"right\")\n\ |
20207
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19731
diff
changeset
|
40 Compute derivative and integral weight matrices for orthogonal collocation.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19731
diff
changeset
|
41 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19731
diff
changeset
|
42 Reference: @nospell{J. Villadsen}, @nospell{M. L. Michelsen},\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19731
diff
changeset
|
43 @cite{Solution of Differential Equation Models by Polynomial Approximation}.\n\ |
3368 | 44 @end deftypefn") |
2928 | 45 { |
46 octave_value_list retval; | |
47 | |
48 int nargin = args.length (); | |
49 | |
50 if (nargin < 1 || nargin > 3) | |
51 { | |
5823 | 52 print_usage (); |
2928 | 53 return retval; |
54 } | |
55 | |
56 if (! args(0).is_scalar_type ()) | |
57 { | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
58 error ("colloc: N must be a scalar"); |
2928 | 59 return retval; |
60 } | |
61 | |
62 double tmp = args(0).double_value (); | |
63 | |
64 if (xisnan (tmp)) | |
65 { | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
66 error ("colloc: N cannot be NaN"); |
2928 | 67 return retval; |
68 } | |
69 | |
5275 | 70 octave_idx_type ncol = NINTbig (tmp); |
2928 | 71 if (ncol < 0) |
72 { | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
73 error ("colloc: N must be positive"); |
2928 | 74 return retval; |
75 } | |
76 | |
5275 | 77 octave_idx_type ntot = ncol; |
78 octave_idx_type left = 0; | |
79 octave_idx_type right = 0; | |
2928 | 80 |
81 for (int i = 1; i < nargin; i++) | |
82 { | |
20617
ba2b07c13913
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
83 std::string s = args(i).string_value ("colloc: expecting string argument \"left\" or \"right\""); |
2928 | 84 |
20617
ba2b07c13913
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
85 if ((s.length () == 1 && (s[0] == 'R' || s[0] == 'r')) |
ba2b07c13913
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
86 || s == "right") |
ba2b07c13913
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
87 { |
ba2b07c13913
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
88 right = 1; |
ba2b07c13913
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
89 } |
ba2b07c13913
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
90 else if ((s.length () == 1 && (s[0] == 'L' || s[0] == 'l')) |
ba2b07c13913
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
91 || s == "left") |
ba2b07c13913
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
92 { |
ba2b07c13913
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
93 left = 1; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
94 } |
2928 | 95 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
96 { |
20617
ba2b07c13913
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
97 error ("colloc: unrecognized argument"); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
98 return retval; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
99 } |
2928 | 100 } |
101 | |
102 ntot += left + right; | |
103 if (ntot < 1) | |
104 { | |
105 error ("colloc: the total number of roots must be positive"); | |
106 return retval; | |
107 } | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
108 |
2928 | 109 CollocWt wts (ncol, left, right); |
110 | |
111 ColumnVector r = wts.roots (); | |
112 Matrix A = wts.first (); | |
113 Matrix B = wts.second (); | |
114 ColumnVector q = wts.quad_weights (); | |
115 | |
116 retval(3) = q; | |
117 retval(2) = B; | |
118 retval(1) = A; | |
119 retval(0) = r; | |
120 | |
121 return retval; | |
122 } |