Mercurial > octave
annotate libinterp/corefcn/dassl.cc @ 20725:7164a69472dd
eliminate more uses of error state
* daspk.cc, dasrt.cc, dassl.cc, lsode.cc, quad.cc: Eliminate uses of
error_state. Handle user-supplied functions consistently.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 19 Nov 2015 15:46:40 -0500 |
parents | 7b608fadc663 |
children | 200ae1d650b7 |
rev | line source |
---|---|
2928 | 1 /* |
2 | |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
3 Copyright (C) 1996-2015 John W. Eaton |
2928 | 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 | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
2928 | 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 | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
2928 | 20 |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
25 #endif | |
26 | |
27 #include <string> | |
28 | |
3567 | 29 #include <iomanip> |
3523 | 30 #include <iostream> |
2928 | 31 |
32 #include "DASSL.h" | |
33 | |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14854
diff
changeset
|
34 #include "defun.h" |
2928 | 35 #include "error.h" |
36 #include "gripes.h" | |
37 #include "oct-obj.h" | |
2968 | 38 #include "ov-fcn.h" |
5729 | 39 #include "ov-cell.h" |
2928 | 40 #include "pager.h" |
3243 | 41 #include "unwind-prot.h" |
2928 | 42 #include "utils.h" |
43 #include "variables.h" | |
44 | |
3998 | 45 #include "DASSL-opts.cc" |
46 | |
2928 | 47 // Global pointer for user defined function required by dassl. |
2968 | 48 static octave_function *dassl_fcn; |
2928 | 49 |
3991 | 50 // Global pointer for optional user defined jacobian function. |
51 static octave_function *dassl_jac; | |
52 | |
4140 | 53 // Have we warned about imaginary values returned from user function? |
54 static bool warned_fcn_imaginary = false; | |
55 static bool warned_jac_imaginary = false; | |
56 | |
3243 | 57 // Is this a recursive call? |
58 static int call_depth = 0; | |
59 | |
2928 | 60 ColumnVector |
3849 | 61 dassl_user_function (const ColumnVector& x, const ColumnVector& xdot, |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
62 double t, octave_idx_type& ires) |
2928 | 63 { |
64 ColumnVector retval; | |
65 | |
20229
5dfaaaae784f
Deprecate Array::capacity() and Sparse::capacity() for numel() and nzmax().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
66 assert (x.numel () == xdot.numel ()); |
2928 | 67 |
68 octave_value_list args; | |
4628 | 69 |
2928 | 70 args(2) = t; |
4628 | 71 args(1) = xdot; |
72 args(0) = x; | |
2928 | 73 |
74 if (dassl_fcn) | |
75 { | |
20725
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
76 octave_value_list tmp; |
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
77 |
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
78 try |
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
79 { |
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
80 tmp = dassl_fcn->do_multi_index_op (1, args); |
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
81 } |
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
82 catch (const octave_execution_exception&) |
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
83 { |
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
84 gripe_user_supplied_eval ("dassl"); |
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
85 throw; |
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
86 } |
2928 | 87 |
3849 | 88 int tlen = tmp.length (); |
89 if (tlen > 0 && tmp(0).is_defined ()) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
90 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
91 if (! warned_fcn_imaginary && tmp(0).is_complex_type ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
92 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
93 warning ("dassl: ignoring imaginary part returned from user-supplied function"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
94 warned_fcn_imaginary = true; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
95 } |
4140 | 96 |
20703
85e5efae848a
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20687
diff
changeset
|
97 retval = tmp(0).vector_value (); |
2928 | 98 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
99 if (tlen > 1) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
100 ires = tmp(1).int_value (); |
3849 | 101 |
20703
85e5efae848a
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20687
diff
changeset
|
102 if (retval.numel () == 0) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
103 gripe_user_supplied_eval ("dassl"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
104 } |
2928 | 105 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
106 gripe_user_supplied_eval ("dassl"); |
2928 | 107 } |
108 | |
109 return retval; | |
110 } | |
111 | |
3991 | 112 Matrix |
113 dassl_user_jacobian (const ColumnVector& x, const ColumnVector& xdot, | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
114 double t, double cj) |
3991 | 115 { |
116 Matrix retval; | |
117 | |
20229
5dfaaaae784f
Deprecate Array::capacity() and Sparse::capacity() for numel() and nzmax().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
118 assert (x.numel () == xdot.numel ()); |
3991 | 119 |
120 octave_value_list args; | |
121 | |
122 args(3) = cj; | |
123 args(2) = t; | |
4628 | 124 args(1) = xdot; |
125 args(0) = x; | |
3991 | 126 |
127 if (dassl_jac) | |
128 { | |
20725
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
129 octave_value_list tmp; |
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
130 |
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
131 try |
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
132 { |
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
133 tmp = dassl_jac->do_multi_index_op (1, args); |
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
134 } |
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
135 catch (const octave_execution_exception&) |
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
136 { |
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
137 gripe_user_supplied_eval ("dassl"); |
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
138 throw; |
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
139 } |
3991 | 140 |
141 int tlen = tmp.length (); | |
142 if (tlen > 0 && tmp(0).is_defined ()) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
143 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
144 if (! warned_jac_imaginary && tmp(0).is_complex_type ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
145 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
146 warning ("dassl: ignoring imaginary part returned from user-supplied jacobian function"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
147 warned_jac_imaginary = true; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
148 } |
4140 | 149 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
150 retval = tmp(0).matrix_value (); |
3991 | 151 |
20703
85e5efae848a
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20687
diff
changeset
|
152 if (retval.numel () == 0) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
153 gripe_user_supplied_eval ("dassl"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
154 } |
3991 | 155 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
156 gripe_user_supplied_eval ("dassl"); |
3991 | 157 } |
158 | |
159 return retval; | |
160 } | |
161 | |
3323 | 162 #define DASSL_ABORT() \ |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9758
diff
changeset
|
163 return retval |
3323 | 164 |
165 #define DASSL_ABORT1(msg) \ | |
166 do \ | |
167 { \ | |
20428
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
168 error ("dassl: " msg); \ |
3323 | 169 DASSL_ABORT (); \ |
170 } \ | |
171 while (0) | |
172 | |
173 #define DASSL_ABORT2(fmt, arg) \ | |
174 do \ | |
175 { \ | |
20428
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
176 error ("dassl: " fmt, arg); \ |
3323 | 177 DASSL_ABORT (); \ |
178 } \ | |
179 while (0) | |
180 | |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14854
diff
changeset
|
181 DEFUN (dassl, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
182 "-*- texinfo -*-\n\ |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14854
diff
changeset
|
183 @deftypefn {Built-in Function} {[@var{x}, @var{xdot}, @var{istate}, @var{msg}] =} dassl (@var{fcn}, @var{x_0}, @var{xdot_0}, @var{t}, @var{t_crit})\n\ |
4115 | 184 Solve the set of differential-algebraic equations\n\ |
185 @tex\n\ | |
4852 | 186 $$ 0 = f (x, \\dot{x}, t) $$\n\ |
4115 | 187 with\n\ |
188 $$ x(t_0) = x_0, \\dot{x}(t_0) = \\dot{x}_0 $$\n\ | |
189 @end tex\n\ | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7562
diff
changeset
|
190 @ifnottex\n\ |
4115 | 191 \n\ |
192 @example\n\ | |
4698 | 193 0 = f (x, xdot, t)\n\ |
4115 | 194 @end example\n\ |
195 \n\ | |
4912 | 196 @noindent\n\ |
4115 | 197 with\n\ |
198 \n\ | |
199 @example\n\ | |
200 x(t_0) = x_0, xdot(t_0) = xdot_0\n\ | |
201 @end example\n\ | |
202 \n\ | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7562
diff
changeset
|
203 @end ifnottex\n\ |
4115 | 204 The solution is returned in the matrices @var{x} and @var{xdot},\n\ |
205 with each row in the result matrices corresponding to one of the\n\ | |
3373 | 206 elements in the vector @var{t}. The first element of @var{t}\n\ |
4115 | 207 should be @math{t_0} and correspond to the initial state of the\n\ |
208 system @var{x_0} and its derivative @var{xdot_0}, so that the first\n\ | |
209 row of the output @var{x} is @var{x_0} and the first row\n\ | |
210 of the output @var{xdot} is @var{xdot_0}.\n\ | |
3373 | 211 \n\ |
8787 | 212 The first argument, @var{fcn}, is a string, inline, or function handle\n\ |
213 that names the function @math{f} to call to compute the vector of\n\ | |
214 residuals for the set of equations. It must have the form\n\ | |
3373 | 215 \n\ |
216 @example\n\ | |
217 @var{res} = f (@var{x}, @var{xdot}, @var{t})\n\ | |
218 @end example\n\ | |
2928 | 219 \n\ |
3373 | 220 @noindent\n\ |
4115 | 221 in which @var{x}, @var{xdot}, and @var{res} are vectors, and @var{t} is a\n\ |
3373 | 222 scalar.\n\ |
223 \n\ | |
8787 | 224 If @var{fcn} is a two-element string array or a two-element cell array\n\ |
9067
8970b4b10e9f
Cleanup documentation for quad.texi and diffeq.texi
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
225 of strings, inline functions, or function handles, the first element names\n\ |
8787 | 226 the function @math{f} described above, and the second element names a\n\ |
227 function to compute the modified Jacobian\n\ | |
4115 | 228 \n\ |
229 @tex\n\ | |
230 $$\n\ | |
231 J = {\\partial f \\over \\partial x}\n\ | |
232 + c {\\partial f \\over \\partial \\dot{x}}\n\ | |
233 $$\n\ | |
234 @end tex\n\ | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7562
diff
changeset
|
235 @ifnottex\n\ |
10840 | 236 \n\ |
4888 | 237 @example\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
238 @group\n\ |
4115 | 239 df df\n\ |
240 jac = -- + c ------\n\ | |
241 dx d xdot\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
242 @end group\n\ |
4115 | 243 @end example\n\ |
10840 | 244 \n\ |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7562
diff
changeset
|
245 @end ifnottex\n\ |
4115 | 246 \n\ |
247 The modified Jacobian function must have the form\n\ | |
248 \n\ | |
249 @example\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
250 @group\n\ |
4115 | 251 \n\ |
252 @var{jac} = j (@var{x}, @var{xdot}, @var{t}, @var{c})\n\ | |
253 \n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
254 @end group\n\ |
4115 | 255 @end example\n\ |
256 \n\ | |
3373 | 257 The second and third arguments to @code{dassl} specify the initial\n\ |
258 condition of the states and their derivatives, and the fourth argument\n\ | |
4115 | 259 specifies a vector of output times at which the solution is desired,\n\ |
3373 | 260 including the time corresponding to the initial condition.\n\ |
2928 | 261 \n\ |
3373 | 262 The set of initial states and derivatives are not strictly required to\n\ |
10840 | 263 be consistent. In practice, however, @sc{dassl} is not very good at\n\ |
3373 | 264 determining a consistent set for you, so it is best if you ensure that\n\ |
265 the initial values result in the function evaluating to zero.\n\ | |
2928 | 266 \n\ |
3373 | 267 The fifth argument is optional, and may be used to specify a set of\n\ |
268 times that the DAE solver should not integrate past. It is useful for\n\ | |
269 avoiding difficulties with singularities and points where there is a\n\ | |
270 discontinuity in the derivative.\n\ | |
3964 | 271 \n\ |
4115 | 272 After a successful computation, the value of @var{istate} will be\n\ |
10840 | 273 greater than zero (consistent with the Fortran version of @sc{dassl}).\n\ |
4115 | 274 \n\ |
275 If the computation is not successful, the value of @var{istate} will be\n\ | |
276 less than zero and @var{msg} will contain additional information.\n\ | |
277 \n\ | |
3964 | 278 You can use the function @code{dassl_options} to set optional\n\ |
279 parameters for @code{dassl}.\n\ | |
5694 | 280 @seealso{daspk, dasrt, lsode}\n\ |
5642 | 281 @end deftypefn") |
2928 | 282 { |
283 octave_value_list retval; | |
284 | |
4140 | 285 warned_fcn_imaginary = false; |
286 warned_jac_imaginary = false; | |
287 | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9758
diff
changeset
|
288 unwind_protect frame; |
2928 | 289 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9758
diff
changeset
|
290 frame.protect_var (call_depth); |
3243 | 291 call_depth++; |
2928 | 292 |
3243 | 293 if (call_depth > 1) |
3323 | 294 DASSL_ABORT1 ("invalid recursive call"); |
2928 | 295 |
3243 | 296 int nargin = args.length (); |
297 | |
3991 | 298 if (nargin > 3 && nargin < 6 && nargout < 5) |
2928 | 299 { |
5729 | 300 std::string fcn_name, fname, jac_name, jname; |
3991 | 301 dassl_fcn = 0; |
302 dassl_jac = 0; | |
303 | |
304 octave_value f_arg = args(0); | |
305 | |
5729 | 306 if (f_arg.is_cell ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
307 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
308 Cell c = f_arg.cell_value (); |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20229
diff
changeset
|
309 if (c.numel () == 1) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
310 f_arg = c(0); |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20229
diff
changeset
|
311 else if (c.numel () == 2) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
312 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
313 if (c(0).is_function_handle () || c(0).is_inline_function ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
314 dassl_fcn = c(0).function_value (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
315 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
316 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
317 fcn_name = unique_symbol_name ("__dassl_fcn__"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
318 fname = "function y = "; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
319 fname.append (fcn_name); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
320 fname.append (" (x, xdot, t) y = "); |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
321 dassl_fcn = extract_function (c(0), "dassl", fcn_name, fname, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
322 "; endfunction"); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
323 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
324 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
325 if (dassl_fcn) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
326 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
327 if (c(1).is_function_handle () || c(1).is_inline_function ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
328 dassl_jac = c(1).function_value (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
329 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
330 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
331 jac_name = unique_symbol_name ("__dassl_jac__"); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
332 jname = "function jac = "; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
333 jname.append (jac_name); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
334 jname.append (" (x, xdot, t, cj) jac = "); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
335 dassl_jac = extract_function (c(1), "dassl", jac_name, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
336 jname, "; endfunction"); |
3991 | 337 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
338 if (!dassl_jac) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
339 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
340 if (fcn_name.length ()) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
341 clear_function (fcn_name); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
342 dassl_fcn = 0; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
343 } |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
344 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
345 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
346 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
347 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
348 DASSL_ABORT1 ("incorrect number of elements in cell array"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
349 } |
3243 | 350 |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
351 if (!dassl_fcn && ! f_arg.is_cell ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
352 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
353 if (f_arg.is_function_handle () || f_arg.is_inline_function ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
354 dassl_fcn = f_arg.function_value (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
355 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
356 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
357 switch (f_arg.rows ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
358 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
359 case 1: |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
360 do |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
361 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
362 fcn_name = unique_symbol_name ("__dassl_fcn__"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
363 fname = "function y = "; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
364 fname.append (fcn_name); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
365 fname.append (" (x, xdot, t) y = "); |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
366 dassl_fcn = extract_function (f_arg, "dassl", fcn_name, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
367 fname, "; endfunction"); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
368 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
369 while (0); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
370 break; |
3991 | 371 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
372 case 2: |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
373 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
374 string_vector tmp = f_arg.all_strings (); |
5729 | 375 |
20556
4bed806ee3d4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
376 fcn_name = unique_symbol_name ("__dassl_fcn__"); |
4bed806ee3d4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
377 fname = "function y = "; |
4bed806ee3d4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
378 fname.append (fcn_name); |
4bed806ee3d4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
379 fname.append (" (x, xdot, t) y = "); |
4bed806ee3d4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
380 dassl_fcn = extract_function (tmp(0), "dassl", fcn_name, |
4bed806ee3d4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
381 fname, "; endfunction"); |
4bed806ee3d4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
382 |
4bed806ee3d4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
383 if (dassl_fcn) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
384 { |
20556
4bed806ee3d4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
385 jac_name = unique_symbol_name ("__dassl_jac__"); |
4bed806ee3d4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
386 jname = "function jac = "; |
4bed806ee3d4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
387 jname.append (jac_name); |
4bed806ee3d4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
388 jname.append (" (x, xdot, t, cj) jac = "); |
4bed806ee3d4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
389 dassl_jac = extract_function (tmp(1), "dassl", |
4bed806ee3d4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
390 jac_name, jname, |
4bed806ee3d4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
391 "; endfunction"); |
3991 | 392 |
20556
4bed806ee3d4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
393 if (!dassl_jac) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
394 { |
20556
4bed806ee3d4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
395 if (fcn_name.length ()) |
4bed806ee3d4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
396 clear_function (fcn_name); |
4bed806ee3d4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
397 dassl_fcn = 0; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
398 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
399 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
400 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
401 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
402 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
403 } |
3991 | 404 |
20703
85e5efae848a
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20687
diff
changeset
|
405 if (! dassl_fcn) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
406 DASSL_ABORT (); |
3243 | 407 |
20711
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20703
diff
changeset
|
408 ColumnVector state = args(1).xvector_value ("dassl: initial state X_0 must be a vector"); |
3243 | 409 |
20711
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20703
diff
changeset
|
410 ColumnVector deriv = args(2).xvector_value ("dassl: initial derivatives XDOT_0 must be a vector"); |
3243 | 411 |
20711
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20703
diff
changeset
|
412 ColumnVector out_times = args(3).xvector_value ("dassl: output time variable T must be a vector"); |
2928 | 413 |
3243 | 414 ColumnVector crit_times; |
415 int crit_times_set = 0; | |
416 if (nargin > 4) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
417 { |
20711
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20703
diff
changeset
|
418 crit_times = args(4).xvector_value ("dassl: list of critical times T_CRIT must be a vector"); |
2928 | 419 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
420 crit_times_set = 1; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
421 } |
2928 | 422 |
20229
5dfaaaae784f
Deprecate Array::capacity() and Sparse::capacity() for numel() and nzmax().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
423 if (state.numel () != deriv.numel ()) |
20711
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20703
diff
changeset
|
424 DASSL_ABORT1 ("X and XDOT_0 must have the same size"); |
3243 | 425 |
426 double tzero = out_times (0); | |
2928 | 427 |
3243 | 428 DAEFunc func (dassl_user_function); |
3991 | 429 if (dassl_jac) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
430 func.set_jacobian_function (dassl_user_jacobian); |
3991 | 431 |
3243 | 432 DASSL dae (state, deriv, tzero, func); |
3991 | 433 |
4122 | 434 dae.set_options (dassl_opts); |
2928 | 435 |
3243 | 436 Matrix output; |
437 Matrix deriv_output; | |
438 | |
439 if (crit_times_set) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
440 output = dae.integrate (out_times, deriv_output, crit_times); |
3243 | 441 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
442 output = dae.integrate (out_times, deriv_output); |
2928 | 443 |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
444 if (fcn_name.length ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
445 clear_function (fcn_name); |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
446 if (jac_name.length ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
447 clear_function (jac_name); |
5729 | 448 |
20556
4bed806ee3d4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
449 std::string msg = dae.error_message (); |
3997 | 450 |
20556
4bed806ee3d4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
451 retval(3) = msg; |
4bed806ee3d4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
452 retval(2) = static_cast<double> (dae.integration_state ()); |
3997 | 453 |
20556
4bed806ee3d4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
454 if (dae.integration_ok ()) |
4bed806ee3d4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
455 { |
4bed806ee3d4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
456 retval(1) = deriv_output; |
4bed806ee3d4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
457 retval(0) = output; |
4bed806ee3d4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
458 } |
4bed806ee3d4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
459 else |
4bed806ee3d4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
460 { |
4bed806ee3d4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
461 retval(1) = Matrix (); |
4bed806ee3d4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
462 retval(0) = Matrix (); |
3997 | 463 |
20556
4bed806ee3d4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
464 if (nargout < 3) |
4bed806ee3d4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
465 error ("dassl: %s", msg.c_str ()); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
466 } |
2928 | 467 } |
3243 | 468 else |
5823 | 469 print_usage (); |
3243 | 470 |
2928 | 471 return retval; |
472 } | |
473 | |
474 /* | |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
475 ## dassl-1.m |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
476 ## |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
477 ## Test dassl() function |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
478 ## |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
479 ## Author: David Billinghurst (David.Billinghurst@riotinto.com.au) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
480 ## Comalco Research and Technology |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
481 ## 20 May 1998 |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
482 ## |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
483 ## Problem |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
484 ## |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
485 ## y1' = -y2, y1(0) = 1 |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
486 ## y2' = y1, y2(0) = 0 |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
487 ## |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
488 ## Solution |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
489 ## |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
490 ## y1(t) = cos(t) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
491 ## y2(t) = sin(t) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
492 ## |
14085
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
493 %!function res = __f (x, xdot, t) |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
494 %! res = [xdot(1)+x(2); xdot(2)-x(1)]; |
14085
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
495 %!endfunction |
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
496 |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
497 %!test |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
498 %! |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
499 %! x0 = [1; 0]; |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
500 %! xdot0 = [0; 1]; |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
501 %! t = (0:1:10)'; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
502 %! |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
503 %! tol = 100 * dassl_options ("relative tolerance"); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
504 %! |
14085
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
505 %! [x, xdot] = dassl ("__f", x0, xdot0, t); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
506 %! |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
507 %! y = [cos(t), sin(t)]; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
508 %! |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
509 %! assert (x, y, tol); |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
510 |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
511 ## dassl-2.m |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
512 ## |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
513 ## Test dassl() function |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
514 ## |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
515 ## Author: David Billinghurst (David.Billinghurst@riotinto.com.au) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
516 ## Comalco Research and Technology |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
517 ## 20 May 1998 |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
518 ## |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
519 ## Based on SLATEC quick check for DASSL by Linda Petzold |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
520 ## |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
521 ## Problem |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
522 ## |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
523 ## x1' + 10*x1 = 0, x1(0) = 1 |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
524 ## x1 + x2 = 1, x2(0) = 0 |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
525 ## |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
526 ## |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
527 ## Solution |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
528 ## |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
529 ## x1(t) = exp(-10*t) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
530 ## x2(t) = 1 - x(1) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
531 ## |
14085
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
532 %!function res = __f (x, xdot, t) |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
533 %! res = [xdot(1)+10*x(1); x(1)+x(2)-1]; |
14085
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
534 %!endfunction |
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
535 |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
536 %!test |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
537 %! |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
538 %! x0 = [1; 0]; |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
539 %! xdot0 = [-10; 10]; |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
540 %! t = (0:0.2:1)'; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
541 %! |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
542 %! tol = 500 * dassl_options ("relative tolerance"); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
543 %! |
14085
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
544 %! [x, xdot] = dassl ("__f", x0, xdot0, t); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
545 %! |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
546 %! y = [exp(-10*t), 1-exp(-10*t)]; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
547 %! |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
548 %! assert (x, y, tol); |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
549 |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
550 %!test |
16780
781916090eb1
Restore dassl tolerance after running %! tests (bug #36137).
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
551 %! old_tol = dassl_options ("absolute tolerance"); |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
552 %! dassl_options ("absolute tolerance", eps); |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
553 %! assert (dassl_options ("absolute tolerance") == eps); |
16780
781916090eb1
Restore dassl tolerance after running %! tests (bug #36137).
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
554 %! ## Restore old value of tolerance |
781916090eb1
Restore dassl tolerance after running %! tests (bug #36137).
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
555 %! dassl_options ("absolute tolerance", old_tol); |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
556 |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
557 %!error dassl_options ("foo", 1, 2) |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
558 */ |