Mercurial > octave
annotate libinterp/corefcn/daspk.cc @ 27923:bd51beb6205e
update formatting of copyright notices
* Use <https://octave.org/copyright/> instead of
<https://octave.org/COPYRIGHT.html/>.
* For consistency with other comments in the Octave sources, use
C++-style comments for copyright blocks in C and C++ files.
* Use delimiters above and below copyright blocks that are appropriate
for the language used in the file.
* Eliminate extra spacing inside copyright blocks.
* lex.ll (looks_like_copyright): Also allow newlines and carriage
returns before the word "Copyright".
* scripts/mk-doc.pl (gethelp): Also skip empty comment lines.
* bp-table.cc, type.m: Adjust tests.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 08 Jan 2020 11:59:41 -0500 |
parents | 1891570abac8 |
children | aef839f40da2 0a5b15007766 |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 //////////////////////////////////////////////////////////////////////// |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
3 // Copyright (C) 1996-2020 The Octave Project Developers |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
4 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 // See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 // distribution or <https://octave.org/copyright/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
7 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
8 // This file is part of Octave. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
9 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
10 // Octave is free software: you can redistribute it and/or modify it |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
11 // under the terms of the GNU General Public License as published by |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
12 // the Free Software Foundation, either version 3 of the License, or |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
13 // (at your option) any later version. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
14 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
15 // Octave is distributed in the hope that it will be useful, but |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
16 // WITHOUT ANY WARRANTY; without even the implied warranty of |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
18 // GNU General Public License for more details. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
19 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
20 // You should have received a copy of the GNU General Public License |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
21 // along with Octave; see the file COPYING. If not, see |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
22 // <https://www.gnu.org/licenses/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 //////////////////////////////////////////////////////////////////////// |
3912 | 25 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
26 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21200
diff
changeset
|
27 # include "config.h" |
3912 | 28 #endif |
29 | |
26864
041caa61ed34
use get_function_handle instead of extract_function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
30 #include <list> |
3912 | 31 #include <string> |
32 | |
33 #include "DASPK.h" | |
34 | |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14854
diff
changeset
|
35 #include "defun.h" |
3912 | 36 #include "error.h" |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21041
diff
changeset
|
37 #include "errwarn.h" |
26864
041caa61ed34
use get_function_handle instead of extract_function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
38 #include "interpreter-private.h" |
20940
48b2ad5ee801
maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents:
20918
diff
changeset
|
39 #include "ovl.h" |
3912 | 40 #include "ov-fcn.h" |
5729 | 41 #include "ov-cell.h" |
3912 | 42 #include "pager.h" |
23473
55916f99b8b6
prefer feval over do_multi_index_op
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
43 #include "parse.h" |
3912 | 44 #include "unwind-prot.h" |
45 #include "utils.h" | |
46 #include "variables.h" | |
47 | |
3998 | 48 #include "DASPK-opts.cc" |
49 | |
3912 | 50 // Global pointer for user defined function required by daspk. |
26864
041caa61ed34
use get_function_handle instead of extract_function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
51 static octave_value daspk_fcn; |
3912 | 52 |
4140 | 53 // Global pointer for optional user defined jacobian function. |
26864
041caa61ed34
use get_function_handle instead of extract_function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
54 static octave_value daspk_jac; |
4140 | 55 |
56 // Have we warned about imaginary values returned from user function? | |
57 static bool warned_fcn_imaginary = false; | |
58 static bool warned_jac_imaginary = false; | |
59 | |
3912 | 60 // Is this a recursive call? |
61 static int call_depth = 0; | |
62 | |
63 ColumnVector | |
64 daspk_user_function (const ColumnVector& x, const ColumnVector& xdot, | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
65 double t, octave_idx_type& ires) |
3912 | 66 { |
67 ColumnVector retval; | |
68 | |
20229
5dfaaaae784f
Deprecate Array::capacity() and Sparse::capacity() for numel() and nzmax().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
69 assert (x.numel () == xdot.numel ()); |
3912 | 70 |
71 octave_value_list args; | |
4628 | 72 |
3912 | 73 args(2) = t; |
4628 | 74 args(1) = xdot; |
75 args(0) = x; | |
3912 | 76 |
26864
041caa61ed34
use get_function_handle instead of extract_function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
77 if (daspk_fcn.is_defined ()) |
3912 | 78 { |
20725
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
79 octave_value_list tmp; |
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
80 |
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
81 try |
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
82 { |
23473
55916f99b8b6
prefer feval over do_multi_index_op
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
83 tmp = octave::feval (daspk_fcn, args, 1); |
20725
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
84 } |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
85 catch (octave::execution_exception& e) |
20725
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
86 { |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21041
diff
changeset
|
87 err_user_supplied_eval (e, "daspk"); |
20725
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
88 } |
3912 | 89 |
90 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
|
91 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
|
92 err_user_supplied_eval ("daspk"); |
4140 | 93 |
23581
c3075ae020e1
maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents:
23577
diff
changeset
|
94 if (! warned_fcn_imaginary && tmp(0).iscomplex ()) |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
95 { |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
96 warning ("daspk: 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
|
97 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
|
98 } |
3912 | 99 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
100 retval = tmp(0).vector_value (); |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
101 |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
102 if (tlen > 1) |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
103 ires = tmp(1).idx_type_value (); |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
104 |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23576
diff
changeset
|
105 if (retval.isempty ()) |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21041
diff
changeset
|
106 err_user_supplied_eval ("daspk"); |
3912 | 107 } |
108 | |
109 return retval; | |
110 } | |
111 | |
4140 | 112 Matrix |
113 daspk_user_jacobian (const ColumnVector& x, const ColumnVector& xdot, | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
114 double t, double cj) |
4140 | 115 { |
116 Matrix retval; | |
117 | |
20229
5dfaaaae784f
Deprecate Array::capacity() and Sparse::capacity() for numel() and nzmax().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
118 assert (x.numel () == xdot.numel ()); |
4140 | 119 |
120 octave_value_list args; | |
121 | |
122 args(3) = cj; | |
123 args(2) = t; | |
4628 | 124 args(1) = xdot; |
125 args(0) = x; | |
4140 | 126 |
26864
041caa61ed34
use get_function_handle instead of extract_function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
127 if (daspk_jac.is_defined ()) |
4140 | 128 { |
20725
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
129 octave_value_list tmp; |
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
130 |
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
131 try |
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
132 { |
23473
55916f99b8b6
prefer feval over do_multi_index_op
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
133 tmp = octave::feval (daspk_jac, args, 1); |
20725
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
134 } |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
135 catch (octave::execution_exception& e) |
20725
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
136 { |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21041
diff
changeset
|
137 err_user_supplied_eval (e, "daspk"); |
20725
7164a69472dd
eliminate more uses of error state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
138 } |
4140 | 139 |
140 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
|
141 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
|
142 err_user_supplied_eval ("daspk"); |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
143 |
23581
c3075ae020e1
maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents:
23577
diff
changeset
|
144 if (! warned_jac_imaginary && tmp(0).iscomplex ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
145 { |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
146 warning ("daspk: 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
|
147 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
|
148 } |
4140 | 149 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
150 retval = tmp(0).matrix_value (); |
4140 | 151 |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23576
diff
changeset
|
152 if (retval.isempty ()) |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21041
diff
changeset
|
153 err_user_supplied_eval ("daspk"); |
4140 | 154 } |
155 | |
156 return retval; | |
157 } | |
158 | |
23699
b29904962d2d
deprecate some global functions that access the symbol table
John W. Eaton <jwe@octave.org>
parents:
23581
diff
changeset
|
159 DEFMETHOD (daspk, interp, args, nargout, |
b29904962d2d
deprecate some global functions that access the symbol table
John W. Eaton <jwe@octave.org>
parents:
23581
diff
changeset
|
160 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
161 @deftypefn {} {[@var{x}, @var{xdot}, @var{istate}, @var{msg}] =} daspk (@var{fcn}, @var{x_0}, @var{xdot_0}, @var{t}, @var{t_crit}) |
25106
d7ad543255c5
doc: Shorten very long first sentences of docstrings (bug #53388).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
162 Solve a set of differential-algebraic equations. |
d7ad543255c5
doc: Shorten very long first sentences of docstrings (bug #53388).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
163 |
d7ad543255c5
doc: Shorten very long first sentences of docstrings (bug #53388).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
164 @code{daspk} solves the set of equations |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
165 @tex |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
166 $$ 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:
21743
diff
changeset
|
167 with |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
168 $$ 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:
21743
diff
changeset
|
169 @end tex |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
170 @ifnottex |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
171 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
172 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
173 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:
21743
diff
changeset
|
174 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
175 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
176 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
177 with |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
178 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
179 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
180 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:
21743
diff
changeset
|
181 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
182 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
183 @end ifnottex |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
184 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:
21743
diff
changeset
|
185 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:
21743
diff
changeset
|
186 elements in the vector @var{t}. 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:
21743
diff
changeset
|
187 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:
21743
diff
changeset
|
188 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:
21743
diff
changeset
|
189 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:
21743
diff
changeset
|
190 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:
21743
diff
changeset
|
191 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
192 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:
21743
diff
changeset
|
193 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:
21743
diff
changeset
|
194 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:
21743
diff
changeset
|
195 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
196 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
197 @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:
21743
diff
changeset
|
198 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
199 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
200 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
201 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:
21743
diff
changeset
|
202 scalar. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
203 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
204 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:
21743
diff
changeset
|
205 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:
21743
diff
changeset
|
206 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:
21743
diff
changeset
|
207 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:
21743
diff
changeset
|
208 @tex |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
209 $$ |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
210 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:
21743
diff
changeset
|
211 + 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:
21743
diff
changeset
|
212 $$ |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
213 @end tex |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
214 @ifnottex |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
215 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
216 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
217 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
218 df df |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
219 jac = -- + c ------ |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
220 dx d xdot |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
221 @end group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
222 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
223 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
224 @end ifnottex |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
225 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
226 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:
21743
diff
changeset
|
227 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
228 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
229 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
230 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
231 @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:
21743
diff
changeset
|
232 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
233 @end group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
234 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
235 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
236 The second and third arguments to @code{daspk} specify the initial |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
237 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:
21743
diff
changeset
|
238 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:
21743
diff
changeset
|
239 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:
21743
diff
changeset
|
240 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
241 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:
21743
diff
changeset
|
242 be consistent. If they are not consistent, you must use the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
243 @code{daspk_options} function to provide additional information so |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
244 that @code{daspk} can compute a consistent starting point. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
245 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
246 The fifth 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:
21743
diff
changeset
|
247 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:
21743
diff
changeset
|
248 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:
21743
diff
changeset
|
249 discontinuity in the derivative. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
250 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
251 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:
21743
diff
changeset
|
252 greater than zero (consistent with the Fortran version of @sc{daspk}). |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
253 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
254 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:
21743
diff
changeset
|
255 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:
21743
diff
changeset
|
256 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
257 You can use the function @code{daspk_options} to set optional |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
258 parameters for @code{daspk}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
259 @seealso{dassl} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
260 @end deftypefn */) |
3912 | 261 { |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20892
diff
changeset
|
262 int nargin = args.length (); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20892
diff
changeset
|
263 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20892
diff
changeset
|
264 if (nargin < 4 || nargin > 5) |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20892
diff
changeset
|
265 print_usage (); |
3912 | 266 |
4140 | 267 warned_fcn_imaginary = false; |
268 warned_jac_imaginary = false; | |
269 | |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20892
diff
changeset
|
270 octave_value_list retval (4); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20892
diff
changeset
|
271 |
21743
f4d7d0eb5b0c
use namespace for unwind_protect class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
272 octave::unwind_protect frame; |
3912 | 273 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
274 frame.protect_var (call_depth); |
3912 | 275 call_depth++; |
276 | |
277 if (call_depth > 1) | |
20957
9db35d2042be
maint: eliminate special cases of statements after error.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
278 error ("daspk: invalid recursive call"); |
3912 | 279 |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
280 std::string fcn_name, fname, jac_name, jname; |
26864
041caa61ed34
use get_function_handle instead of extract_function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
281 |
041caa61ed34
use get_function_handle instead of extract_function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
282 daspk_fcn = octave_value (); |
041caa61ed34
use get_function_handle instead of extract_function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
283 daspk_jac = octave_value (); |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
284 |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
285 octave_value f_arg = args(0); |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
286 |
26864
041caa61ed34
use get_function_handle instead of extract_function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
287 std::list<std::string> fcn_param_names ({"x", "xdot", "t"}); |
041caa61ed34
use get_function_handle instead of extract_function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
288 std::list<std::string> jac_param_names ({"x", "xdot", "t", "cj"}); |
041caa61ed34
use get_function_handle instead of extract_function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
289 |
23576
00e518162fda
maint: Deprecate is_cell and replace with iscell.
Rik <rik@octave.org>
parents:
23473
diff
changeset
|
290 if (f_arg.iscell ()) |
3912 | 291 { |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
292 Cell c = f_arg.cell_value (); |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
293 if (c.numel () == 1) |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
294 f_arg = c(0); |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
295 else if (c.numel () == 2) |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
296 { |
26864
041caa61ed34
use get_function_handle instead of extract_function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
297 daspk_fcn = octave::get_function_handle (interp, c(0), |
041caa61ed34
use get_function_handle instead of extract_function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
298 fcn_param_names); |
4140 | 299 |
26864
041caa61ed34
use get_function_handle instead of extract_function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
300 if (daspk_fcn.is_defined ()) |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
301 { |
26864
041caa61ed34
use get_function_handle instead of extract_function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
302 daspk_jac = octave::get_function_handle (interp, c(1), |
041caa61ed34
use get_function_handle instead of extract_function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
303 jac_param_names); |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
304 |
26864
041caa61ed34
use get_function_handle instead of extract_function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
305 if (daspk_jac.is_undefined ()) |
041caa61ed34
use get_function_handle instead of extract_function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
306 daspk_fcn = octave_value (); |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
307 } |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
308 } |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
309 else |
20957
9db35d2042be
maint: eliminate special cases of statements after error.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
310 error ("daspk: incorrect number of elements in cell array"); |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
311 } |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
312 |
26864
041caa61ed34
use get_function_handle instead of extract_function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
313 if (daspk_fcn.is_undefined () && ! f_arg.iscell ()) |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
314 { |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
315 if (f_arg.is_function_handle () || f_arg.is_inline_function ()) |
26864
041caa61ed34
use get_function_handle instead of extract_function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
316 daspk_fcn = f_arg; |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
317 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
318 { |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
319 switch (f_arg.rows ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
320 { |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
321 case 1: |
26864
041caa61ed34
use get_function_handle instead of extract_function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
322 daspk_fcn = octave::get_function_handle (interp, f_arg, |
041caa61ed34
use get_function_handle instead of extract_function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
323 fcn_param_names); |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
324 break; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
325 |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
326 case 2: |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
327 { |
20990
fc9cca99b2de
Deprecate all_strings, replace with string_vector_value.
Rik <rik@octave.org>
parents:
20974
diff
changeset
|
328 string_vector tmp = f_arg.string_vector_value (); |
3912 | 329 |
26864
041caa61ed34
use get_function_handle instead of extract_function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
330 daspk_fcn = octave::get_function_handle (interp, tmp(0), |
041caa61ed34
use get_function_handle instead of extract_function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
331 fcn_param_names); |
4140 | 332 |
26864
041caa61ed34
use get_function_handle instead of extract_function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
333 if (daspk_fcn.is_defined ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
334 { |
26864
041caa61ed34
use get_function_handle instead of extract_function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
335 daspk_jac = octave::get_function_handle (interp, tmp(1), |
041caa61ed34
use get_function_handle instead of extract_function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
336 jac_param_names); |
5729 | 337 |
26864
041caa61ed34
use get_function_handle instead of extract_function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
338 if (daspk_jac.is_undefined ()) |
041caa61ed34
use get_function_handle instead of extract_function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
339 daspk_fcn = octave_value (); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
340 } |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
341 } |
26864
041caa61ed34
use get_function_handle instead of extract_function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
342 break; |
041caa61ed34
use get_function_handle instead of extract_function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
343 |
041caa61ed34
use get_function_handle instead of extract_function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
344 default: |
041caa61ed34
use get_function_handle instead of extract_function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
345 error ("daspk: 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
|
346 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
347 } |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
348 } |
4140 | 349 |
26864
041caa61ed34
use get_function_handle instead of extract_function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
350 if (daspk_fcn.is_undefined ()) |
041caa61ed34
use get_function_handle instead of extract_function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
351 error ("daspk: FCN argument is not a valid function name or handle"); |
3912 | 352 |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
353 ColumnVector state = args(1).xvector_value ("daspk: initial state X_0 must be a vector"); |
3912 | 354 |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
355 ColumnVector deriv = args(2).xvector_value ("daspk: initial derivatives XDOT_0 must be a vector"); |
3912 | 356 |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
357 ColumnVector out_times = args(3).xvector_value ("daspk: output time variable T must be a vector"); |
3912 | 358 |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
359 ColumnVector crit_times; |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
360 int crit_times_set = 0; |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
361 if (nargin > 4) |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
362 { |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
363 crit_times = args(4).xvector_value ("daspk: list of critical times T_CRIT must be a vector"); |
3912 | 364 |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
365 crit_times_set = 1; |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
366 } |
3912 | 367 |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
368 if (state.numel () != deriv.numel ()) |
20957
9db35d2042be
maint: eliminate special cases of statements after error.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
369 error ("daspk: X_0 and XDOT_0 must have the same size"); |
4140 | 370 |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
371 double tzero = out_times (0); |
3912 | 372 |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
373 DAEFunc func (daspk_user_function); |
26864
041caa61ed34
use get_function_handle instead of extract_function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
374 if (daspk_jac.is_defined ()) |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
375 func.set_jacobian_function (daspk_user_jacobian); |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
376 |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
377 DASPK dae (state, deriv, tzero, func); |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
378 dae.set_options (daspk_opts); |
3912 | 379 |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
380 Matrix output; |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
381 Matrix deriv_output; |
3912 | 382 |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
383 if (crit_times_set) |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
384 output = dae.integrate (out_times, deriv_output, crit_times); |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
385 else |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
386 output = dae.integrate (out_times, deriv_output); |
3997 | 387 |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
388 std::string msg = dae.error_message (); |
3912 | 389 |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
390 if (dae.integration_ok ()) |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
391 { |
20892 | 392 retval(0) = output; |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
393 retval(1) = deriv_output; |
3912 | 394 } |
395 else | |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
396 { |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
397 if (nargout < 3) |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
398 error ("daspk: %s", msg.c_str ()); |
20892 | 399 |
400 retval(0) = Matrix (); | |
401 retval(1) = Matrix (); | |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
402 } |
3912 | 403 |
20892 | 404 retval(2) = static_cast<double> (dae.integration_state ()); |
405 retval(3) = msg; | |
406 | |
3912 | 407 return retval; |
408 } |