annotate src/DLD-FUNCTIONS/dasrt.cc @ 10846:a4f482e66b65

Grammarcheck more of the documentation. Use @noindent macro appropriately. Limit line length to 80 characters.
author Rik <octave@nomad.inbox5.com>
date Sun, 01 Aug 2010 20:22:17 -0700
parents 89f4d7e294cc
children fd0a3ac60b0e
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
8920
eb63fbe60fab update copyright notices
John W. Eaton <jwe@octave.org>
parents: 8787
diff changeset
3 Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2009 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
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
23 #ifdef HAVE_CONFIG_H
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
24 #include <config.h>
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
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
33 #include "defun-dld.h"
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
34 #include "error.h"
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
35 #include "gripes.h"
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
36 #include "oct-obj.h"
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
4628
c0121a3b9cbe [project @ 2003-11-17 20:19:07 by jwe]
jwe
parents: 4140
diff changeset
66 assert (x.capacity () == xdot.capacity ());
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 {
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
76 octave_value_list tmp = dasrt_f->do_multi_index_op (1, args);
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
77
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
78 if (error_state)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
79 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
80 gripe_user_supplied_eval ("dasrt");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
81 return retval;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
82 }
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
83
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
84 if (tmp.length () > 0 && tmp(0).is_defined ())
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
85 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
86 if (! warned_fcn_imaginary && tmp(0).is_complex_type ())
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
87 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
88 warning ("dasrt: ignoring imaginary part returned from user-supplied function");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
89 warned_fcn_imaginary = true;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
90 }
4140
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
91
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
92 retval = ColumnVector (tmp(0).vector_value ());
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
93
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
94 if (error_state || retval.length () == 0)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
95 gripe_user_supplied_eval ("dasrt");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
96 }
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
97 else
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
98 gripe_user_supplied_eval ("dasrt");
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
99 }
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 return retval;
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
102 }
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 static ColumnVector
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
105 dasrt_user_cf (const ColumnVector& x, double t)
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
106 {
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
107 ColumnVector retval;
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
108
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
109 octave_value_list args;
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
110
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
111 args(1) = t;
4628
c0121a3b9cbe [project @ 2003-11-17 20:19:07 by jwe]
jwe
parents: 4140
diff changeset
112 args(0) = x;
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
113
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
114 if (dasrt_cf)
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
115 {
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
116 octave_value_list tmp = dasrt_cf->do_multi_index_op (1, args);
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
117
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
118 if (error_state)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
119 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
120 gripe_user_supplied_eval ("dasrt");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
121 return retval;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
122 }
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
123
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
124 if (tmp.length () > 0 && tmp(0).is_defined ())
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
125 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
126 if (! warned_cf_imaginary && tmp(0).is_complex_type ())
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
127 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
128 warning ("dasrt: ignoring imaginary part returned from user-supplied constraint function");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
129 warned_cf_imaginary = true;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
130 }
4140
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
131
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
132 retval = ColumnVector (tmp(0).vector_value ());
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
133
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
134 if (error_state || retval.length () == 0)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
135 gripe_user_supplied_eval ("dasrt");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
136 }
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
137 else
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
138 gripe_user_supplied_eval ("dasrt");
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
139 }
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
140
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
141 return retval;
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
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
144 static Matrix
3993
f23bc69132cc [project @ 2002-07-16 20:18:56 by jwe]
jwe
parents: 3992
diff changeset
145 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
146 double t, double cj)
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
147 {
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
148 Matrix retval;
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
149
4628
c0121a3b9cbe [project @ 2003-11-17 20:19:07 by jwe]
jwe
parents: 4140
diff changeset
150 assert (x.capacity () == xdot.capacity ());
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
151
3993
f23bc69132cc [project @ 2002-07-16 20:18:56 by jwe]
jwe
parents: 3992
diff changeset
152 octave_value_list args;
f23bc69132cc [project @ 2002-07-16 20:18:56 by jwe]
jwe
parents: 3992
diff changeset
153
f23bc69132cc [project @ 2002-07-16 20:18:56 by jwe]
jwe
parents: 3992
diff changeset
154 args(3) = cj;
f23bc69132cc [project @ 2002-07-16 20:18:56 by jwe]
jwe
parents: 3992
diff changeset
155 args(2) = t;
4628
c0121a3b9cbe [project @ 2003-11-17 20:19:07 by jwe]
jwe
parents: 4140
diff changeset
156 args(1) = xdot;
c0121a3b9cbe [project @ 2003-11-17 20:19:07 by jwe]
jwe
parents: 4140
diff changeset
157 args(0) = x;
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
158
3993
f23bc69132cc [project @ 2002-07-16 20:18:56 by jwe]
jwe
parents: 3992
diff changeset
159 if (dasrt_j)
f23bc69132cc [project @ 2002-07-16 20:18:56 by jwe]
jwe
parents: 3992
diff changeset
160 {
f23bc69132cc [project @ 2002-07-16 20:18:56 by jwe]
jwe
parents: 3992
diff changeset
161 octave_value_list tmp = dasrt_j->do_multi_index_op (1, args);
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
162
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
163 if (error_state)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
164 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
165 gripe_user_supplied_eval ("dasrt");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
166 return retval;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
167 }
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
168
3993
f23bc69132cc [project @ 2002-07-16 20:18:56 by jwe]
jwe
parents: 3992
diff changeset
169 int tlen = tmp.length ();
f23bc69132cc [project @ 2002-07-16 20:18:56 by jwe]
jwe
parents: 3992
diff changeset
170 if (tlen > 0 && tmp(0).is_defined ())
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
171 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
172 if (! warned_jac_imaginary && tmp(0).is_complex_type ())
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
173 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
174 warning ("dasrt: ignoring imaginary part returned from user-supplied jacobian function");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
175 warned_jac_imaginary = true;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
176 }
4140
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
177
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
178 retval = tmp(0).matrix_value ();
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
179
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
180 if (error_state || retval.length () == 0)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
181 gripe_user_supplied_eval ("dasrt");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
182 }
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
183 else
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
184 gripe_user_supplied_eval ("dasrt");
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
185 }
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
186
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
187 return retval;
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 #define DASRT_ABORT \
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
191 return retval
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
192
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
193 #define DASRT_ABORT1(msg) \
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
194 do \
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
195 { \
4035
92776b806c55 [project @ 2002-08-10 08:04:07 by jwe]
jwe
parents: 3998
diff changeset
196 ::error ("dasrt: " msg); \
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
197 DASRT_ABORT; \
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
198 } \
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
199 while (0)
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
200
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
201 #define DASRT_ABORT2(fmt, arg) \
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
202 do \
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
203 { \
4035
92776b806c55 [project @ 2002-08-10 08:04:07 by jwe]
jwe
parents: 3998
diff changeset
204 ::error ("dasrt: " fmt, arg); \
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
205 DASRT_ABORT; \
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
206 } \
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
207 while (0)
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
208
3997
d4091aff6468 [project @ 2002-07-17 18:00:06 by jwe]
jwe
parents: 3994
diff changeset
209 DEFUN_DLD (dasrt, args, nargout,
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
210 "-*- texinfo -*-\n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
211 @deftypefn {Loadable Function} {[@var{x}, @var{xdot}, @var{t_out}, @var{istat}, @var{msg}] =} dasrt (@var{fcn} [, @var{g}], @var{x_0}, @var{xdot_0}, @var{t} [, @var{t_crit}])\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
212 Solve the set of differential-algebraic equations\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
213 @tex\n\
4852
404c7122853e [project @ 2004-04-06 17:23:37 by jwe]
jwe
parents: 4661
diff changeset
214 $$ 0 = f (x, \\dot{x}, t) $$\n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
215 with\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
216 $$ x(t_0) = x_0, \\dot{x}(t_0) = \\dot{x}_0 $$\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
217 @end tex\n\
8517
81d6ab3ac93c Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents: 7017
diff changeset
218 @ifnottex\n\
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
219 \n\
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
220 @example\n\
4852
404c7122853e [project @ 2004-04-06 17:23:37 by jwe]
jwe
parents: 4661
diff changeset
221 0 = f (x, xdot, t)\n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
222 @end example\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
223 \n\
10846
a4f482e66b65 Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents: 10840
diff changeset
224 @noindent\n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
225 with\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
226 \n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
227 @example\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
228 x(t_0) = x_0, xdot(t_0) = xdot_0\n\
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
229 @end example\n\
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
230 \n\
8517
81d6ab3ac93c Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents: 7017
diff changeset
231 @end ifnottex\n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
232 with functional stopping criteria (root solving).\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
233 \n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
234 The solution is returned in the matrices @var{x} and @var{xdot},\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
235 with each row in the result matrices corresponding to one of the\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
236 elements in the vector @var{t_out}. The first element of @var{t}\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
237 should be @math{t_0} and correspond to the initial state of the\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
238 system @var{x_0} and its derivative @var{xdot_0}, so that the first\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
239 row of the output @var{x} is @var{x_0} and the first row\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
240 of the output @var{xdot} is @var{xdot_0}.\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
241 \n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
242 The vector @var{t} provides an upper limit on the length of the\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
243 integration. If the stopping condition is met, the vector\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
244 @var{t_out} will be shorter than @var{t}, and the final element of\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
245 @var{t_out} will be the point at which the stopping condition was met,\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
246 and may not correspond to any element of the vector @var{t}.\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
247 \n\
8787
5b23faa8113c Documentation fixes.
Olaf Till <olaf.till@uni-jena.de>
parents: 8517
diff changeset
248 The first argument, @var{fcn}, is a string, inline, or function handle\n\
5b23faa8113c Documentation fixes.
Olaf Till <olaf.till@uni-jena.de>
parents: 8517
diff changeset
249 that names the function @math{f} to call to compute the vector of\n\
5b23faa8113c Documentation fixes.
Olaf Till <olaf.till@uni-jena.de>
parents: 8517
diff changeset
250 residuals for the set of equations. It must have the form\n\
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
251 \n\
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
252 @example\n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
253 @var{res} = f (@var{x}, @var{xdot}, @var{t})\n\
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
254 @end example\n\
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
255 \n\
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
256 @noindent\n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
257 in which @var{x}, @var{xdot}, and @var{res} are vectors, and @var{t} is a\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
258 scalar.\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
259 \n\
8787
5b23faa8113c Documentation fixes.
Olaf Till <olaf.till@uni-jena.de>
parents: 8517
diff changeset
260 If @var{fcn} is a two-element string array or a two-element cell array\n\
9067
8970b4b10e9f Cleanup documentation for quad.texi and diffeq.texi
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
261 of strings, inline functions, or function handles, the first element names\n\
8787
5b23faa8113c Documentation fixes.
Olaf Till <olaf.till@uni-jena.de>
parents: 8517
diff changeset
262 the function @math{f} described above, and the second element names a\n\
5b23faa8113c Documentation fixes.
Olaf Till <olaf.till@uni-jena.de>
parents: 8517
diff changeset
263 function to compute the modified Jacobian\n\
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
264 \n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
265 @tex\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
266 $$\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
267 J = {\\partial f \\over \\partial x}\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
268 + c {\\partial f \\over \\partial \\dot{x}}\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
269 $$\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
270 @end tex\n\
8517
81d6ab3ac93c Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents: 7017
diff changeset
271 @ifnottex\n\
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
272 \n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
273 @example\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
274 @group\n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
275 df df\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
276 jac = -- + c ------\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
277 dx d xdot\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
278 @end group\n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
279 @end example\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
280 \n\
8517
81d6ab3ac93c Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents: 7017
diff changeset
281 @end ifnottex\n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
282 \n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
283 The modified Jacobian function must have the form\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
284 \n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
285 @example\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
286 @group\n\
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
287 \n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
288 @var{jac} = j (@var{x}, @var{xdot}, @var{t}, @var{c})\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
289 \n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
290 @end group\n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
291 @end example\n\
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
292 \n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
293 The optional second argument names a function that defines the\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
294 constraint functions whose roots are desired during the integration.\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
295 This function must have the form\n\
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
296 \n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
297 @example\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
298 @var{g_out} = g (@var{x}, @var{t})\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
299 @end example\n\
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
300 \n\
10846
a4f482e66b65 Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents: 10840
diff changeset
301 @noindent\n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
302 and return a vector of the constraint function values.\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10791
diff changeset
303 If the value of any of the constraint functions changes sign, @sc{dasrt}\n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
304 will attempt to stop the integration at the point of the sign change.\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
305 \n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
306 If the name of the constraint function is omitted, @code{dasrt} solves\n\
4852
404c7122853e [project @ 2004-04-06 17:23:37 by jwe]
jwe
parents: 4661
diff changeset
307 the same problem as @code{daspk} or @code{dassl}.\n\
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
308 \n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
309 Note that because of numerical errors in the constraint functions\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10791
diff changeset
310 due to round-off and integration error, @sc{dasrt} may return false\n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
311 roots, or return the same root at two or more nearly equal values of\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
312 @var{T}. If such false roots are suspected, the user should consider\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
313 smaller error tolerances or higher precision in the evaluation of the\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
314 constraint functions.\n\
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
315 \n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
316 If a root of some constraint function defines the end of the problem,\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10791
diff changeset
317 the input to @sc{dasrt} should nevertheless allow integration to a\n\
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10791
diff changeset
318 point slightly past that root, so that @sc{dasrt} can locate the root\n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
319 by interpolation.\n\
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
320 \n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
321 The third and fourth arguments to @code{dasrt} specify the initial\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
322 condition of the states and their derivatives, and the fourth argument\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
323 specifies a vector of output times at which the solution is desired,\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
324 including the time corresponding to the initial condition.\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
325 \n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
326 The set of initial states and derivatives are not strictly required to\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10791
diff changeset
327 be consistent. In practice, however, @sc{dassl} is not very good at\n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
328 determining a consistent set for you, so it is best if you ensure that\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
329 the initial values result in the function evaluating to zero.\n\
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
330 \n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
331 The sixth argument is optional, and may be used to specify a set of\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
332 times that the DAE solver should not integrate past. It is useful for\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
333 avoiding difficulties with singularities and points where there is a\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
334 discontinuity in the derivative.\n\
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
335 \n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
336 After a successful computation, the value of @var{istate} will be\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10791
diff changeset
337 greater than zero (consistent with the Fortran version of @sc{dassl}).\n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
338 \n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
339 If the computation is not successful, the value of @var{istate} will be\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 4052
diff changeset
340 less than zero and @var{msg} will contain additional information.\n\
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
341 \n\
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
342 You can use the function @code{dasrt_options} to set optional\n\
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
343 parameters for @code{dasrt}.\n\
5694
95d90f781ca8 [project @ 2006-03-20 18:29:20 by jwe]
jwe
parents: 5642
diff changeset
344 @seealso{daspk, dasrt, lsode}\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5307
diff changeset
345 @end deftypefn")
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
346 {
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
347 octave_value_list retval;
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
348
4140
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
349 warned_fcn_imaginary = false;
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
350 warned_jac_imaginary = false;
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
351 warned_cf_imaginary = false;
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
352
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
353 unwind_protect frame;
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
354
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
355 frame.protect_var (call_depth);
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
356 call_depth++;
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
357
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
358 if (call_depth > 1)
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
359 DASRT_ABORT1 ("invalid recursive call");
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 int argp = 0;
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 int nargin = args.length ();
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
364
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
365 if (nargin < 4 || nargin > 6)
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
366 {
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5729
diff changeset
367 print_usage ();
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
368 return retval;
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
369 }
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
370
5729
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
371 std::string fcn_name, fname, jac_name, jname;
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
372 dasrt_f = 0;
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
373 dasrt_j = 0;
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
374 dasrt_cf = 0;
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
375
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
376 // Check all the arguments. Are they the right animals?
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
377
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
378 // 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
379
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
380 octave_value f_arg = args(0);
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
381
5729
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
382 if (f_arg.is_cell ())
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
383 {
5729
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
384 Cell c = f_arg.cell_value ();
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
385 if (c.length() == 1)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
386 f_arg = c(0);
5729
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
387 else if (c.length() == 2)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
388 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
389 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
390 dasrt_f = c(0).function_value ();
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
391 else
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
392 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
393 fcn_name = unique_symbol_name ("__dasrt_fcn__");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
394 fname = "function y = ";
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
395 fname.append (fcn_name);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
396 fname.append (" (x, xdot, t) y = ");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
397 dasrt_f = extract_function
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
398 (c(0), "dasrt", fcn_name, fname, "; endfunction");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
399 }
5729
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
400
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
401 if (dasrt_f)
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 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
404 dasrt_j = c(1).function_value ();
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
405 else
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
406 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
407 jac_name = unique_symbol_name ("__dasrt_jac__");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
408 jname = "function jac = ";
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
409 jname.append(jac_name);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
410 jname.append (" (x, xdot, t, cj) jac = ");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
411 dasrt_j = extract_function
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
412 (c(1), "dasrt", jac_name, jname, "; endfunction");
5729
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
413
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
414 if (!dasrt_j)
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 if (fcn_name.length())
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
417 clear_function (fcn_name);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
418 dasrt_f = 0;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
419 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
420 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
421 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
422 }
5729
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
423 else
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
424 DASRT_ABORT1 ("incorrect number of elements in cell array");
5729
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
425 }
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
426
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
427 if (!dasrt_f && ! f_arg.is_cell())
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
428 {
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
429 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
430 dasrt_f = f_arg.function_value ();
5729
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
431 else
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
432 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
433 switch (f_arg.rows ())
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
434 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
435 case 1:
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
436 fcn_name = unique_symbol_name ("__dasrt_fcn__");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
437 fname = "function y = ";
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
438 fname.append (fcn_name);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
439 fname.append (" (x, xdot, t) y = ");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
440 dasrt_f = extract_function
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
441 (f_arg, "dasrt", fcn_name, fname, "; endfunction");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
442 break;
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
443
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
444 case 2:
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
445 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
446 string_vector tmp = args(0).all_strings ();
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
447
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
448 if (! error_state)
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 fcn_name = unique_symbol_name ("__dasrt_fcn__");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
451 fname = "function y = ";
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
452 fname.append (fcn_name);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
453 fname.append (" (x, xdot, t) y = ");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
454 dasrt_f = extract_function
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
455 (tmp(0), "dasrt", fcn_name, fname, "; endfunction");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
456
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
457 if (dasrt_f)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
458 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
459 jac_name = unique_symbol_name ("__dasrt_jac__");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
460 jname = "function jac = ";
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
461 jname.append(jac_name);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
462 jname.append (" (x, xdot, t, cj) jac = ");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
463 dasrt_j = extract_function
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
464 (tmp(1), "dasrt", jac_name, jname, "; endfunction");
5729
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
465
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
466 if (! dasrt_j)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
467 dasrt_f = 0;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
468 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
469 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
470 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
471 break;
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
472
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
473 default:
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
474 DASRT_ABORT1
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
475 ("first arg should be a string or 2-element string array");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
476 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
477 }
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
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
480 if (error_state || (! dasrt_f))
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
481 DASRT_ABORT;
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 DAERTFunc func (dasrt_user_f);
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 argp++;
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
486
5729
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
487 if (args(1).is_function_handle() || args(1).is_inline_function())
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
488 {
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
489 dasrt_cf = args(1).function_value();
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
490
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
491 if (! dasrt_cf)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
492 DASRT_ABORT1 ("expecting function name as argument 2");
5729
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
493
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
494 argp++;
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
495
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
496 func.set_constraint_function (dasrt_user_cf);
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
497 }
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
498 else if (args(1).is_string ())
3990
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 dasrt_cf = is_valid_function (args(1), "dasrt", true);
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
501 if (! dasrt_cf)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
502 DASRT_ABORT1 ("expecting function name as argument 2");
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
503
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
504 argp++;
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
505
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
506 func.set_constraint_function (dasrt_user_cf);
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
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
509 ColumnVector state (args(argp++).vector_value ());
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 if (error_state)
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
512 DASRT_ABORT2 ("expecting state vector as argument %d", argp);
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
513
3992
53b4eab68976 [project @ 2002-07-16 19:36:52 by jwe]
jwe
parents: 3990
diff changeset
514 ColumnVector stateprime (args(argp++).vector_value ());
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
515
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
516 if (error_state)
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
517 DASRT_ABORT2
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
518 ("expecting time derivative of state vector as argument %d", argp);
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
519
3994
a41827ec5677 [project @ 2002-07-16 23:57:09 by jwe]
jwe
parents: 3993
diff changeset
520 ColumnVector out_times (args(argp++).vector_value ());
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
521
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
522 if (error_state)
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
523 DASRT_ABORT2
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
524 ("expecting output time vector as %s argument %d", argp);
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
525
3994
a41827ec5677 [project @ 2002-07-16 23:57:09 by jwe]
jwe
parents: 3993
diff changeset
526 double tzero = out_times (0);
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
527
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
528 ColumnVector crit_times;
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
529
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
530 bool crit_times_set = false;
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
531
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
532 if (argp < nargin)
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
533 {
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
534 crit_times = ColumnVector (args(argp++).vector_value ());
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
535
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
536 if (error_state)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
537 DASRT_ABORT2
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
538 ("expecting critical time vector as argument %d", argp);
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
539
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
540 crit_times_set = true;
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
541 }
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
542
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
543 if (dasrt_j)
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
544 func.set_jacobian_function (dasrt_user_j);
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
545
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
546 DASRT_result output;
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
547
3992
53b4eab68976 [project @ 2002-07-16 19:36:52 by jwe]
jwe
parents: 3990
diff changeset
548 DASRT dae = DASRT (state, stateprime, tzero, func);
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
549
4122
19a1626b8d57 [project @ 2002-10-23 22:10:53 by jwe]
jwe
parents: 4117
diff changeset
550 dae.set_options (dasrt_opts);
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
551
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
552 if (crit_times_set)
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
553 output = dae.integrate (out_times, crit_times);
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
554 else
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
555 output = dae.integrate (out_times);
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
556
5729
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
557 if (fcn_name.length())
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
558 clear_function (fcn_name);
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
559 if (jac_name.length())
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
560 clear_function (jac_name);
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
561
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
562 if (! error_state)
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
563 {
3997
d4091aff6468 [project @ 2002-07-17 18:00:06 by jwe]
jwe
parents: 3994
diff changeset
564 std::string msg = dae.error_message ();
d4091aff6468 [project @ 2002-07-17 18:00:06 by jwe]
jwe
parents: 3994
diff changeset
565
d4091aff6468 [project @ 2002-07-17 18:00:06 by jwe]
jwe
parents: 3994
diff changeset
566 retval(4) = msg;
d4091aff6468 [project @ 2002-07-17 18:00:06 by jwe]
jwe
parents: 3994
diff changeset
567 retval(3) = static_cast<double> (dae.integration_state ());
d4091aff6468 [project @ 2002-07-17 18:00:06 by jwe]
jwe
parents: 3994
diff changeset
568
d4091aff6468 [project @ 2002-07-17 18:00:06 by jwe]
jwe
parents: 3994
diff changeset
569 if (dae.integration_ok ())
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
570 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
571 retval(2) = output.times ();
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
572 retval(1) = output.deriv ();
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
573 retval(0) = output.state ();
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
574 }
3997
d4091aff6468 [project @ 2002-07-17 18:00:06 by jwe]
jwe
parents: 3994
diff changeset
575 else
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
576 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
577 retval(2) = Matrix ();
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
578 retval(1) = Matrix ();
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
579 retval(0) = Matrix ();
3997
d4091aff6468 [project @ 2002-07-17 18:00:06 by jwe]
jwe
parents: 3994
diff changeset
580
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
581 if (nargout < 4)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
582 error ("dasrt: %s", msg.c_str ());
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
583 }
3990
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
584 }
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
585
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
586 return retval;
46388d6a4e44 [project @ 2002-07-16 06:20:39 by jwe]
jwe
parents:
diff changeset
587 }