comparison src/colloc.cc @ 1:78fd87e624cb

[project @ 1993-08-08 01:13:40 by jwe] Initial revision
author jwe
date Sun, 08 Aug 1993 01:13:40 +0000
parents
children d68036bcad4c
comparison
equal deleted inserted replaced
0:22412e3a4641 1:78fd87e624cb
1 // tc-colloc.cc -*- C++ -*-
2 /*
3
4 Copyright (C) 1993 John W. Eaton
5
6 This file is part of Octave.
7
8 Octave is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by the
10 Free Software Foundation; either version 2, or (at your option) any
11 later version.
12
13 Octave is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with Octave; see the file COPYING. If not, write to the Free
20 Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
21
22 */
23
24 #ifdef __GNUG__
25 #pragma implementation
26 #endif
27
28 #include "CollocWt.h"
29
30 #include "tree-const.h"
31 #include "error.h"
32 #include "utils.h"
33
34 #ifdef WITH_DLD
35 tree_constant *
36 builtin_colloc_2 (tree_constant *args, int nargin, int nargout)
37 {
38 return collocation_weights (args, nargin);
39 }
40 #endif
41
42 tree_constant *
43 collocation_weights (tree_constant *args, int nargin)
44 {
45 tree_constant *retval = NULL_TREE_CONST;
46
47 if (args[1].const_type () != tree_constant_rep::complex_scalar_constant
48 && args[1].const_type () != tree_constant_rep::scalar_constant)
49 {
50 message ("colloc", "first argument must be a scalar");
51 return retval;
52 }
53
54 int ncol = NINT (args[1].double_value ());
55 if (ncol < 0)
56 {
57 message ("colloc", "first argument must be non-negative");
58 return retval;
59 }
60
61 int ntot = ncol;
62 int left = 0;
63 int right = 0;
64
65 for (int i = 2; i < nargin; i++)
66 {
67 if (args[i].is_defined ())
68 {
69 if (! args[i].is_string_type ())
70 {
71 message ("colloc", "expecting string argument");
72 return retval;
73 }
74
75 char *s = args[i].string_value ();
76 if (s != (char *) NULL
77 && (((*s == 'R' || *s == 'r') && strlen (s) == 1)
78 || strcmp (s, "right") == 0))
79 {
80 right = 1;
81 }
82 else if (s != (char *) NULL
83 && (((*s == 'L' || *s == 'l') && strlen (s) == 1)
84 || strcmp (s, "left") == 0))
85 {
86 left = 1;
87 }
88 else
89 {
90 message ("colloc", "unrecognized argument");
91 return retval;
92 }
93 }
94 else
95 {
96 message ("colloc", "unexpected NULL argument");
97 return retval;
98 }
99 }
100
101 ntot += left + right;
102 if (ntot < 1)
103 message ("colloc", "the total number of roots must be positive");
104
105 CollocWt wts (ncol, left, right);
106
107 ColumnVector r = wts.roots ();
108 Matrix A = wts.first ();
109 Matrix B = wts.second ();
110 ColumnVector q = wts.quad_weights ();
111
112 retval = new tree_constant [5];
113
114 retval[0] = tree_constant (r);
115 retval[1] = tree_constant (A);
116 retval[2] = tree_constant (B);
117 retval[3] = tree_constant (q);
118 retval[4] = tree_constant ();
119
120 return retval;
121 }
122
123 /*
124 ;;; Local Variables: ***
125 ;;; mode: C++ ***
126 ;;; page-delimiter: "^/\\*" ***
127 ;;; End: ***
128 */
129