Mercurial > octave
annotate libinterp/corefcn/colloc.cc @ 25054:6652d3823428 stable
maint: Update copyright dates in all source files.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 30 Mar 2018 09:19:05 -0400 |
parents | 194eb4bd202b |
children | db31e068f4db |
rev | line source |
---|---|
2928 | 1 /* |
2 | |
25054
6652d3823428
maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
3 Copyright (C) 1996-2018 John W. Eaton |
2928 | 4 |
5 This file is part of Octave. | |
6 | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23803
diff
changeset
|
7 Octave is free software: you can redistribute it and/or modify it |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
8 under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23803
diff
changeset
|
9 the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
10 (at your option) any later version. |
2928 | 11 |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
12 Octave is distributed in the hope that it will be useful, but |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
13 WITHOUT ANY WARRANTY; without even the implied warranty of |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
15 GNU General Public License for more details. |
2928 | 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 |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23803
diff
changeset
|
19 <https://www.gnu.org/licenses/>. |
2928 | 20 |
21 */ | |
22 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
23 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21200
diff
changeset
|
24 # include "config.h" |
2928 | 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" |
20940
48b2ad5ee801
maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents:
20918
diff
changeset
|
34 #include "ovl.h" |
2928 | 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, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
38 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
39 @deftypefn {} {[@var{r}, @var{amat}, @var{bmat}, @var{q}] =} colloc (@var{n}, "left", "right") |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
40 Compute derivative and integral weight matrices for orthogonal collocation. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
41 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
42 Reference: @nospell{J. Villadsen}, @nospell{M. L. Michelsen}, |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
43 @cite{Solution of Differential Equation Models by Polynomial Approximation}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
44 @end deftypefn */) |
2928 | 45 { |
46 int nargin = args.length (); | |
47 | |
48 if (nargin < 1 || nargin > 3) | |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
49 print_usage (); |
2928 | 50 |
51 if (! args(0).is_scalar_type ()) | |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
52 error ("colloc: N must be a scalar"); |
2928 | 53 |
54 double tmp = args(0).double_value (); | |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
55 if (octave::math::isnan (tmp)) |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
56 error ("colloc: N cannot be NaN"); |
2928 | 57 |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
58 octave_idx_type ncol = octave::math::nint_big (tmp); |
2928 | 59 if (ncol < 0) |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
60 error ("colloc: N must be positive"); |
2928 | 61 |
5275 | 62 octave_idx_type ntot = ncol; |
63 octave_idx_type left = 0; | |
64 octave_idx_type right = 0; | |
2928 | 65 |
66 for (int i = 1; i < nargin; i++) | |
67 { | |
20711
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20700
diff
changeset
|
68 std::string s = args(i).xstring_value ("colloc: optional arguments must be strings"); |
2928 | 69 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
70 if ((s.length () == 1 && (s[0] == 'R' || s[0] == 'r')) || s == "right") |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
71 right = 1; |
20582
ba2b07c13913
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
72 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
|
73 || s == "left") |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
74 left = 1; |
2928 | 75 else |
23803
90689bdbe048
Use C++11 raw string literals to avoid escaping double quotes.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
76 error (R"(colloc: string argument must be "left" or "right")"); |
2928 | 77 } |
78 | |
79 ntot += left + right; | |
80 if (ntot < 1) | |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20802
diff
changeset
|
81 error ("colloc: the total number of roots must be positive"); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
82 |
2928 | 83 CollocWt wts (ncol, left, right); |
84 | |
85 ColumnVector r = wts.roots (); | |
86 Matrix A = wts.first (); | |
87 Matrix B = wts.second (); | |
88 ColumnVector q = wts.quad_weights (); | |
89 | |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
90 return ovl (r, A, B, q); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
91 } |