Mercurial > octave
annotate libinterp/corefcn/dasrt.cc @ 20812:d9ca869ca124
maint: Clean-up more instances of print_usage().
* mk-opts.pl: Fix script that generates *-opt.cc files to put print_usage()
first.
* __ilu__.cc (F__ilutp__): Don't declare and initialize multiple comma
separated variables.
* __lin_interpn__.cc (F__lin_interpn__): Eliminate extra spaces in if
conditional.
* dasrt.cc (Fdasrt): Declare variables only as needed, in this case, after
input validation has succeeded.
* file-io.cc (Frewind): Declare variables after input validation succeeds.
* file-io.cc (Ftempname): Rename variable len to nargin to match rest of code.
* gammainc.cc (Fgammainc): Put nargin checking first in function.
* hex2num.cc (Fhex2num, Fnum2hex): Declare "octave_value retval;" first in
function to match rest of Octave code base.
* load-path.cc (Frmpath): Re-phrase comment.
* lu.cc (Flu): Declare variables after input validation succeeds. Use space
after ! operator.
* lu.cc (Fluupdate): Place octave_value_list declaration first in function.
Declare variables after input validation succeeds.
* matrix_type.cc (Fmatrix_type): Place octave_value declaration first in
function.
* tril.cc (do_trilu): Move nargin checking higher in function.
* utils.cc (Fdir_in_loadpath): Declare variables after input validation
succeeds.
* __glpk__.cc (F__glpk__): Rename variable nrhs to nargin to match rest of
code base.
* __magick_read__.cc (F__magick_ping__, F__magick_formats__): Add newline
to space out code for readability.
* __osmesa_print__.cc (F__osmesa_print__): Use DeMorgan's Law to simplify
nargin validation.
* audiodevinfo.cc (F__recorder_record__): Correct indentation.
* chol.cc (Fcholinsert, Fcholdelete, Fcholshift): Place octave_value_list
declaration first in function.
* dmperm.cc (Fdmperm, Fsprank): Place octave_value_list declaration first in
function.
* qr.cc (Fqrupdate, Fqrinsert, Fqrdelete, Fqrshift): Place octave_value_list
declaration first in function.
* lex.ll (Fiskeyword): Rewrite function to use modern syntax. Add BIST
tests for special words "get", "set". Add BIST tests for input validation.
author | Rik <rik@octave.org> |
---|---|
date | Sat, 05 Dec 2015 15:59:22 -0800 |
parents | 8bb38ba1bad6 |
children | 1142cf6abc0d |
rev | line source |
---|---|
3990 | 1 /* |
2 | |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
3 Copyright (C) 2002-2015 John W. Eaton |
3990 | 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. | |
3990 | 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/>. | |
3990 | 20 |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
25 #endif | |
26 | |
4052 | 27 #include <iostream> |
3990 | 28 #include <string> |
29 | |
30 #include "DASRT.h" | |
31 #include "lo-mappers.h" | |
32 | |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14854
diff
changeset
|
33 #include "defun.h" |
3990 | 34 #include "error.h" |
35 #include "gripes.h" | |
36 #include "oct-obj.h" | |
37 #include "ov-fcn.h" | |
5729 | 38 #include "ov-cell.h" |
3990 | 39 #include "pager.h" |
40 #include "parse.h" | |
41 #include "unwind-prot.h" | |
42 #include "utils.h" | |
43 #include "variables.h" | |
44 | |
3998 | 45 #include "DASRT-opts.cc" |
46 | |
4115 | 47 // Global pointers for user defined function required by dasrt. |
3990 | 48 static octave_function *dasrt_f; |
49 static octave_function *dasrt_j; | |
50 static octave_function *dasrt_cf; | |
51 | |
4140 | 52 // Have we warned about imaginary values returned from user function? |
53 static bool warned_fcn_imaginary = false; | |
54 static bool warned_jac_imaginary = false; | |
55 static bool warned_cf_imaginary = false; | |
56 | |
3990 | 57 // Is this a recursive call? |
58 static int call_depth = 0; | |
59 | |
60 static ColumnVector | |
4628 | 61 dasrt_user_f (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&) |
3990 | 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 ()); |
3990 | 67 |
4628 | 68 octave_value_list args; |
3990 | 69 |
3993 | 70 args(2) = t; |
4628 | 71 args(1) = xdot; |
72 args(0) = x; | |
3990 | 73 |
74 if (dasrt_f) | |
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 = dasrt_f->do_multi_index_op (1, args); |
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
81 } |
20785
b6f2909e7f94
always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
82 catch (octave_execution_exception& e) |
20725
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
83 { |
20756
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20725
diff
changeset
|
84 gripe_user_supplied_eval (e, "dasrt"); |
20725
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
85 } |
3990 | 86 |
87 if (tmp.length () > 0 && tmp(0).is_defined ()) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
88 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
89 if (! warned_fcn_imaginary && tmp(0).is_complex_type ()) |
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 warning ("dasrt: ignoring imaginary part returned from user-supplied function"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
92 warned_fcn_imaginary = true; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
93 } |
4140 | 94 |
20703
85e5efae848a
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20687
diff
changeset
|
95 retval = tmp(0).vector_value (); |
3990 | 96 |
20703
85e5efae848a
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20687
diff
changeset
|
97 if (retval.numel () == 0) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
98 gripe_user_supplied_eval ("dasrt"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
99 } |
3990 | 100 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
101 gripe_user_supplied_eval ("dasrt"); |
3990 | 102 } |
103 | |
104 return retval; | |
105 } | |
106 | |
107 static ColumnVector | |
108 dasrt_user_cf (const ColumnVector& x, double t) | |
109 { | |
110 ColumnVector retval; | |
111 | |
112 octave_value_list args; | |
113 | |
114 args(1) = t; | |
4628 | 115 args(0) = x; |
3990 | 116 |
117 if (dasrt_cf) | |
118 { | |
20725
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
119 octave_value_list tmp; |
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
120 |
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
121 try |
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
122 { |
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
123 tmp = dasrt_cf->do_multi_index_op (1, args); |
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
124 } |
20785
b6f2909e7f94
always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
125 catch (octave_execution_exception& e) |
20725
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
126 { |
20756
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20725
diff
changeset
|
127 gripe_user_supplied_eval (e, "dasrt"); |
20725
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
128 } |
3990 | 129 |
130 if (tmp.length () > 0 && tmp(0).is_defined ()) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
131 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
132 if (! warned_cf_imaginary && tmp(0).is_complex_type ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
133 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
134 warning ("dasrt: ignoring imaginary part returned from user-supplied constraint function"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
135 warned_cf_imaginary = true; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
136 } |
4140 | 137 |
20703
85e5efae848a
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20687
diff
changeset
|
138 retval = tmp(0).vector_value (); |
3990 | 139 |
20703
85e5efae848a
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20687
diff
changeset
|
140 if (retval.numel () == 0) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
141 gripe_user_supplied_eval ("dasrt"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
142 } |
3990 | 143 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
144 gripe_user_supplied_eval ("dasrt"); |
3990 | 145 } |
146 | |
147 return retval; | |
148 } | |
149 | |
150 static Matrix | |
3993 | 151 dasrt_user_j (const ColumnVector& x, const ColumnVector& xdot, |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
152 double t, double cj) |
3990 | 153 { |
154 Matrix retval; | |
155 | |
20229
5dfaaaae784f
Deprecate Array::capacity() and Sparse::capacity() for numel() and nzmax().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
156 assert (x.numel () == xdot.numel ()); |
3990 | 157 |
3993 | 158 octave_value_list args; |
159 | |
160 args(3) = cj; | |
161 args(2) = t; | |
4628 | 162 args(1) = xdot; |
163 args(0) = x; | |
3990 | 164 |
3993 | 165 if (dasrt_j) |
166 { | |
20725
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
167 octave_value_list tmp; |
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
168 |
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
169 try |
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
170 { |
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
171 tmp = dasrt_j->do_multi_index_op (1, args); |
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
172 } |
20785
b6f2909e7f94
always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
173 catch (octave_execution_exception& e) |
20725
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
174 { |
20756
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20725
diff
changeset
|
175 gripe_user_supplied_eval (e, "dasrt"); |
20725
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
176 } |
3990 | 177 |
3993 | 178 int tlen = tmp.length (); |
179 if (tlen > 0 && tmp(0).is_defined ()) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
180 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
181 if (! warned_jac_imaginary && tmp(0).is_complex_type ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
182 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
183 warning ("dasrt: ignoring imaginary part returned from user-supplied jacobian function"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
184 warned_jac_imaginary = true; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
185 } |
4140 | 186 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
187 retval = tmp(0).matrix_value (); |
3990 | 188 |
20703
85e5efae848a
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20687
diff
changeset
|
189 if (retval.numel () == 0) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
190 gripe_user_supplied_eval ("dasrt"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
191 } |
3990 | 192 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
193 gripe_user_supplied_eval ("dasrt"); |
3990 | 194 } |
195 | |
196 return retval; | |
197 } | |
198 | |
199 #define DASRT_ABORT \ | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
200 return retval |
3990 | 201 |
202 #define DASRT_ABORT1(msg) \ | |
203 do \ | |
204 { \ | |
20428
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
205 error ("dasrt: " msg); \ |
3990 | 206 DASRT_ABORT; \ |
207 } \ | |
208 while (0) | |
209 | |
210 #define DASRT_ABORT2(fmt, arg) \ | |
211 do \ | |
212 { \ | |
20428
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
213 error ("dasrt: " fmt, arg); \ |
3990 | 214 DASRT_ABORT; \ |
215 } \ | |
216 while (0) | |
217 | |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14854
diff
changeset
|
218 DEFUN (dasrt, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
219 "-*- texinfo -*-\n\ |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14854
diff
changeset
|
220 @deftypefn {Built-in Function} {[@var{x}, @var{xdot}, @var{t_out}, @var{istat}, @var{msg}] =} dasrt (@var{fcn}, [], @var{x_0}, @var{xdot_0}, @var{t})\n\ |
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14854
diff
changeset
|
221 @deftypefnx {Built-in Function} {@dots{} =} dasrt (@var{fcn}, @var{g}, @var{x_0}, @var{xdot_0}, @var{t})\n\ |
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14854
diff
changeset
|
222 @deftypefnx {Built-in Function} {@dots{} =} dasrt (@var{fcn}, [], @var{x_0}, @var{xdot_0}, @var{t}, @var{t_crit})\n\ |
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14854
diff
changeset
|
223 @deftypefnx {Built-in Function} {@dots{} =} dasrt (@var{fcn}, @var{g}, @var{x_0}, @var{xdot_0}, @var{t}, @var{t_crit})\n\ |
4115 | 224 Solve the set of differential-algebraic equations\n\ |
225 @tex\n\ | |
4852 | 226 $$ 0 = f (x, \\dot{x}, t) $$\n\ |
4115 | 227 with\n\ |
228 $$ x(t_0) = x_0, \\dot{x}(t_0) = \\dot{x}_0 $$\n\ | |
229 @end tex\n\ | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7017
diff
changeset
|
230 @ifnottex\n\ |
3990 | 231 \n\ |
232 @example\n\ | |
4852 | 233 0 = f (x, xdot, t)\n\ |
4115 | 234 @end example\n\ |
235 \n\ | |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10840
diff
changeset
|
236 @noindent\n\ |
4115 | 237 with\n\ |
238 \n\ | |
239 @example\n\ | |
240 x(t_0) = x_0, xdot(t_0) = xdot_0\n\ | |
3990 | 241 @end example\n\ |
242 \n\ | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7017
diff
changeset
|
243 @end ifnottex\n\ |
4115 | 244 with functional stopping criteria (root solving).\n\ |
245 \n\ | |
246 The solution is returned in the matrices @var{x} and @var{xdot},\n\ | |
247 with each row in the result matrices corresponding to one of the\n\ | |
248 elements in the vector @var{t_out}. The first element of @var{t}\n\ | |
249 should be @math{t_0} and correspond to the initial state of the\n\ | |
250 system @var{x_0} and its derivative @var{xdot_0}, so that the first\n\ | |
251 row of the output @var{x} is @var{x_0} and the first row\n\ | |
252 of the output @var{xdot} is @var{xdot_0}.\n\ | |
253 \n\ | |
254 The vector @var{t} provides an upper limit on the length of the\n\ | |
255 integration. If the stopping condition is met, the vector\n\ | |
256 @var{t_out} will be shorter than @var{t}, and the final element of\n\ | |
257 @var{t_out} will be the point at which the stopping condition was met,\n\ | |
258 and may not correspond to any element of the vector @var{t}.\n\ | |
259 \n\ | |
8787 | 260 The first argument, @var{fcn}, is a string, inline, or function handle\n\ |
261 that names the function @math{f} to call to compute the vector of\n\ | |
262 residuals for the set of equations. It must have the form\n\ | |
3990 | 263 \n\ |
264 @example\n\ | |
4115 | 265 @var{res} = f (@var{x}, @var{xdot}, @var{t})\n\ |
3990 | 266 @end example\n\ |
267 \n\ | |
268 @noindent\n\ | |
4115 | 269 in which @var{x}, @var{xdot}, and @var{res} are vectors, and @var{t} is a\n\ |
270 scalar.\n\ | |
271 \n\ | |
8787 | 272 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
|
273 of strings, inline functions, or function handles, the first element names\n\ |
8787 | 274 the function @math{f} described above, and the second element names a\n\ |
275 function to compute the modified Jacobian\n\ | |
3990 | 276 \n\ |
4115 | 277 @tex\n\ |
278 $$\n\ | |
279 J = {\\partial f \\over \\partial x}\n\ | |
280 + c {\\partial f \\over \\partial \\dot{x}}\n\ | |
281 $$\n\ | |
282 @end tex\n\ | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7017
diff
changeset
|
283 @ifnottex\n\ |
3990 | 284 \n\ |
4115 | 285 @example\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
286 @group\n\ |
4115 | 287 df df\n\ |
288 jac = -- + c ------\n\ | |
289 dx d xdot\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
290 @end group\n\ |
4115 | 291 @end example\n\ |
292 \n\ | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7017
diff
changeset
|
293 @end ifnottex\n\ |
4115 | 294 \n\ |
295 The modified Jacobian function must have the form\n\ | |
296 \n\ | |
297 @example\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
298 @group\n\ |
3990 | 299 \n\ |
4115 | 300 @var{jac} = j (@var{x}, @var{xdot}, @var{t}, @var{c})\n\ |
301 \n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
302 @end group\n\ |
4115 | 303 @end example\n\ |
3990 | 304 \n\ |
4115 | 305 The optional second argument names a function that defines the\n\ |
306 constraint functions whose roots are desired during the integration.\n\ | |
307 This function must have the form\n\ | |
3990 | 308 \n\ |
4115 | 309 @example\n\ |
310 @var{g_out} = g (@var{x}, @var{t})\n\ | |
311 @end example\n\ | |
3990 | 312 \n\ |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10840
diff
changeset
|
313 @noindent\n\ |
4115 | 314 and return a vector of the constraint function values.\n\ |
10840 | 315 If the value of any of the constraint functions changes sign, @sc{dasrt}\n\ |
4115 | 316 will attempt to stop the integration at the point of the sign change.\n\ |
317 \n\ | |
318 If the name of the constraint function is omitted, @code{dasrt} solves\n\ | |
4852 | 319 the same problem as @code{daspk} or @code{dassl}.\n\ |
3990 | 320 \n\ |
4115 | 321 Note that because of numerical errors in the constraint functions\n\ |
10840 | 322 due to round-off and integration error, @sc{dasrt} may return false\n\ |
4115 | 323 roots, or return the same root at two or more nearly equal values of\n\ |
324 @var{T}. If such false roots are suspected, the user should consider\n\ | |
325 smaller error tolerances or higher precision in the evaluation of the\n\ | |
326 constraint functions.\n\ | |
3990 | 327 \n\ |
4115 | 328 If a root of some constraint function defines the end of the problem,\n\ |
10840 | 329 the input to @sc{dasrt} should nevertheless allow integration to a\n\ |
330 point slightly past that root, so that @sc{dasrt} can locate the root\n\ | |
4115 | 331 by interpolation.\n\ |
3990 | 332 \n\ |
4115 | 333 The third and fourth arguments to @code{dasrt} specify the initial\n\ |
334 condition of the states and their derivatives, and the fourth argument\n\ | |
335 specifies a vector of output times at which the solution is desired,\n\ | |
336 including the time corresponding to the initial condition.\n\ | |
337 \n\ | |
338 The set of initial states and derivatives are not strictly required to\n\ | |
10840 | 339 be consistent. In practice, however, @sc{dassl} is not very good at\n\ |
4115 | 340 determining a consistent set for you, so it is best if you ensure that\n\ |
341 the initial values result in the function evaluating to zero.\n\ | |
3990 | 342 \n\ |
4115 | 343 The sixth argument is optional, and may be used to specify a set of\n\ |
344 times that the DAE solver should not integrate past. It is useful for\n\ | |
345 avoiding difficulties with singularities and points where there is a\n\ | |
346 discontinuity in the derivative.\n\ | |
3990 | 347 \n\ |
4115 | 348 After a successful computation, the value of @var{istate} will be\n\ |
10840 | 349 greater than zero (consistent with the Fortran version of @sc{dassl}).\n\ |
4115 | 350 \n\ |
351 If the computation is not successful, the value of @var{istate} will be\n\ | |
352 less than zero and @var{msg} will contain additional information.\n\ | |
3990 | 353 \n\ |
354 You can use the function @code{dasrt_options} to set optional\n\ | |
355 parameters for @code{dasrt}.\n\ | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
356 @seealso{dasrt_options, daspk, dasrt, lsode}\n\ |
5642 | 357 @end deftypefn") |
3990 | 358 { |
359 octave_value_list retval; | |
360 | |
4140 | 361 warned_fcn_imaginary = false; |
362 warned_jac_imaginary = false; | |
363 warned_cf_imaginary = false; | |
364 | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
365 unwind_protect frame; |
3990 | 366 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
367 frame.protect_var (call_depth); |
3990 | 368 call_depth++; |
369 | |
370 if (call_depth > 1) | |
371 DASRT_ABORT1 ("invalid recursive call"); | |
372 | |
373 int nargin = args.length (); | |
374 | |
375 if (nargin < 4 || nargin > 6) | |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
376 print_usage (); |
3990 | 377 |
20812
d9ca869ca124
maint: Clean-up more instances of print_usage().
Rik <rik@octave.org>
parents:
20802
diff
changeset
|
378 int argp = 0; |
5729 | 379 std::string fcn_name, fname, jac_name, jname; |
3990 | 380 dasrt_f = 0; |
381 dasrt_j = 0; | |
382 dasrt_cf = 0; | |
383 | |
384 // Check all the arguments. Are they the right animals? | |
385 | |
386 // Here's where I take care of f and j in one shot: | |
387 | |
388 octave_value f_arg = args(0); | |
389 | |
5729 | 390 if (f_arg.is_cell ()) |
3990 | 391 { |
5729 | 392 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
|
393 if (c.numel () == 1) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
394 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
|
395 else if (c.numel () == 2) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
396 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
397 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
|
398 dasrt_f = c(0).function_value (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
399 else |
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 fcn_name = unique_symbol_name ("__dasrt_fcn__"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
402 fname = "function y = "; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
403 fname.append (fcn_name); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
404 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
|
405 dasrt_f = extract_function (c(0), "dasrt", fcn_name, fname, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
406 "; endfunction"); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
407 } |
5729 | 408 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
409 if (dasrt_f) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
410 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
411 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
|
412 dasrt_j = c(1).function_value (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
413 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
414 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
415 jac_name = unique_symbol_name ("__dasrt_jac__"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
416 jname = "function jac = "; |
14854
5ae9f0f77635
maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
417 jname.append (jac_name); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
418 jname.append (" (x, xdot, t, cj) jac = "); |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
419 dasrt_j = extract_function (c(1), "dasrt", jac_name, jname, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
420 "; endfunction"); |
5729 | 421 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
422 if (!dasrt_j) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
423 { |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
424 if (fcn_name.length ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
425 clear_function (fcn_name); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
426 dasrt_f = 0; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
427 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
428 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
429 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
430 } |
5729 | 431 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
432 DASRT_ABORT1 ("incorrect number of elements in cell array"); |
5729 | 433 } |
434 | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
435 if (!dasrt_f && ! f_arg.is_cell ()) |
5729 | 436 { |
437 if (f_arg.is_function_handle () || f_arg.is_inline_function ()) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
438 dasrt_f = f_arg.function_value (); |
5729 | 439 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
440 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
441 switch (f_arg.rows ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
442 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
443 case 1: |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
444 fcn_name = unique_symbol_name ("__dasrt_fcn__"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
445 fname = "function y = "; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
446 fname.append (fcn_name); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
447 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
|
448 dasrt_f = extract_function (f_arg, "dasrt", fcn_name, fname, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
449 "; endfunction"); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
450 break; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
451 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
452 case 2: |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
453 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
454 string_vector tmp = args(0).all_strings (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
455 |
20557
b10432a40432
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
456 fcn_name = unique_symbol_name ("__dasrt_fcn__"); |
b10432a40432
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
457 fname = "function y = "; |
b10432a40432
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
458 fname.append (fcn_name); |
b10432a40432
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
459 fname.append (" (x, xdot, t) y = "); |
b10432a40432
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
460 dasrt_f = extract_function (tmp(0), "dasrt", fcn_name, |
b10432a40432
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
461 fname, "; endfunction"); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
462 |
20557
b10432a40432
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
463 if (dasrt_f) |
b10432a40432
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
464 { |
b10432a40432
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
465 jac_name = unique_symbol_name ("__dasrt_jac__"); |
b10432a40432
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
466 jname = "function jac = "; |
b10432a40432
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
467 jname.append (jac_name); |
b10432a40432
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
468 jname.append (" (x, xdot, t, cj) jac = "); |
b10432a40432
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
469 dasrt_j = extract_function (tmp(1), "dasrt", jac_name, |
b10432a40432
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
470 jname, "; endfunction"); |
5729 | 471 |
20557
b10432a40432
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
472 if (! dasrt_j) |
b10432a40432
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
473 dasrt_f = 0; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
474 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
475 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
476 break; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
477 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
478 default: |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
479 DASRT_ABORT1 |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
480 ("first arg should be a string or 2-element string array"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
481 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
482 } |
3990 | 483 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
484 |
20703
85e5efae848a
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20687
diff
changeset
|
485 if (! dasrt_f) |
3990 | 486 DASRT_ABORT; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
487 |
3990 | 488 DAERTFunc func (dasrt_user_f); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
489 |
3990 | 490 argp++; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
491 |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
492 if (args(1).is_function_handle () || args(1).is_inline_function ()) |
5729 | 493 { |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
494 dasrt_cf = args(1).function_value (); |
5729 | 495 |
496 if (! dasrt_cf) | |
20711
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20703
diff
changeset
|
497 DASRT_ABORT1 ("invalid constraint function G"); |
5729 | 498 |
499 argp++; | |
500 | |
501 func.set_constraint_function (dasrt_user_cf); | |
502 } | |
503 else if (args(1).is_string ()) | |
3990 | 504 { |
505 dasrt_cf = is_valid_function (args(1), "dasrt", true); | |
506 if (! dasrt_cf) | |
20711
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20703
diff
changeset
|
507 DASRT_ABORT1 ("invalid constraint function G"); |
3990 | 508 |
509 argp++; | |
510 | |
511 func.set_constraint_function (dasrt_user_cf); | |
512 } | |
513 | |
20711
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20703
diff
changeset
|
514 ColumnVector state = args(argp).xvector_value ("dasrt: initial state X_0 must be a vector"); |
3990 | 515 |
20711
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20703
diff
changeset
|
516 ColumnVector stateprime = args(argp).xvector_value ("dasrt: initial derivatives XDOT_0 must be a vector"); |
20703
85e5efae848a
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20687
diff
changeset
|
517 argp++; |
3990 | 518 |
20711
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20703
diff
changeset
|
519 ColumnVector out_times = args(argp).xvector_value ("dasrt: output time variable T must be a vector"); |
20703
85e5efae848a
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20687
diff
changeset
|
520 argp++; |
3990 | 521 |
3994 | 522 double tzero = out_times (0); |
3990 | 523 |
524 ColumnVector crit_times; | |
525 | |
526 bool crit_times_set = false; | |
527 | |
528 if (argp < nargin) | |
529 { | |
20711
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20703
diff
changeset
|
530 crit_times = args(argp).xvector_value ("dasrt: list of critical times T_CRIT must be a vector"); |
20703
85e5efae848a
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20687
diff
changeset
|
531 argp++; |
3990 | 532 |
533 crit_times_set = true; | |
534 } | |
535 | |
536 if (dasrt_j) | |
537 func.set_jacobian_function (dasrt_user_j); | |
538 | |
539 DASRT_result output; | |
540 | |
3992 | 541 DASRT dae = DASRT (state, stateprime, tzero, func); |
3990 | 542 |
4122 | 543 dae.set_options (dasrt_opts); |
3990 | 544 |
545 if (crit_times_set) | |
546 output = dae.integrate (out_times, crit_times); | |
547 else | |
548 output = dae.integrate (out_times); | |
549 | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
550 if (fcn_name.length ()) |
5729 | 551 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:
14138
diff
changeset
|
552 if (jac_name.length ()) |
5729 | 553 clear_function (jac_name); |
554 | |
20557
b10432a40432
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
555 std::string msg = dae.error_message (); |
3997 | 556 |
20557
b10432a40432
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
557 retval(4) = msg; |
b10432a40432
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
558 retval(3) = static_cast<double> (dae.integration_state ()); |
3997 | 559 |
20557
b10432a40432
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
560 if (dae.integration_ok ()) |
b10432a40432
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
561 { |
b10432a40432
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
562 retval(2) = output.times (); |
b10432a40432
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
563 retval(1) = output.deriv (); |
b10432a40432
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
564 retval(0) = output.state (); |
b10432a40432
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
565 } |
b10432a40432
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
566 else |
b10432a40432
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
567 { |
b10432a40432
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
568 retval(2) = Matrix (); |
b10432a40432
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
569 retval(1) = Matrix (); |
b10432a40432
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
570 retval(0) = Matrix (); |
3997 | 571 |
20557
b10432a40432
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
572 if (nargout < 4) |
b10432a40432
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
573 error ("dasrt: %s", msg.c_str ()); |
3990 | 574 } |
575 | |
576 return retval; | |
577 } |