3
|
1 /* |
|
2 |
1865
|
3 Copyright (C) 1996 John W. Eaton |
3
|
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 2, or (at your option) any |
|
10 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, write to the Free |
1315
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
3
|
20 |
|
21 */ |
|
22 |
382
|
23 #if !defined (octave_NLEqn_h) |
|
24 #define octave_NLEqn_h 1 |
|
25 |
1296
|
26 #if defined (__GNUG__) |
|
27 #pragma interface |
|
28 #endif |
|
29 |
1531
|
30 #include <cfloat> |
|
31 #include <cmath> |
|
32 |
465
|
33 #include "dColVector.h" |
238
|
34 #include "NLFunc.h" |
3
|
35 |
1865
|
36 class |
|
37 NLEqn_options |
289
|
38 { |
1865
|
39 public: |
289
|
40 |
1865
|
41 NLEqn_options (void) |
|
42 : x_tolerance (::sqrt (DBL_EPSILON)) { } |
1531
|
43 |
1865
|
44 NLEqn_options (const NLEqn_options& opt) |
|
45 : x_tolerance (opt.x_tolerance) { } |
289
|
46 |
1531
|
47 NLEqn_options& operator = (const NLEqn_options& opt) |
|
48 { |
|
49 if (this != &opt) |
1865
|
50 x_tolerance = opt.x_tolerance; |
289
|
51 |
1531
|
52 return *this; |
|
53 } |
|
54 |
|
55 ~NLEqn_options (void) { } |
289
|
56 |
1865
|
57 void set_default_options (void) { x_tolerance = ::sqrt (DBL_EPSILON); } |
289
|
58 |
1872
|
59 void set_options (const NLEqn_options& opt) |
|
60 { x_tolerance = opt.x_tolerance; } |
|
61 |
1531
|
62 void set_tolerance (double val) |
1865
|
63 { x_tolerance = (val > 0.0) ? val : ::sqrt (DBL_EPSILON); } |
289
|
64 |
1531
|
65 double tolerance (void) { return x_tolerance; } |
289
|
66 |
1865
|
67 private: |
289
|
68 |
|
69 double x_tolerance; |
|
70 }; |
|
71 |
1865
|
72 class |
|
73 NLEqn : public NLFunc, public NLEqn_options |
3
|
74 { |
1865
|
75 public: |
1531
|
76 |
1865
|
77 NLEqn (void) |
|
78 : NLFunc (), NLEqn_options (), x () { } |
1531
|
79 |
1865
|
80 NLEqn (const ColumnVector& xx, const NLFunc f) |
|
81 : NLFunc (f), NLEqn_options (), x (xx) { } |
1531
|
82 |
1865
|
83 NLEqn (const NLEqn& a) |
|
84 : NLFunc (a.fun, a.jac), NLEqn_options (), x (a.x) { } |
3
|
85 |
1531
|
86 NLEqn& operator = (const NLEqn& a) |
|
87 { |
1865
|
88 if (this != &a) |
|
89 { |
|
90 NLFunc::operator = (a); |
|
91 NLEqn_options::operator = (a); |
1531
|
92 |
1865
|
93 x = a.x; |
|
94 } |
1531
|
95 return *this; |
|
96 } |
3
|
97 |
1865
|
98 ~NLEqn (void) { } |
3
|
99 |
1865
|
100 void set_states (const ColumnVector& xx) { x = xx; } |
1531
|
101 |
|
102 ColumnVector states (void) const { return x; } |
|
103 |
1865
|
104 int size (void) const { return x.capacity (); } |
3
|
105 |
1531
|
106 ColumnVector solve (void) |
|
107 { |
|
108 int info; |
|
109 return solve (info); |
|
110 } |
3
|
111 |
1531
|
112 ColumnVector solve (const ColumnVector& xvec) |
|
113 { |
|
114 set_states (xvec); |
|
115 int info; |
|
116 return solve (info); |
|
117 } |
3
|
118 |
1531
|
119 ColumnVector solve (const ColumnVector& xvec, int& info) |
|
120 { |
|
121 set_states (xvec); |
|
122 return solve (info); |
|
123 } |
|
124 |
|
125 ColumnVector solve (int& info); |
3
|
126 |
|
127 private: |
|
128 |
1531
|
129 ColumnVector x; |
3
|
130 |
|
131 void error (const char* msg); |
|
132 }; |
|
133 |
|
134 #endif |
|
135 |
|
136 /* |
|
137 ;;; Local Variables: *** |
|
138 ;;; mode: C++ *** |
|
139 ;;; End: *** |
|
140 */ |