annotate src/DLD-FUNCTIONS/dassl.cc @ 14138:72c96de7a403 stable

maint: update copyright notices for 2012
author John W. Eaton <jwe@octave.org>
date Mon, 02 Jan 2012 14:25:41 -0500
parents 4e8f23ccadce
children 60e5cf354d80
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
1 /*
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
2
14138
72c96de7a403 maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents: 14085
diff changeset
3 Copyright (C) 1996-2012 John W. Eaton
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
4
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
6
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
295f037b4b3e [project @ 1997-05-05 05:32:33 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.
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
11
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
15 for more details.
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
16
295f037b4b3e [project @ 1997-05-05 05:32:33 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/>.
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
20
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
21 */
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
22
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
23 #ifdef HAVE_CONFIG_H
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
24 #include <config.h>
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
25 #endif
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
26
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
27 #include <string>
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
28
3567
dd8998699aa8 [project @ 2000-02-03 09:54:28 by jwe]
jwe
parents: 3544
diff changeset
29 #include <iomanip>
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3419
diff changeset
30 #include <iostream>
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
31
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
32 #include "DASSL.h"
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
33
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
34 #include "defun-dld.h"
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
35 #include "error.h"
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
36 #include "gripes.h"
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
37 #include "oct-obj.h"
2968
e330cb788508 [project @ 1997-05-15 17:40:29 by jwe]
jwe
parents: 2928
diff changeset
38 #include "ov-fcn.h"
5729
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
39 #include "ov-cell.h"
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
40 #include "pager.h"
3243
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
41 #include "unwind-prot.h"
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
42 #include "utils.h"
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
43 #include "variables.h"
295f037b4b3e [project @ 1997-05-05 05:32:33 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 "DASSL-opts.cc"
f6df65db67f9 [project @ 2002-07-24 18:10:39 by jwe]
jwe
parents: 3997
diff changeset
46
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
47 // Global pointer for user defined function required by dassl.
2968
e330cb788508 [project @ 1997-05-15 17:40:29 by jwe]
jwe
parents: 2928
diff changeset
48 static octave_function *dassl_fcn;
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
49
3991
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
50 // Global pointer for optional user defined jacobian function.
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
51 static octave_function *dassl_jac;
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
52
4140
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
53 // 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
54 static bool warned_fcn_imaginary = false;
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
55 static bool warned_jac_imaginary = false;
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
56
3243
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
57 // Is this a recursive call?
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
58 static int call_depth = 0;
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
59
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
60 ColumnVector
3849
5266e351a19c [project @ 2001-11-02 04:50:09 by jwe]
jwe
parents: 3747
diff changeset
61 dassl_user_function (const ColumnVector& x, const ColumnVector& xdot,
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
62 double t, octave_idx_type& ires)
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
63 {
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
64 ColumnVector retval;
295f037b4b3e [project @ 1997-05-05 05:32:33 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 ());
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
67
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
68 octave_value_list args;
4628
c0121a3b9cbe [project @ 2003-11-17 20:19:07 by jwe]
jwe
parents: 4140
diff changeset
69
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
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;
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
73
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
74 if (dassl_fcn)
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
75 {
3544
71bd2d124119 [project @ 2000-02-02 21:02:31 by jwe]
jwe
parents: 3523
diff changeset
76 octave_value_list tmp = dassl_fcn->do_multi_index_op (1, args);
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
77
295f037b4b3e [project @ 1997-05-05 05:32:33 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 ("dassl");
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 }
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
83
3849
5266e351a19c [project @ 2001-11-02 04:50:09 by jwe]
jwe
parents: 3747
diff changeset
84 int tlen = tmp.length ();
5266e351a19c [project @ 2001-11-02 04:50:09 by jwe]
jwe
parents: 3747
diff changeset
85 if (tlen > 0 && tmp(0).is_defined ())
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
86 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
87 if (! warned_fcn_imaginary && tmp(0).is_complex_type ())
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
88 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
89 warning ("dassl: ignoring imaginary part returned from user-supplied function");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
90 warned_fcn_imaginary = true;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
91 }
4140
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
92
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
93 retval = ColumnVector (tmp(0).vector_value ());
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
94
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
95 if (tlen > 1)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
96 ires = tmp(1).int_value ();
3849
5266e351a19c [project @ 2001-11-02 04:50:09 by jwe]
jwe
parents: 3747
diff changeset
97
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
98 if (error_state || retval.length () == 0)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
99 gripe_user_supplied_eval ("dassl");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
100 }
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
101 else
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
102 gripe_user_supplied_eval ("dassl");
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
103 }
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
104
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
105 return retval;
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
106 }
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
107
3991
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
108 Matrix
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
109 dassl_user_jacobian (const ColumnVector& x, const ColumnVector& xdot,
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
110 double t, double cj)
3991
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
111 {
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
112 Matrix retval;
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
113
4628
c0121a3b9cbe [project @ 2003-11-17 20:19:07 by jwe]
jwe
parents: 4140
diff changeset
114 assert (x.capacity () == xdot.capacity ());
3991
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
115
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
116 octave_value_list args;
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
117
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
118 args(3) = cj;
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
119 args(2) = t;
4628
c0121a3b9cbe [project @ 2003-11-17 20:19:07 by jwe]
jwe
parents: 4140
diff changeset
120 args(1) = xdot;
c0121a3b9cbe [project @ 2003-11-17 20:19:07 by jwe]
jwe
parents: 4140
diff changeset
121 args(0) = x;
3991
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
122
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
123 if (dassl_jac)
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
124 {
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
125 octave_value_list tmp = dassl_jac->do_multi_index_op (1, args);
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
126
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
127 if (error_state)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
128 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
129 gripe_user_supplied_eval ("dassl");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
130 return retval;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
131 }
3991
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
132
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
133 int tlen = tmp.length ();
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
134 if (tlen > 0 && tmp(0).is_defined ())
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
135 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
136 if (! warned_jac_imaginary && tmp(0).is_complex_type ())
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
137 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
138 warning ("dassl: ignoring imaginary part returned from user-supplied jacobian function");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
139 warned_jac_imaginary = true;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
140 }
4140
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
141
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
142 retval = tmp(0).matrix_value ();
3991
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
143
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
144 if (error_state || retval.length () == 0)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
145 gripe_user_supplied_eval ("dassl");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
146 }
3991
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
147 else
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
148 gripe_user_supplied_eval ("dassl");
3991
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
149 }
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
150
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
151 return retval;
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
152 }
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
153
3323
511caaa5e98e [project @ 1999-10-27 02:21:46 by jwe]
jwe
parents: 3321
diff changeset
154 #define DASSL_ABORT() \
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9758
diff changeset
155 return retval
3323
511caaa5e98e [project @ 1999-10-27 02:21:46 by jwe]
jwe
parents: 3321
diff changeset
156
511caaa5e98e [project @ 1999-10-27 02:21:46 by jwe]
jwe
parents: 3321
diff changeset
157 #define DASSL_ABORT1(msg) \
511caaa5e98e [project @ 1999-10-27 02:21:46 by jwe]
jwe
parents: 3321
diff changeset
158 do \
511caaa5e98e [project @ 1999-10-27 02:21:46 by jwe]
jwe
parents: 3321
diff changeset
159 { \
3747
50f30e40abca [project @ 2000-12-07 05:47:06 by jwe]
jwe
parents: 3568
diff changeset
160 ::error ("dassl: " msg); \
3323
511caaa5e98e [project @ 1999-10-27 02:21:46 by jwe]
jwe
parents: 3321
diff changeset
161 DASSL_ABORT (); \
511caaa5e98e [project @ 1999-10-27 02:21:46 by jwe]
jwe
parents: 3321
diff changeset
162 } \
511caaa5e98e [project @ 1999-10-27 02:21:46 by jwe]
jwe
parents: 3321
diff changeset
163 while (0)
511caaa5e98e [project @ 1999-10-27 02:21:46 by jwe]
jwe
parents: 3321
diff changeset
164
511caaa5e98e [project @ 1999-10-27 02:21:46 by jwe]
jwe
parents: 3321
diff changeset
165 #define DASSL_ABORT2(fmt, arg) \
511caaa5e98e [project @ 1999-10-27 02:21:46 by jwe]
jwe
parents: 3321
diff changeset
166 do \
511caaa5e98e [project @ 1999-10-27 02:21:46 by jwe]
jwe
parents: 3321
diff changeset
167 { \
3747
50f30e40abca [project @ 2000-12-07 05:47:06 by jwe]
jwe
parents: 3568
diff changeset
168 ::error ("dassl: " fmt, arg); \
3323
511caaa5e98e [project @ 1999-10-27 02:21:46 by jwe]
jwe
parents: 3321
diff changeset
169 DASSL_ABORT (); \
511caaa5e98e [project @ 1999-10-27 02:21:46 by jwe]
jwe
parents: 3321
diff changeset
170 } \
511caaa5e98e [project @ 1999-10-27 02:21:46 by jwe]
jwe
parents: 3321
diff changeset
171 while (0)
511caaa5e98e [project @ 1999-10-27 02:21:46 by jwe]
jwe
parents: 3321
diff changeset
172
3991
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
173 DEFUN_DLD (dassl, args, nargout,
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3325
diff changeset
174 "-*- texinfo -*-\n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
175 @deftypefn {Loadable Function} {[@var{x}, @var{xdot}, @var{istate}, @var{msg}] =} dassl (@var{fcn}, @var{x_0}, @var{xdot_0}, @var{t}, @var{t_crit})\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
176 Solve the set of differential-algebraic equations\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
177 @tex\n\
4852
404c7122853e [project @ 2004-04-06 17:23:37 by jwe]
jwe
parents: 4698
diff changeset
178 $$ 0 = f (x, \\dot{x}, t) $$\n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
179 with\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
180 $$ 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: 3998
diff changeset
181 @end tex\n\
8517
81d6ab3ac93c Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents: 7562
diff changeset
182 @ifnottex\n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
183 \n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
184 @example\n\
4698
737fd5c0ae06 [project @ 2004-01-19 19:25:26 by jwe]
jwe
parents: 4628
diff changeset
185 0 = f (x, xdot, t)\n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
186 @end example\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
187 \n\
4912
048db020498c [project @ 2004-07-22 20:45:59 by jwe]
jwe
parents: 4888
diff changeset
188 @noindent\n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
189 with\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
190 \n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
191 @example\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
192 x(t_0) = x_0, xdot(t_0) = xdot_0\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
193 @end example\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
194 \n\
8517
81d6ab3ac93c Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents: 7562
diff changeset
195 @end ifnottex\n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
196 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: 3998
diff changeset
197 with each row in the result matrices corresponding to one of the\n\
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3325
diff changeset
198 elements in the vector @var{t}. The first element of @var{t}\n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
199 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: 3998
diff changeset
200 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: 3998
diff changeset
201 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: 3998
diff changeset
202 of the output @var{xdot} is @var{xdot_0}.\n\
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3325
diff changeset
203 \n\
8787
5b23faa8113c Documentation fixes.
Olaf Till <olaf.till@uni-jena.de>
parents: 8517
diff changeset
204 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
205 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
206 residuals for the set of equations. It must have the form\n\
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3325
diff changeset
207 \n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3325
diff changeset
208 @example\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3325
diff changeset
209 @var{res} = f (@var{x}, @var{xdot}, @var{t})\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3325
diff changeset
210 @end example\n\
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
211 \n\
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3325
diff changeset
212 @noindent\n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
213 in which @var{x}, @var{xdot}, and @var{res} are vectors, and @var{t} is a\n\
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3325
diff changeset
214 scalar.\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3325
diff changeset
215 \n\
8787
5b23faa8113c Documentation fixes.
Olaf Till <olaf.till@uni-jena.de>
parents: 8517
diff changeset
216 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
217 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
218 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
219 function to compute the modified Jacobian\n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
220 \n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
221 @tex\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
222 $$\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
223 J = {\\partial f \\over \\partial x}\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
224 + c {\\partial f \\over \\partial \\dot{x}}\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
225 $$\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
226 @end tex\n\
8517
81d6ab3ac93c Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents: 7562
diff changeset
227 @ifnottex\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10155
diff changeset
228 \n\
4888
4a796c5fc7a3 [project @ 2004-04-30 18:27:07 by jwe]
jwe
parents: 4852
diff changeset
229 @example\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
230 @group\n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
231 df df\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
232 jac = -- + c ------\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
233 dx d xdot\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
234 @end group\n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
235 @end example\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10155
diff changeset
236 \n\
8517
81d6ab3ac93c Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents: 7562
diff changeset
237 @end ifnottex\n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
238 \n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
239 The modified Jacobian function must have the form\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
240 \n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
241 @example\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
242 @group\n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
243 \n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
244 @var{jac} = j (@var{x}, @var{xdot}, @var{t}, @var{c})\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
245 \n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
246 @end group\n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
247 @end example\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
248 \n\
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3325
diff changeset
249 The second and third arguments to @code{dassl} specify the initial\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3325
diff changeset
250 condition of the states and their derivatives, and the fourth argument\n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
251 specifies a vector of output times at which the solution is desired,\n\
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3325
diff changeset
252 including the time corresponding to the initial condition.\n\
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
253 \n\
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3325
diff changeset
254 The set of initial states and derivatives are not strictly required to\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10155
diff changeset
255 be consistent. In practice, however, @sc{dassl} is not very good at\n\
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3325
diff changeset
256 determining a consistent set for you, so it is best if you ensure that\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3325
diff changeset
257 the initial values result in the function evaluating to zero.\n\
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
258 \n\
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3325
diff changeset
259 The fifth argument is optional, and may be used to specify a set of\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3325
diff changeset
260 times that the DAE solver should not integrate past. It is useful for\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3325
diff changeset
261 avoiding difficulties with singularities and points where there is a\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3325
diff changeset
262 discontinuity in the derivative.\n\
3964
3030cb6cb559 [project @ 2002-06-28 17:17:55 by jwe]
jwe
parents: 3849
diff changeset
263 \n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
264 After a successful computation, the value of @var{istate} will be\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10155
diff changeset
265 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: 3998
diff changeset
266 \n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
267 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: 3998
diff changeset
268 less than zero and @var{msg} will contain additional information.\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
269 \n\
3964
3030cb6cb559 [project @ 2002-06-28 17:17:55 by jwe]
jwe
parents: 3849
diff changeset
270 You can use the function @code{dassl_options} to set optional\n\
3030cb6cb559 [project @ 2002-06-28 17:17:55 by jwe]
jwe
parents: 3849
diff changeset
271 parameters for @code{dassl}.\n\
5694
95d90f781ca8 [project @ 2006-03-20 18:29:20 by jwe]
jwe
parents: 5642
diff changeset
272 @seealso{daspk, dasrt, lsode}\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5307
diff changeset
273 @end deftypefn")
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
274 {
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
275 octave_value_list retval;
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
276
4140
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
277 warned_fcn_imaginary = false;
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
278 warned_jac_imaginary = false;
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
279
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9758
diff changeset
280 unwind_protect frame;
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
281
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9758
diff changeset
282 frame.protect_var (call_depth);
3243
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
283 call_depth++;
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
284
3243
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
285 if (call_depth > 1)
3323
511caaa5e98e [project @ 1999-10-27 02:21:46 by jwe]
jwe
parents: 3321
diff changeset
286 DASSL_ABORT1 ("invalid recursive call");
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
287
3243
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
288 int nargin = args.length ();
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
289
3991
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
290 if (nargin > 3 && nargin < 6 && nargout < 5)
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
291 {
5729
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
292 std::string fcn_name, fname, jac_name, jname;
3991
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
293 dassl_fcn = 0;
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
294 dassl_jac = 0;
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
295
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
296 octave_value f_arg = args(0);
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
297
5729
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
298 if (f_arg.is_cell ())
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
299 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
300 Cell c = f_arg.cell_value ();
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
301 if (c.length() == 1)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
302 f_arg = c(0);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
303 else if (c.length() == 2)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
304 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
305 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
306 dassl_fcn = c(0).function_value ();
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
307 else
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
308 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
309 fcn_name = unique_symbol_name ("__dassl_fcn__");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
310 fname = "function y = ";
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
311 fname.append (fcn_name);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
312 fname.append (" (x, xdot, t) y = ");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
313 dassl_fcn = extract_function
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
314 (c(0), "dassl", fcn_name, fname, "; endfunction");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
315 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
316
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
317 if (dassl_fcn)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
318 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
319 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
320 dassl_jac = c(1).function_value ();
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
321 else
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
322 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
323 jac_name = unique_symbol_name ("__dassl_jac__");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
324 jname = "function jac = ";
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
325 jname.append(jac_name);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
326 jname.append (" (x, xdot, t, cj) jac = ");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
327 dassl_jac = extract_function
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
328 (c(1), "dassl", jac_name, jname, "; endfunction");
3991
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
329
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
330 if (!dassl_jac)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
331 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
332 if (fcn_name.length())
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
333 clear_function (fcn_name);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
334 dassl_fcn = 0;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
335 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
336 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
337 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
338 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
339 else
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
340 DASSL_ABORT1 ("incorrect number of elements in cell array");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
341 }
3243
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
342
5729
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
343 if (!dassl_fcn && ! f_arg.is_cell())
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
344 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
345 if (f_arg.is_function_handle () || f_arg.is_inline_function ())
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
346 dassl_fcn = f_arg.function_value ();
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
347 else
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
348 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
349 switch (f_arg.rows ())
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
350 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
351 case 1:
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
352 do
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
353 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
354 fcn_name = unique_symbol_name ("__dassl_fcn__");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
355 fname = "function y = ";
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
356 fname.append (fcn_name);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
357 fname.append (" (x, xdot, t) y = ");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
358 dassl_fcn = extract_function
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
359 (f_arg, "dassl", fcn_name, fname, "; endfunction");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
360 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
361 while (0);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
362 break;
3991
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
363
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
364 case 2:
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
365 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
366 string_vector tmp = f_arg.all_strings ();
5729
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
367
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
368 if (! error_state)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
369 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
370 fcn_name = unique_symbol_name ("__dassl_fcn__");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
371 fname = "function y = ";
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
372 fname.append (fcn_name);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
373 fname.append (" (x, xdot, t) y = ");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
374 dassl_fcn = extract_function
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
375 (tmp(0), "dassl", fcn_name, fname, "; endfunction");
3991
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
376
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
377 if (dassl_fcn)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
378 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
379 jac_name = unique_symbol_name ("__dassl_jac__");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
380 jname = "function jac = ";
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
381 jname.append(jac_name);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
382 jname.append (" (x, xdot, t, cj) jac = ");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
383 dassl_jac = extract_function
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
384 (tmp(1), "dassl", jac_name, jname,
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
385 "; endfunction");
5729
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
386
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
387 if (!dassl_jac)
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 (fcn_name.length())
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
390 clear_function (fcn_name);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
391 dassl_fcn = 0;
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 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
394 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
395 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
396 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
397 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
398 }
3991
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
399
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
400 if (error_state || ! dassl_fcn)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
401 DASSL_ABORT ();
3243
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
402
3419
e71b3d1dd327 [project @ 2000-01-12 05:23:34 by jwe]
jwe
parents: 3373
diff changeset
403 ColumnVector state = ColumnVector (args(1).vector_value ());
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
404
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
405 if (error_state)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
406 DASSL_ABORT1 ("expecting state vector as second argument");
3243
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
407
3419
e71b3d1dd327 [project @ 2000-01-12 05:23:34 by jwe]
jwe
parents: 3373
diff changeset
408 ColumnVector deriv (args(2).vector_value ());
3243
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
409
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
410 if (error_state)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
411 DASSL_ABORT1 ("expecting derivative vector as third argument");
3243
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
412
3419
e71b3d1dd327 [project @ 2000-01-12 05:23:34 by jwe]
jwe
parents: 3373
diff changeset
413 ColumnVector out_times (args(3).vector_value ());
3243
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
414
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
415 if (error_state)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
416 DASSL_ABORT1 ("expecting output time vector as fourth argument");
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
417
3243
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
418 ColumnVector crit_times;
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
419 int crit_times_set = 0;
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
420 if (nargin > 4)
10154
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 crit_times = ColumnVector (args(4).vector_value ());
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
423
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
424 if (error_state)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
425 DASSL_ABORT1 ("expecting critical time vector as fifth argument");
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
426
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
427 crit_times_set = 1;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
428 }
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
429
3243
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
430 if (state.capacity () != deriv.capacity ())
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
431 DASSL_ABORT1 ("x and xdot must have the same size");
3243
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
432
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
433 double tzero = out_times (0);
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
434
3243
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
435 DAEFunc func (dassl_user_function);
3991
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
436 if (dassl_jac)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
437 func.set_jacobian_function (dassl_user_jacobian);
3991
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
438
3243
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
439 DASSL dae (state, deriv, tzero, func);
3991
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
440
4122
19a1626b8d57 [project @ 2002-10-23 22:10:53 by jwe]
jwe
parents: 4117
diff changeset
441 dae.set_options (dassl_opts);
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
442
3243
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
443 Matrix output;
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
444 Matrix deriv_output;
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
445
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
446 if (crit_times_set)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
447 output = dae.integrate (out_times, deriv_output, crit_times);
3243
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
448 else
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
449 output = dae.integrate (out_times, deriv_output);
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
450
5729
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
451 if (fcn_name.length())
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
452 clear_function (fcn_name);
5729
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
453 if (jac_name.length())
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
454 clear_function (jac_name);
5729
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
455
3243
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
456 if (! error_state)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
457 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
458 std::string msg = dae.error_message ();
3997
d4091aff6468 [project @ 2002-07-17 18:00:06 by jwe]
jwe
parents: 3991
diff changeset
459
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
460 retval(3) = msg;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
461 retval(2) = static_cast<double> (dae.integration_state ());
3997
d4091aff6468 [project @ 2002-07-17 18:00:06 by jwe]
jwe
parents: 3991
diff changeset
462
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
463 if (dae.integration_ok ())
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
464 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
465 retval(1) = deriv_output;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
466 retval(0) = output;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
467 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
468 else
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 retval(1) = Matrix ();
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
471 retval(0) = Matrix ();
3997
d4091aff6468 [project @ 2002-07-17 18:00:06 by jwe]
jwe
parents: 3991
diff changeset
472
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
473 if (nargout < 3)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
474 error ("dassl: %s", msg.c_str ());
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
475 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10066
diff changeset
476 }
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
477 }
3243
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
478 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5729
diff changeset
479 print_usage ();
3243
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
480
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
481 return retval;
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
482 }
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
483
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
484 /*
7562
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
485
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
486 %% dassl-1.m
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
487 %%
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
488 %% Test dassl() function
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
489 %%
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
490 %% Author: David Billinghurst (David.Billinghurst@riotinto.com.au)
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
491 %% Comalco Research and Technology
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
492 %% 20 May 1998
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
493 %%
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
494 %% Problem
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
495 %%
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
496 %% y1' = -y2, y1(0) = 1
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
497 %% y2' = y1, y2(0) = 0
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
498 %%
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
499 %% Solution
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
500 %%
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
501 %% y1(t) = cos(t)
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
502 %% y2(t) = sin(t)
14085
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
503
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
504 %!function res = __f (x, xdot, t)
7562
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
505 %! res = [xdot(1)+x(2); xdot(2)-x(1)];
14085
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
506 %!endfunction
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
507
7562
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
508 %!test
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
509 %!
7562
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
510 %! x0 = [1; 0];
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
511 %! xdot0 = [0; 1];
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
512 %! t = (0:1:10)';
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
513 %!
7562
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
514 %! tol = 100 * dassl_options ("relative tolerance");
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
515 %!
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
516 %!
14085
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
517 %! [x, xdot] = dassl ("__f", x0, xdot0, t);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
518 %!
7562
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
519 %! y = [cos(t), sin(t)];
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
520 %!
7562
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
521 %! assert(all (all (abs (x - y) < tol)));
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
522
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
523 %% dassl-2.m
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
524 %%
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
525 %% Test dassl() function
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
526 %%
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
527 %% Author: David Billinghurst (David.Billinghurst@riotinto.com.au)
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
528 %% Comalco Research and Technology
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
529 %% 20 May 1998
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
530 %%
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
531 %% Based on SLATEC quick check for DASSL by Linda Petzold
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
532 %%
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
533 %% Problem
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
534 %%
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
535 %% x1' + 10*x1 = 0, x1(0) = 1
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
536 %% x1 + x2 = 1, x2(0) = 0
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
537 %%
7562
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
538 %%
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
539 %% Solution
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
540 %%
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
541 %% x1(t) = exp(-10*t)
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
542 %% x2(t) = 1 - x(1)
14085
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
543
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
544 %!function res = __f (x, xdot, t)
7562
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
545 %! res = [xdot(1)+10*x(1); x(1)+x(2)-1];
14085
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
546 %!endfunction
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
547
7562
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
548 %!test
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
549 %!
7562
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
550 %! x0 = [1; 0];
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
551 %! xdot0 = [-10; 10];
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
552 %! t = (0:0.2:1)';
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
553 %!
7562
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
554 %! tol = 500 * dassl_options ("relative tolerance");
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
555 %!
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
556 %!
14085
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
557 %! [x, xdot] = dassl ("__f", x0, xdot0, t);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
558 %!
7562
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
559 %! y = [exp(-10*t), 1-exp(-10*t)];
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
560 %!
7562
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
561 %! assert(all (all (abs (x - y) < tol)));
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
562
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
563 %!test
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
564 %! dassl_options ("absolute tolerance", eps);
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
565 %! assert(dassl_options ("absolute tolerance") == eps);
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
566
13915
5fa482628bf6 Remove unnecessary regular expression '.*' from ends of %!error blocks
Rik <octave@nomad.inbox5.com>
parents: 11586
diff changeset
567 %!error <Invalid call to dassl_options> dassl_options ("foo", 1, 2);
7562
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
568
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
569 */