GNU Octave  4.2.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
colloc.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2017 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 the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
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
18 along with Octave; see the file COPYING. If not, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if defined (HAVE_CONFIG_H)
24 # include "config.h"
25 #endif
26 
27 #include <string>
28 
29 #include "CollocWt.h"
30 #include "lo-mappers.h"
31 
32 #include "defun.h"
33 #include "error.h"
34 #include "ovl.h"
35 #include "utils.h"
36 
37 DEFUN (colloc, args, ,
38  doc: /* -*- texinfo -*-
39 @deftypefn {} {[@var{r}, @var{amat}, @var{bmat}, @var{q}] =} colloc (@var{n}, "left", "right")
40 Compute derivative and integral weight matrices for orthogonal collocation.
41 
42 Reference: @nospell{J. Villadsen}, @nospell{M. L. Michelsen},
43 @cite{Solution of Differential Equation Models by Polynomial Approximation}.
44 @end deftypefn */)
45 {
46  int nargin = args.length ();
47 
48  if (nargin < 1 || nargin > 3)
49  print_usage ();
50 
51  if (! args(0).is_scalar_type ())
52  error ("colloc: N must be a scalar");
53 
54  double tmp = args(0).double_value ();
55  if (octave::math::isnan (tmp))
56  error ("colloc: N cannot be NaN");
57 
59  if (ncol < 0)
60  error ("colloc: N must be positive");
61 
62  octave_idx_type ntot = ncol;
65 
66  for (int i = 1; i < nargin; i++)
67  {
68  std::string s = args(i).xstring_value ("colloc: optional arguments must be strings");
69 
70  if ((s.length () == 1 && (s[0] == 'R' || s[0] == 'r')) || s == "right")
71  right = 1;
72  else if ((s.length () == 1 && (s[0] == 'L' || s[0] == 'l'))
73  || s == "left")
74  left = 1;
75  else
76  error ("colloc: string argument must be \"left\" or \"right\"");
77  }
78 
79  ntot += left + right;
80  if (ntot < 1)
81  error ("colloc: the total number of roots must be positive");
82 
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 
90  return ovl (r, A, B, q);
91 }
static int left
Definition: randmtzig.cc:185
OCTAVE_EXPORT octave_value_list isa nd deftypefn *return ovl(args(0).is_integer_type())
OCTINTERP_API void print_usage(void)
Definition: defun.cc:52
bool isnan(double x)
Definition: lo-mappers.cc:347
#define DEFUN(name, args_name, nargout_name, doc)
Definition: defun.h:46
void error(const char *fmt,...)
Definition: error.cc:570
s
Definition: file-io.cc:2682
in this the arguments are accumulated from left to right
Definition: data.cc:393
JNIEnv void * args
Definition: ov-java.cc:67
F77_RET_T const F77_INT F77_CMPLX const F77_INT F77_CMPLX * B
int nargin
Definition: graphics.cc:10115
ColumnVector roots(void)
Definition: CollocWt.h:155
double tmp
Definition: data.cc:6300
Definition: dMatrix.h:37
Matrix first(void)
Definition: CollocWt.h:160
=val(i)}if ode{val(i)}occurs in table i
Definition: lookup.cc:239
octave_idx_type nint_big(double x)
Definition: lo-mappers.cc:409
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:854
Matrix second(void)
Definition: CollocWt.h:162
F77_RET_T const F77_INT F77_CMPLX * A