Mercurial > octave
annotate libinterp/corefcn/colloc.cc @ 29681:25246c1a1645
move CollocWt class inside octave namespace
* CollocWt.h, CollocWt.cc: Move CollocWt and supporting functions
inside octave namespace. Provide deprecated typedef for old global
name.
* colloc.cc (Fcolloc): Use octave::CollocWt.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sun, 16 May 2021 10:03:44 -0400 |
parents | 7854d5752dd2 |
children | 32c3a5805893 |
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 // |
29358
0a5b15007766
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
3 // Copyright (C) 1996-2021 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 | |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
41 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
|
42 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
|
43 @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
|
44 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
|
45 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
46 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
|
47 @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
|
48 @end deftypefn */) |
2928 | 49 { |
50 int nargin = args.length (); | |
51 | |
52 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
|
53 print_usage (); |
2928 | 54 |
55 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
|
56 error ("colloc: N must be a scalar"); |
2928 | 57 |
58 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
|
59 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
|
60 error ("colloc: N cannot be NaN"); |
2928 | 61 |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
62 octave_idx_type ncol = octave::math::nint_big (tmp); |
2928 | 63 if (ncol < 0) |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
64 error ("colloc: N must be positive"); |
2928 | 65 |
5275 | 66 octave_idx_type ntot = ncol; |
67 octave_idx_type left = 0; | |
68 octave_idx_type right = 0; | |
2928 | 69 |
70 for (int i = 1; i < nargin; i++) | |
71 { | |
20711
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20700
diff
changeset
|
72 std::string s = args(i).xstring_value ("colloc: optional arguments must be strings"); |
2928 | 73 |
25252
75eea4768e24
Add BIST tests for colloc input validation (bug #53653)
Rik <rik@octave.org>
parents:
25247
diff
changeset
|
74 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
|
75 |
75eea4768e24
Add BIST tests for colloc input validation (bug #53653)
Rik <rik@octave.org>
parents:
25247
diff
changeset
|
76 if (s == "r" || s == "right") |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
77 right = 1; |
25252
75eea4768e24
Add BIST tests for colloc input validation (bug #53653)
Rik <rik@octave.org>
parents:
25247
diff
changeset
|
78 else if (s == "l" || s == "left") |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
79 left = 1; |
2928 | 80 else |
23803
90689bdbe048
Use C++11 raw string literals to avoid escaping double quotes.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
81 error (R"(colloc: string argument must be "left" or "right")"); |
2928 | 82 } |
83 | |
84 ntot += left + right; | |
85 if (ntot < 1) | |
25252
75eea4768e24
Add BIST tests for colloc input validation (bug #53653)
Rik <rik@octave.org>
parents:
25247
diff
changeset
|
86 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
|
87 |
29681
25246c1a1645
move CollocWt class inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
88 octave::CollocWt wts (ncol, left, right); |
2928 | 89 |
90 ColumnVector r = wts.roots (); | |
91 Matrix A = wts.first (); | |
92 Matrix B = wts.second (); | |
93 ColumnVector q = wts.quad_weights (); | |
94 | |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
95 return ovl (r, A, B, q); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
96 } |
25247
db31e068f4db
Rewrite incorrect assert statement in colloc calculation (bug #53653)
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
97 |
db31e068f4db
Rewrite incorrect assert statement in colloc calculation (bug #53653)
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
98 /* |
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 %!assert (colloc (1), 0.5) |
db31e068f4db
Rewrite incorrect assert statement in colloc calculation (bug #53653)
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
101 %!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
|
102 %!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
|
103 %!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
|
104 |
25252
75eea4768e24
Add BIST tests for colloc input validation (bug #53653)
Rik <rik@octave.org>
parents:
25247
diff
changeset
|
105 ## Test input validation |
75eea4768e24
Add BIST tests for colloc input validation (bug #53653)
Rik <rik@octave.org>
parents:
25247
diff
changeset
|
106 %!error colloc () |
75eea4768e24
Add BIST tests for colloc input validation (bug #53653)
Rik <rik@octave.org>
parents:
25247
diff
changeset
|
107 %!error colloc (1,2,3,4) |
75eea4768e24
Add BIST tests for colloc input validation (bug #53653)
Rik <rik@octave.org>
parents:
25247
diff
changeset
|
108 %!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
|
109 %!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
|
110 %!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
|
111 %!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
|
112 %!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
|
113 %!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
|
114 |
25247
db31e068f4db
Rewrite incorrect assert statement in colloc calculation (bug #53653)
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
115 */ |