Mercurial > octave
annotate libinterp/corefcn/colloc.cc @ 20711:7b608fadc663
Make error messages more specific about the variable and problem encountered.
* besselj.cc, bitfcns.cc, colloc.cc, daspk.cc, dasrt.cc, dassl.cc, data.cc,
dirfns.cc, ellipj.cc, error.cc, gl-render.cc, graphics.cc, graphics.in.h,
load-path.cc, lsode.cc, lu.cc, luinc.cc, oct-hist.cc, oct-obj.cc,
octave-link.cc, quad.cc, rand.cc, symtab.cc, sysdep.cc, toplev.cc, utils.cc,
variables.cc, __init_fltk__.cc, chol.cc, fftw.cc, ov-cell.cc, ov-ch-mat.cc,
ov-class.cc, ov-classdef.cc, ov-cx-mat.cc, ov-fcn-inline.cc, ov-struct.cc,
ov-usr-fcn.cc, CMatrix.cc, dMatrix.cc, fCMatrix.cc, fMatrix.cc, lo-specfun.cc,
curl.m, divergence.m, __fltk_file_filter__.m, __uiobject_split_args__.m,
uigetfile.m, doc.m, imshow.m, rref.m, subspace.m, edit.m, fileattrib.m, open.m,
substruct.m, annotation.m, axis.m, caxis.m, datetick.m, hidden.m, legend.m,
whitebg.m, colorbar.m, __add_datasource__.m, __ezplot__.m, __pie__.m,
__plt_get_axis_arg__.m, pan.m, __print_parse_opts__.m, rotate3d.m, subplot.m,
zoom.m, compan.m, addpref.m, getpref.m, setpref.m, powerset.m, bicg.m,
bicgstab.m, cgs.m, qmr.m, spaugment.m, pascal.m, moment.m, cstrcat.m,
system.tst:
Make error messages more specific about the variable and problem encountered.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 18 Nov 2015 10:40:26 -0800 |
parents | 68e3a747ca02 |
children | 8bb38ba1bad6 |
rev | line source |
---|---|
2928 | 1 /* |
2 | |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19040
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\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
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:
19697
diff
changeset
|
41 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
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:
19697
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 { | |
20711
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20700
diff
changeset
|
83 std::string s = args(i).xstring_value ("colloc: optional arguments must be strings"); |
2928 | 84 |
20582
ba2b07c13913
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20555
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:
20555
diff
changeset
|
86 || s == "right") |
ba2b07c13913
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
87 { |
ba2b07c13913
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
88 right = 1; |
ba2b07c13913
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
89 } |
ba2b07c13913
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20555
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:
20555
diff
changeset
|
91 || s == "left") |
ba2b07c13913
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
92 { |
ba2b07c13913
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20555
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 { |
20711
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20700
diff
changeset
|
97 error ("colloc: string argument must be \"left\" or \"right\""); |
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 } |