annotate libinterp/corefcn/dasrt.cc @ 24211:7b74355c8e9d stable

Correct calling forms of dasrt in docstring. * dasrt.cc (Fdasrt): Correct calling forms which do not have a constraint function.
author Rik <rik@octave.org>
date Wed, 08 Nov 2017 12:01:33 -0800
parents affd98ae79ef
children 39d05d70ea60
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
1 /*
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
2
23219
3ac9f9ecfae5 maint: Update copyright dates.
John W. Eaton <jwe@octave.org>
parents: 23083
diff changeset
3 Copyright (C) 2002-2017 John W. Eaton
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
4
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
6
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5823
diff changeset
9 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5823
diff changeset
10 option) any later version.
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
11
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
15 for more details.
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
16
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5823
diff changeset
18 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5823
diff changeset
19 <http://www.gnu.org/licenses/>.
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
20
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
21 */
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
22
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
23 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21200
diff changeset
24 # include "config.h"
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
25 #endif
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
26
4052
c2562b2593e2 [project @ 2002-08-17 22:15:13 by jwe]
jwe
parents: 4035
diff changeset
27 #include <iostream>
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
28 #include <string>
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
29
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
30 #include "DASRT.h"
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
31 #include "lo-mappers.h"
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
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
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
34 #include "error.h"
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 20990
diff changeset
35 #include "errwarn.h"
20940
48b2ad5ee801 maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents: 20918
diff changeset
36 #include "ovl.h"
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
37 #include "ov-fcn.h"
5729
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
38 #include "ov-cell.h"
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
39 #include "pager.h"
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
40 #include "parse.h"
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
41 #include "unwind-prot.h"
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
42 #include "utils.h"
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
43 #include "variables.h"
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
44
3998
f6df65db67f9 [project @ 2002-07-24 18:10:39 by jwe]
jwe
parents: 3997
diff changeset
45 #include "DASRT-opts.cc"
f6df65db67f9 [project @ 2002-07-24 18:10:39 by jwe]
jwe
parents: 3997
diff changeset
46
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
47 // Global pointers for user defined function required by dasrt.
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
48 static octave_function *dasrt_f;
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
49 static octave_function *dasrt_j;
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
50 static octave_function *dasrt_cf;
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
51
4140
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
52 // Have we warned about imaginary values returned from user function?
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
53 static bool warned_fcn_imaginary = false;
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
54 static bool warned_jac_imaginary = false;
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
55 static bool warned_cf_imaginary = false;
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
56
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
57 // Is this a recursive call?
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
58 static int call_depth = 0;
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
59
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
60 static ColumnVector
4628
c0121a3b9cbe [project @ 2003-11-17 20:19:07 by jwe]
jwe
parents: 4140
diff changeset
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
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
63 {
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
64 ColumnVector retval;
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
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
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
67
4628
c0121a3b9cbe [project @ 2003-11-17 20:19:07 by jwe]
jwe
parents: 4140
diff changeset
68 octave_value_list args;
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
69
3993
f23bc69132cc [project @ 2002-07-16 20:18:56 by jwe]
jwe
parents: 3992
diff changeset
70 args(2) = t;
4628
c0121a3b9cbe [project @ 2003-11-17 20:19:07 by jwe]
jwe
parents: 4140
diff changeset
71 args(1) = xdot;
c0121a3b9cbe [project @ 2003-11-17 20:19:07 by jwe]
jwe
parents: 4140
diff changeset
72 args(0) = x;
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
73
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
74 if (dasrt_f)
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
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 }
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
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 {
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 20990
diff changeset
84 err_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
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
86
21885
0806871e3e1e maint: Prefer is_empty() rather than "length () == 0".
Rik <rik@octave.org>
parents: 21743
diff changeset
87 if (tmp.empty () || ! tmp(0).is_defined ())
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
88 err_user_supplied_eval ("dasrt");
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
89
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
90 if (! warned_fcn_imaginary && tmp(0).is_complex_type ())
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
91 {
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
92 warning ("dasrt: ignoring imaginary part returned from user-supplied function");
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
93 warned_fcn_imaginary = true;
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
94 }
4140
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
95
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
96 retval = tmp(0).vector_value ();
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
97
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
98 if (retval.is_empty ())
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 20990
diff changeset
99 err_user_supplied_eval ("dasrt");
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
100 }
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
101
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
102 return retval;
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
103 }
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
104
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
105 static ColumnVector
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
106 dasrt_user_cf (const ColumnVector& x, double t)
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
107 {
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
108 ColumnVector retval;
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
109
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
110 octave_value_list args;
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
111
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
112 args(1) = t;
4628
c0121a3b9cbe [project @ 2003-11-17 20:19:07 by jwe]
jwe
parents: 4140
diff changeset
113 args(0) = x;
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
114
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
115 if (dasrt_cf)
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
116 {
20725
7164a69472dd eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
117 octave_value_list tmp;
7164a69472dd eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
118
7164a69472dd eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
119 try
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 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
122 }
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
123 catch (octave::execution_exception& e)
20725
7164a69472dd eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
124 {
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 20990
diff changeset
125 err_user_supplied_eval (e, "dasrt");
20725
7164a69472dd eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
126 }
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
127
21885
0806871e3e1e maint: Prefer is_empty() rather than "length () == 0".
Rik <rik@octave.org>
parents: 21743
diff changeset
128 if (tmp.empty () || ! tmp(0).is_defined ())
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
129 err_user_supplied_eval ("dasrt");
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
130
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
131 if (! warned_cf_imaginary && tmp(0).is_complex_type ())
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
132 {
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
133 warning ("dasrt: ignoring imaginary part returned from user-supplied constraint function");
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
134 warned_cf_imaginary = true;
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
135 }
4140
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
136
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
137 retval = tmp(0).vector_value ();
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
138
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
139 if (retval.is_empty ())
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 20990
diff changeset
140 err_user_supplied_eval ("dasrt");
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
141 }
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
142
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
143 return retval;
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
144 }
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
145
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
146 static Matrix
3993
f23bc69132cc [project @ 2002-07-16 20:18:56 by jwe]
jwe
parents: 3992
diff changeset
147 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
148 double t, double cj)
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
149 {
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
150 Matrix retval;
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
151
20229
5dfaaaae784f Deprecate Array::capacity() and Sparse::capacity() for numel() and nzmax().
Carnë Draug <carandraug@octave.org>
parents: 19697
diff changeset
152 assert (x.numel () == xdot.numel ());
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
153
3993
f23bc69132cc [project @ 2002-07-16 20:18:56 by jwe]
jwe
parents: 3992
diff changeset
154 octave_value_list args;
f23bc69132cc [project @ 2002-07-16 20:18:56 by jwe]
jwe
parents: 3992
diff changeset
155
f23bc69132cc [project @ 2002-07-16 20:18:56 by jwe]
jwe
parents: 3992
diff changeset
156 args(3) = cj;
f23bc69132cc [project @ 2002-07-16 20:18:56 by jwe]
jwe
parents: 3992
diff changeset
157 args(2) = t;
4628
c0121a3b9cbe [project @ 2003-11-17 20:19:07 by jwe]
jwe
parents: 4140
diff changeset
158 args(1) = xdot;
c0121a3b9cbe [project @ 2003-11-17 20:19:07 by jwe]
jwe
parents: 4140
diff changeset
159 args(0) = x;
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
160
3993
f23bc69132cc [project @ 2002-07-16 20:18:56 by jwe]
jwe
parents: 3992
diff changeset
161 if (dasrt_j)
f23bc69132cc [project @ 2002-07-16 20:18:56 by jwe]
jwe
parents: 3992
diff changeset
162 {
20725
7164a69472dd eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
163 octave_value_list tmp;
7164a69472dd eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
164
7164a69472dd eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
165 try
7164a69472dd eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
166 {
7164a69472dd eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
167 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
168 }
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
169 catch (octave::execution_exception& e)
20725
7164a69472dd eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
170 {
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 20990
diff changeset
171 err_user_supplied_eval (e, "dasrt");
20725
7164a69472dd eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
172 }
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
173
3993
f23bc69132cc [project @ 2002-07-16 20:18:56 by jwe]
jwe
parents: 3992
diff changeset
174 int tlen = tmp.length ();
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
175 if (tlen == 0 || ! tmp(0).is_defined ())
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
176 err_user_supplied_eval ("dasrt");
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
177
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
178 if (! warned_jac_imaginary && tmp(0).is_complex_type ())
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
179 {
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
180 warning ("dasrt: ignoring imaginary part returned from user-supplied jacobian function");
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
181 warned_jac_imaginary = true;
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
182 }
4140
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
183
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
184 retval = tmp(0).matrix_value ();
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
185
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
186 if (retval.is_empty ())
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 20990
diff changeset
187 err_user_supplied_eval ("dasrt");
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
188 }
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
189
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
190 return retval;
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
191 }
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
192
15039
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14854
diff changeset
193 DEFUN (dasrt, args, nargout,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
194 doc: /* -*- texinfo -*-
24211
7b74355c8e9d Correct calling forms of dasrt in docstring.
Rik <rik@octave.org>
parents: 24205
diff changeset
195 @deftypefn {} {[@var{x}, @var{xdot}, @var{t_out}, @var{istat}, @var{msg}] =} dasrt (@var{fcn}, @var{g}, @var{x_0}, @var{xdot_0}, @var{t})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
196 @deftypefnx {} {@dots{} =} dasrt (@var{fcn}, @var{g}, @var{x_0}, @var{xdot_0}, @var{t}, @var{t_crit})
24211
7b74355c8e9d Correct calling forms of dasrt in docstring.
Rik <rik@octave.org>
parents: 24205
diff changeset
197 @deftypefnx {} {@dots{} =} dasrt (@var{fcn}, @var{x_0}, @var{xdot_0}, @var{t})
7b74355c8e9d Correct calling forms of dasrt in docstring.
Rik <rik@octave.org>
parents: 24205
diff changeset
198 @deftypefnx {} {@dots{} =} dasrt (@var{fcn}, @var{x_0}, @var{xdot_0}, @var{t}, @var{t_crit})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
199 Solve the set of differential-algebraic equations
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
200 @tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
201 $$ 0 = f (x, \dot{x}, t) $$
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
202 with
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
203 $$ x(t_0) = x_0, \dot{x}(t_0) = \dot{x}_0 $$
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
204 @end tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
205 @ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
206
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
207 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
208 0 = f (x, xdot, t)
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
209 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
210
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
211 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
212 with
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
213
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
214 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
215 x(t_0) = x_0, xdot(t_0) = xdot_0
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
216 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
217
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
218 @end ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
219 with functional stopping criteria (root solving).
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
220
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
221 The solution is returned in the matrices @var{x} and @var{xdot},
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
222 with each row in the result matrices corresponding to one of the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
223 elements in the vector @var{t_out}. The first element of @var{t}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
224 should be @math{t_0} and correspond to the initial state of the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
225 system @var{x_0} and its derivative @var{xdot_0}, so that the first
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
226 row of the output @var{x} is @var{x_0} and the first row
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
227 of the output @var{xdot} is @var{xdot_0}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
228
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
229 The vector @var{t} provides an upper limit on the length of the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
230 integration. If the stopping condition is met, the vector
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
231 @var{t_out} will be shorter than @var{t}, and the final element of
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
232 @var{t_out} will be the point at which the stopping condition was met,
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
233 and may not correspond to any element of the vector @var{t}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
234
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
235 The first argument, @var{fcn}, is a string, inline, or function handle
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
236 that names the function @math{f} to call to compute the vector of
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
237 residuals for the set of equations. It must have the form
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
238
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
239 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
240 @var{res} = f (@var{x}, @var{xdot}, @var{t})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
241 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
242
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
243 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
244 in which @var{x}, @var{xdot}, and @var{res} are vectors, and @var{t} is a
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
245 scalar.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
246
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
247 If @var{fcn} is a two-element string array or a two-element cell array
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
248 of strings, inline functions, or function handles, the first element names
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
249 the function @math{f} described above, and the second element names a
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
250 function to compute the modified Jacobian
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
251
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
252 @tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
253 $$
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
254 J = {\partial f \over \partial x}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
255 + c {\partial f \over \partial \dot{x}}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
256 $$
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
257 @end tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
258 @ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
259
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
260 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
261 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
262 df df
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
263 jac = -- + c ------
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
264 dx d xdot
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
265 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
266 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
267
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
268 @end ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
269
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
270 The modified Jacobian function must have the form
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
271
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
272 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
273 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
274
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
275 @var{jac} = j (@var{x}, @var{xdot}, @var{t}, @var{c})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
276
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
277 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
278 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
279
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
280 The optional second argument names a function that defines the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
281 constraint functions whose roots are desired during the integration.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
282 This function must have the form
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
283
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
284 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
285 @var{g_out} = g (@var{x}, @var{t})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
286 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
287
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
288 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
289 and return a vector of the constraint function values.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
290 If the value of any of the constraint functions changes sign, @sc{dasrt}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
291 will attempt to stop the integration at the point of the sign change.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
292
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
293 If the name of the constraint function is omitted, @code{dasrt} solves
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
294 the same problem as @code{daspk} or @code{dassl}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
295
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
296 Note that because of numerical errors in the constraint functions
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
297 due to round-off and integration error, @sc{dasrt} may return false
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
298 roots, or return the same root at two or more nearly equal values of
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
299 @var{T}. If such false roots are suspected, the user should consider
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
300 smaller error tolerances or higher precision in the evaluation of the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
301 constraint functions.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
302
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
303 If a root of some constraint function defines the end of the problem,
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
304 the input to @sc{dasrt} should nevertheless allow integration to a
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
305 point slightly past that root, so that @sc{dasrt} can locate the root
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
306 by interpolation.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
307
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
308 The third and fourth arguments to @code{dasrt} specify the initial
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
309 condition of the states and their derivatives, and the fourth argument
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
310 specifies a vector of output times at which the solution is desired,
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
311 including the time corresponding to the initial condition.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
312
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
313 The set of initial states and derivatives are not strictly required to
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
314 be consistent. In practice, however, @sc{dassl} is not very good at
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
315 determining a consistent set for you, so it is best if you ensure that
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
316 the initial values result in the function evaluating to zero.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
317
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
318 The sixth argument is optional, and may be used to specify a set of
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
319 times that the DAE solver should not integrate past. It is useful for
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
320 avoiding difficulties with singularities and points where there is a
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
321 discontinuity in the derivative.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
322
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
323 After a successful computation, the value of @var{istate} will be
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
324 greater than zero (consistent with the Fortran version of @sc{dassl}).
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
325
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
326 If the computation is not successful, the value of @var{istate} will be
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
327 less than zero and @var{msg} will contain additional information.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
328
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
329 You can use the function @code{dasrt_options} to set optional
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
330 parameters for @code{dasrt}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
331 @seealso{dasrt_options, daspk, dasrt, lsode}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
332 @end deftypefn */)
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
333 {
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20892
diff changeset
334 int nargin = args.length ();
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20892
diff changeset
335
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20892
diff changeset
336 if (nargin < 4 || nargin > 6)
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20892
diff changeset
337 print_usage ();
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
338
4140
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
339 warned_fcn_imaginary = false;
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
340 warned_jac_imaginary = false;
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
341 warned_cf_imaginary = false;
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
342
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20892
diff changeset
343 octave_value_list retval (5);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20892
diff changeset
344
21743
f4d7d0eb5b0c use namespace for unwind_protect class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
345 octave::unwind_protect frame;
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
346
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
347 frame.protect_var (call_depth);
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
348 call_depth++;
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
349
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
350 if (call_depth > 1)
20957
9db35d2042be maint: eliminate special cases of statements after error.
Rik <rik@octave.org>
parents: 20940
diff changeset
351 error ("dasrt: invalid recursive call");
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
352
20812
d9ca869ca124 maint: Clean-up more instances of print_usage().
Rik <rik@octave.org>
parents: 20802
diff changeset
353 int argp = 0;
5729
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
354 std::string fcn_name, fname, jac_name, jname;
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
355 dasrt_f = 0;
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
356 dasrt_j = 0;
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
357 dasrt_cf = 0;
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
358
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
359 // Check all the arguments. Are they the right animals?
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
360
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
361 // Here's where I take care of f and j in one shot:
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
362
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
363 octave_value f_arg = args(0);
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
364
5729
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
365 if (f_arg.is_cell ())
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
366 {
5729
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
367 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
368 if (c.numel () == 1)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
369 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
370 else if (c.numel () == 2)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
371 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
372 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
373 dasrt_f = c(0).function_value ();
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
374 else
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
375 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
376 fcn_name = unique_symbol_name ("__dasrt_fcn__");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
377 fname = "function y = ";
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
378 fname.append (fcn_name);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
379 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
380 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
381 "; endfunction");
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
382 }
5729
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
383
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
384 if (dasrt_f)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
385 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
386 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
387 dasrt_j = c(1).function_value ();
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
388 else
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
389 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
390 jac_name = unique_symbol_name ("__dasrt_jac__");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
391 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
392 jname.append (jac_name);
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
393 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
394 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
395 "; endfunction");
5729
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
396
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20892
diff changeset
397 if (! dasrt_j)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
398 {
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
399 if (fcn_name.length ())
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
400 clear_function (fcn_name);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
401 dasrt_f = 0;
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 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
404 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
405 }
5729
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
406 else
20957
9db35d2042be maint: eliminate special cases of statements after error.
Rik <rik@octave.org>
parents: 20940
diff changeset
407 error ("dasrt: incorrect number of elements in cell array");
5729
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
408 }
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
409
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20892
diff changeset
410 if (! dasrt_f && ! f_arg.is_cell ())
5729
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
411 {
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
412 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
413 dasrt_f = f_arg.function_value ();
5729
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
414 else
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
415 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
416 switch (f_arg.rows ())
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
417 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
418 case 1:
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
419 fcn_name = unique_symbol_name ("__dasrt_fcn__");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
420 fname = "function y = ";
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
421 fname.append (fcn_name);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
422 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
423 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
424 "; endfunction");
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
425 break;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
426
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
427 case 2:
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
428 {
20990
fc9cca99b2de Deprecate all_strings, replace with string_vector_value.
Rik <rik@octave.org>
parents: 20974
diff changeset
429 string_vector tmp = args(0).string_vector_value ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
430
20557
b10432a40432 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20428
diff changeset
431 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
432 fname = "function y = ";
b10432a40432 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20428
diff changeset
433 fname.append (fcn_name);
b10432a40432 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20428
diff changeset
434 fname.append (" (x, xdot, t) y = ");
b10432a40432 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20428
diff changeset
435 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
436 fname, "; endfunction");
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
437
20557
b10432a40432 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20428
diff changeset
438 if (dasrt_f)
b10432a40432 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20428
diff changeset
439 {
b10432a40432 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20428
diff changeset
440 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
441 jname = "function jac = ";
b10432a40432 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20428
diff changeset
442 jname.append (jac_name);
b10432a40432 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20428
diff changeset
443 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
444 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
445 jname, "; endfunction");
5729
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
446
20557
b10432a40432 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20428
diff changeset
447 if (! dasrt_j)
b10432a40432 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20428
diff changeset
448 dasrt_f = 0;
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
449 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
450 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
451 break;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
452
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
453 default:
20957
9db35d2042be maint: eliminate special cases of statements after error.
Rik <rik@octave.org>
parents: 20940
diff changeset
454 error ("dasrt: first arg should be a string or 2-element string array");
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
455 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
456 }
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
457 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
458
20703
85e5efae848a eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
459 if (! dasrt_f)
20957
9db35d2042be maint: eliminate special cases of statements after error.
Rik <rik@octave.org>
parents: 20940
diff changeset
460 return retval;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
461
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
462 DAERTFunc func (dasrt_user_f);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
463
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
464 argp++;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
465
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
466 if (args(1).is_function_handle () || args(1).is_inline_function ())
5729
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
467 {
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
468 dasrt_cf = args(1).function_value ();
5729
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
469
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
470 if (! dasrt_cf)
20957
9db35d2042be maint: eliminate special cases of statements after error.
Rik <rik@octave.org>
parents: 20940
diff changeset
471 error ("dasrt: invalid constraint function G");
5729
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
472
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
473 argp++;
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
474
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
475 func.set_constraint_function (dasrt_user_cf);
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
476 }
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
477 else if (args(1).is_string ())
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
478 {
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
479 dasrt_cf = is_valid_function (args(1), "dasrt", true);
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
480 if (! dasrt_cf)
20957
9db35d2042be maint: eliminate special cases of statements after error.
Rik <rik@octave.org>
parents: 20940
diff changeset
481 error ("dasrt: invalid constraint function G");
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
482
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
483 argp++;
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
484
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
485 func.set_constraint_function (dasrt_user_cf);
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
486 }
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
487
24205
affd98ae79ef correctly parse dasrt arguments
John W. Eaton <jwe@octave.org>
parents: 23219
diff changeset
488 ColumnVector state = args(argp++).xvector_value ("dasrt: initial state X_0 must be a vector");
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
489
24205
affd98ae79ef correctly parse dasrt arguments
John W. Eaton <jwe@octave.org>
parents: 23219
diff changeset
490 ColumnVector stateprime = args(argp++).xvector_value ("dasrt: initial derivatives XDOT_0 must be a vector");
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
491
24205
affd98ae79ef correctly parse dasrt arguments
John W. Eaton <jwe@octave.org>
parents: 23219
diff changeset
492 ColumnVector out_times = args(argp++).xvector_value ("dasrt: output time variable T must be a vector");
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
493
3994
a41827ec5677 [project @ 2002-07-16 23:57:09 by jwe]
jwe
parents: 3993
diff changeset
494 double tzero = out_times (0);
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
495
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
496 ColumnVector crit_times;
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
497
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
498 bool crit_times_set = false;
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
499
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
500 if (argp < nargin)
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
501 {
20711
7b608fadc663 Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents: 20703
diff changeset
502 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
503 argp++;
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
504
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
505 crit_times_set = true;
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
506 }
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
507
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
508 if (dasrt_j)
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
509 func.set_jacobian_function (dasrt_user_j);
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
510
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
511 DASRT_result output;
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
512
3992
53b4eab68976 [project @ 2002-07-16 19:36:52 by jwe]
jwe
parents: 3990
diff changeset
513 DASRT dae = DASRT (state, stateprime, tzero, func);
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
514
4122
19a1626b8d57 [project @ 2002-10-23 22:10:53 by jwe]
jwe
parents: 4117
diff changeset
515 dae.set_options (dasrt_opts);
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
516
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
517 if (crit_times_set)
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
518 output = dae.integrate (out_times, crit_times);
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
519 else
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
520 output = dae.integrate (out_times);
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
521
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
522 if (fcn_name.length ())
5729
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
523 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
524 if (jac_name.length ())
5729
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
525 clear_function (jac_name);
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
526
20557
b10432a40432 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20428
diff changeset
527 std::string msg = dae.error_message ();
3997
d4091aff6468 [project @ 2002-07-17 18:00:06 by jwe]
jwe
parents: 3994
diff changeset
528
20557
b10432a40432 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20428
diff changeset
529 if (dae.integration_ok ())
b10432a40432 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20428
diff changeset
530 {
20892
c07bee629973 2015 Code Sprint: use ovl ().
Rik <rik@octave.org>
parents: 20853
diff changeset
531 retval(0) = output.state ();
20557
b10432a40432 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20428
diff changeset
532 retval(1) = output.deriv ();
20892
c07bee629973 2015 Code Sprint: use ovl ().
Rik <rik@octave.org>
parents: 20853
diff changeset
533 retval(2) = output.times ();
20557
b10432a40432 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20428
diff changeset
534 }
b10432a40432 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20428
diff changeset
535 else
b10432a40432 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20428
diff changeset
536 {
b10432a40432 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20428
diff changeset
537 if (nargout < 4)
b10432a40432 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20428
diff changeset
538 error ("dasrt: %s", msg.c_str ());
20892
c07bee629973 2015 Code Sprint: use ovl ().
Rik <rik@octave.org>
parents: 20853
diff changeset
539
c07bee629973 2015 Code Sprint: use ovl ().
Rik <rik@octave.org>
parents: 20853
diff changeset
540 retval(0) = Matrix ();
c07bee629973 2015 Code Sprint: use ovl ().
Rik <rik@octave.org>
parents: 20853
diff changeset
541 retval(1) = Matrix ();
c07bee629973 2015 Code Sprint: use ovl ().
Rik <rik@octave.org>
parents: 20853
diff changeset
542 retval(2) = Matrix ();
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
543 }
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
544
20892
c07bee629973 2015 Code Sprint: use ovl ().
Rik <rik@octave.org>
parents: 20853
diff changeset
545 retval(3) = static_cast<double> (dae.integration_state ());
c07bee629973 2015 Code Sprint: use ovl ().
Rik <rik@octave.org>
parents: 20853
diff changeset
546 retval(4) = msg;
c07bee629973 2015 Code Sprint: use ovl ().
Rik <rik@octave.org>
parents: 20853
diff changeset
547
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
548 return retval;
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
549 }