GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
colloc.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2018 John W. Eaton
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
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <https://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if defined (HAVE_CONFIG_H)
24 # include "config.h"
25 #endif
26 
27 #include <algorithm>
28 #include <string>
29 
30 #include "CollocWt.h"
31 #include "lo-mappers.h"
32 
33 #include "defun.h"
34 #include "error.h"
35 #include "ovl.h"
36 #include "utils.h"
37 
38 DEFUN (colloc, args, ,
39  doc: /* -*- texinfo -*-
40 @deftypefn {} {[@var{r}, @var{amat}, @var{bmat}, @var{q}] =} colloc (@var{n}, "left", "right")
41 Compute derivative and integral weight matrices for orthogonal collocation.
42 
43 Reference: @nospell{J. Villadsen}, @nospell{M. L. Michelsen},
44 @cite{Solution of Differential Equation Models by Polynomial Approximation}.
45 @end deftypefn */)
46 {
47  int nargin = args.length ();
48 
50  print_usage ();
51 
52  if (! args(0).is_scalar_type ())
53  error ("colloc: N must be a scalar");
54 
55  double tmp = args(0).double_value ();
57  error ("colloc: N cannot be NaN");
58 
60  if (ncol < 0)
61  error ("colloc: N must be positive");
62 
63  octave_idx_type ntot = ncol;
66 
67  for (int i = 1; i < nargin; i++)
68  {
69  std::string s = args(i).xstring_value ("colloc: optional arguments must be strings");
70 
71  std::transform (s.begin (), s.end (), s.begin (), ::tolower);
72 
73  if (s == "r" || s == "right")
74  right = 1;
75  else if (s == "l" || s == "left")
76  left = 1;
77  else
78  error (R"(colloc: string argument must be "left" or "right")");
79  }
80 
81  ntot += left + right;
82  if (ntot < 1)
83  error (R"("colloc: the total number of roots (N + "left" + "right") must be >= 1)");
84 
85  CollocWt wts (ncol, left, right);
86 
87  ColumnVector r = wts.roots ();
88  Matrix A = wts.first ();
89  Matrix B = wts.second ();
90  ColumnVector q = wts.quad_weights ();
91 
92  return ovl (r, A, B, q);
93 }
94 
95 /*
96 
97 %!assert (colloc (1), 0.5)
98 %!assert (colloc (1, "left"), [0; 0.5])
99 %!assert (colloc (1, "right"), [0.5; 1])
100 %!assert (colloc (1, "left", "right"), [0; 0.5; 1])
101 
102 ## Test input validation
103 %!error colloc ()
104 %!error colloc (1,2,3,4)
105 %!error <N must be a scalar> colloc (ones (2,2))
106 %!error <N cannot be NaN> colloc (NaN)
107 %!error <N must be positive> colloc (-1)
108 %!error <optional arguments must be strings> colloc (1, 1)
109 %!error <string argument must be "left" or "right"> colloc (1, "foobar")
110 %!error <total number of roots .* must be .= 1> colloc (0)
111 
112 */
static int left
Definition: randmtzig.cc:184
F77_RET_T const F77_INT F77_CMPLX const F77_INT F77_CMPLX * B
OCTINTERP_API void print_usage(void)
Definition: defun.cc:54
bool isnan(bool)
Definition: lo-mappers.h:187
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
Definition: defun.h:53
void error(const char *fmt,...)
Definition: error.cc:578
s
Definition: file-io.cc:2729
in this the arguments are accumulated from left to right
Definition: data.cc:390
F77_RET_T const F77_INT F77_CMPLX * A
ColumnVector roots(void)
Definition: CollocWt.h:155
double tmp
Definition: data.cc:6252
Definition: dMatrix.h:36
Matrix first(void)
Definition: CollocWt.h:160
OCTAVE_EXPORT octave_value_list isa nd deftypefn *return ovl(args(0).isinteger())
octave_idx_type nint_big(double x)
Definition: lo-mappers.cc:182
args.length() nargin
Definition: file-io.cc:589
ColumnVector transform(const Matrix &m, double x, double y, double z)
Definition: graphics.cc:5410
for i
Definition: data.cc:5264
ColumnVector quad_weights(void)
Definition: CollocWt.h:158
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:888
Matrix second(void)
Definition: CollocWt.h:162