Mercurial > octave
annotate libinterp/corefcn/colloc.cc @ 30564:796f54d4ddbf stable
update Octave Project Developers copyright for the new year
In files that have the "Octave Project Developers" copyright notice,
update for 2021.
In all .txi and .texi files except gpl.txi and gpl.texi in the
doc/liboctave and doc/interpreter directories, change the copyright
to "Octave Project Developers", the same as used for other source
files. Update copyright notices for 2022 (not done since 2019). For
gpl.txi and gpl.texi, change the copyright notice to be "Free Software
Foundation, Inc." and leave the date at 2007 only because this file
only contains the text of the GPL, not anything created by the Octave
Project Developers.
Add Paul Thomas to contributors.in.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 28 Dec 2021 18:22:40 -0500 |
parents | 7d6709900da7 |
children | e88a07dec498 |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 //////////////////////////////////////////////////////////////////////// |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 // |
30564
796f54d4ddbf
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
29961
diff
changeset
|
3 // Copyright (C) 1996-2022 The Octave Project Developers |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
4 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 // See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 // distribution or <https://octave.org/copyright/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
7 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
8 // This file is part of Octave. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
9 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
10 // Octave is free software: you can redistribute it and/or modify it |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
11 // under the terms of the GNU General Public License as published by |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
12 // the Free Software Foundation, either version 3 of the License, or |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
13 // (at your option) any later version. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
14 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
15 // Octave is distributed in the hope that it will be useful, but |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
16 // WITHOUT ANY WARRANTY; without even the implied warranty of |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
18 // GNU General Public License for more details. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
19 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
20 // You should have received a copy of the GNU General Public License |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
21 // along with Octave; see the file COPYING. If not, see |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
22 // <https://www.gnu.org/licenses/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 //////////////////////////////////////////////////////////////////////// |
2928 | 25 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
26 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21200
diff
changeset
|
27 # include "config.h" |
2928 | 28 #endif |
29 | |
25252
75eea4768e24
Add BIST tests for colloc input validation (bug #53653)
Rik <rik@octave.org>
parents:
25247
diff
changeset
|
30 #include <algorithm> |
2928 | 31 #include <string> |
32 | |
33 #include "CollocWt.h" | |
34 #include "lo-mappers.h" | |
35 | |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
36 #include "defun.h" |
2928 | 37 #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
|
38 #include "ovl.h" |
2928 | 39 #include "utils.h" |
40 | |
29958
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29681
diff
changeset
|
41 OCTAVE_NAMESPACE_BEGIN |
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29681
diff
changeset
|
42 |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
43 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
|
44 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
|
45 @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
|
46 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
|
47 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
48 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
|
49 @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
|
50 @end deftypefn */) |
2928 | 51 { |
52 int nargin = args.length (); | |
53 | |
54 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
|
55 print_usage (); |
2928 | 56 |
57 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
|
58 error ("colloc: N must be a scalar"); |
2928 | 59 |
60 double tmp = args(0).double_value (); | |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
61 if (math::isnan (tmp)) |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
62 error ("colloc: N cannot be NaN"); |
2928 | 63 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
64 octave_idx_type ncol = math::nint_big (tmp); |
2928 | 65 if (ncol < 0) |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
66 error ("colloc: N must be positive"); |
2928 | 67 |
5275 | 68 octave_idx_type ntot = ncol; |
69 octave_idx_type left = 0; | |
70 octave_idx_type right = 0; | |
2928 | 71 |
72 for (int i = 1; i < nargin; i++) | |
73 { | |
20711
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20700
diff
changeset
|
74 std::string s = args(i).xstring_value ("colloc: optional arguments must be strings"); |
2928 | 75 |
25252
75eea4768e24
Add BIST tests for colloc input validation (bug #53653)
Rik <rik@octave.org>
parents:
25247
diff
changeset
|
76 std::transform (s.begin (), s.end (), s.begin (), ::tolower); |
75eea4768e24
Add BIST tests for colloc input validation (bug #53653)
Rik <rik@octave.org>
parents:
25247
diff
changeset
|
77 |
75eea4768e24
Add BIST tests for colloc input validation (bug #53653)
Rik <rik@octave.org>
parents:
25247
diff
changeset
|
78 if (s == "r" || s == "right") |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
79 right = 1; |
25252
75eea4768e24
Add BIST tests for colloc input validation (bug #53653)
Rik <rik@octave.org>
parents:
25247
diff
changeset
|
80 else if (s == "l" || s == "left") |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
81 left = 1; |
2928 | 82 else |
23803
90689bdbe048
Use C++11 raw string literals to avoid escaping double quotes.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
83 error (R"(colloc: string argument must be "left" or "right")"); |
2928 | 84 } |
85 | |
86 ntot += left + right; | |
87 if (ntot < 1) | |
25252
75eea4768e24
Add BIST tests for colloc input validation (bug #53653)
Rik <rik@octave.org>
parents:
25247
diff
changeset
|
88 error (R"("colloc: the total number of roots (N + "left" + "right") must be >= 1)"); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
89 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
90 CollocWt wts (ncol, left, right); |
2928 | 91 |
92 ColumnVector r = wts.roots (); | |
93 Matrix A = wts.first (); | |
94 Matrix B = wts.second (); | |
95 ColumnVector q = wts.quad_weights (); | |
96 | |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
97 return ovl (r, A, B, q); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
98 } |
25247
db31e068f4db
Rewrite incorrect assert statement in colloc calculation (bug #53653)
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
99 |
db31e068f4db
Rewrite incorrect assert statement in colloc calculation (bug #53653)
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
100 /* |
db31e068f4db
Rewrite incorrect assert statement in colloc calculation (bug #53653)
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
101 |
db31e068f4db
Rewrite incorrect assert statement in colloc calculation (bug #53653)
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
102 %!assert (colloc (1), 0.5) |
db31e068f4db
Rewrite incorrect assert statement in colloc calculation (bug #53653)
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
103 %!assert (colloc (1, "left"), [0; 0.5]) |
db31e068f4db
Rewrite incorrect assert statement in colloc calculation (bug #53653)
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
104 %!assert (colloc (1, "right"), [0.5; 1]) |
db31e068f4db
Rewrite incorrect assert statement in colloc calculation (bug #53653)
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
105 %!assert (colloc (1, "left", "right"), [0; 0.5; 1]) |
db31e068f4db
Rewrite incorrect assert statement in colloc calculation (bug #53653)
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
106 |
25252
75eea4768e24
Add BIST tests for colloc input validation (bug #53653)
Rik <rik@octave.org>
parents:
25247
diff
changeset
|
107 ## Test input validation |
75eea4768e24
Add BIST tests for colloc input validation (bug #53653)
Rik <rik@octave.org>
parents:
25247
diff
changeset
|
108 %!error colloc () |
75eea4768e24
Add BIST tests for colloc input validation (bug #53653)
Rik <rik@octave.org>
parents:
25247
diff
changeset
|
109 %!error colloc (1,2,3,4) |
75eea4768e24
Add BIST tests for colloc input validation (bug #53653)
Rik <rik@octave.org>
parents:
25247
diff
changeset
|
110 %!error <N must be a scalar> colloc (ones (2,2)) |
75eea4768e24
Add BIST tests for colloc input validation (bug #53653)
Rik <rik@octave.org>
parents:
25247
diff
changeset
|
111 %!error <N cannot be NaN> colloc (NaN) |
75eea4768e24
Add BIST tests for colloc input validation (bug #53653)
Rik <rik@octave.org>
parents:
25247
diff
changeset
|
112 %!error <N must be positive> colloc (-1) |
75eea4768e24
Add BIST tests for colloc input validation (bug #53653)
Rik <rik@octave.org>
parents:
25247
diff
changeset
|
113 %!error <optional arguments must be strings> colloc (1, 1) |
75eea4768e24
Add BIST tests for colloc input validation (bug #53653)
Rik <rik@octave.org>
parents:
25247
diff
changeset
|
114 %!error <string argument must be "left" or "right"> colloc (1, "foobar") |
75eea4768e24
Add BIST tests for colloc input validation (bug #53653)
Rik <rik@octave.org>
parents:
25247
diff
changeset
|
115 %!error <total number of roots .* must be .= 1> colloc (0) |
75eea4768e24
Add BIST tests for colloc input validation (bug #53653)
Rik <rik@octave.org>
parents:
25247
diff
changeset
|
116 |
25247
db31e068f4db
Rewrite incorrect assert statement in colloc calculation (bug #53653)
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
117 */ |
29958
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29681
diff
changeset
|
118 |
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29681
diff
changeset
|
119 OCTAVE_NAMESPACE_END |