annotate src/DLD-FUNCTIONS/dassl.cc @ 9064:7c02ec148a3c

Check grammar on all .cc files Same check as previously done on .m files Attempt to enforce some conformity in documentation text for rules such as two spaces after a period, commas around latin abbreviations, etc.
author Rik <rdrider0-list@yahoo.com>
date Sat, 28 Mar 2009 13:57:22 -0700
parents eb63fbe60fab
children 8970b4b10e9f
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
7017
a1dbe9d80eee [project @ 2007-10-12 21:27:11 by jwe]
jwe
parents: 7016
diff changeset
3 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
8920
eb63fbe60fab update copyright notices
John W. Eaton <jwe@octave.org>
parents: 8787
diff changeset
4 2005, 2006, 2007, 2008, 2009 John W. Eaton
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
5
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
6 This file is part of Octave.
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
7
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
8 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
9 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
10 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
11 option) any later version.
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
12
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
13 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
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
15 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
16 for more details.
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
17
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
18 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
19 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
20 <http://www.gnu.org/licenses/>.
2928
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
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
24 #ifdef HAVE_CONFIG_H
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
25 #include <config.h>
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
26 #endif
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
27
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
28 #include <string>
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
29
3567
dd8998699aa8 [project @ 2000-02-03 09:54:28 by jwe]
jwe
parents: 3544
diff changeset
30 #include <iomanip>
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3419
diff changeset
31 #include <iostream>
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
32
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
33 #include "DASSL.h"
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
34
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
35 #include "defun-dld.h"
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
36 #include "error.h"
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
37 #include "gripes.h"
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
38 #include "oct-obj.h"
2968
e330cb788508 [project @ 1997-05-15 17:40:29 by jwe]
jwe
parents: 2928
diff changeset
39 #include "ov-fcn.h"
5729
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
40 #include "ov-cell.h"
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
41 #include "pager.h"
3243
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
42 #include "unwind-prot.h"
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
43 #include "utils.h"
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
44 #include "variables.h"
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
45
3998
f6df65db67f9 [project @ 2002-07-24 18:10:39 by jwe]
jwe
parents: 3997
diff changeset
46 #include "DASSL-opts.cc"
f6df65db67f9 [project @ 2002-07-24 18:10:39 by jwe]
jwe
parents: 3997
diff changeset
47
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
48 // 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
49 static octave_function *dassl_fcn;
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
50
3991
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
51 // Global pointer for optional user defined jacobian function.
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
52 static octave_function *dassl_jac;
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
53
4140
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
54 // 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
55 static bool warned_fcn_imaginary = false;
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
56 static bool warned_jac_imaginary = false;
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
57
3243
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
58 // Is this a recursive call?
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
59 static int call_depth = 0;
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
60
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
61 ColumnVector
3849
5266e351a19c [project @ 2001-11-02 04:50:09 by jwe]
jwe
parents: 3747
diff changeset
62 dassl_user_function (const ColumnVector& x, const ColumnVector& xdot,
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 4912
diff changeset
63 double t, octave_idx_type& ires)
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
64 {
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
65 ColumnVector retval;
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
66
4628
c0121a3b9cbe [project @ 2003-11-17 20:19:07 by jwe]
jwe
parents: 4140
diff changeset
67 assert (x.capacity () == xdot.capacity ());
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
68
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
69 octave_value_list args;
4628
c0121a3b9cbe [project @ 2003-11-17 20:19:07 by jwe]
jwe
parents: 4140
diff changeset
70
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
71 args(2) = t;
4628
c0121a3b9cbe [project @ 2003-11-17 20:19:07 by jwe]
jwe
parents: 4140
diff changeset
72 args(1) = xdot;
c0121a3b9cbe [project @ 2003-11-17 20:19:07 by jwe]
jwe
parents: 4140
diff changeset
73 args(0) = x;
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
74
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
75 if (dassl_fcn)
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
76 {
3544
71bd2d124119 [project @ 2000-02-02 21:02:31 by jwe]
jwe
parents: 3523
diff changeset
77 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
78
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
79 if (error_state)
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
80 {
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
81 gripe_user_supplied_eval ("dassl");
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
82 return retval;
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
83 }
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
84
3849
5266e351a19c [project @ 2001-11-02 04:50:09 by jwe]
jwe
parents: 3747
diff changeset
85 int tlen = tmp.length ();
5266e351a19c [project @ 2001-11-02 04:50:09 by jwe]
jwe
parents: 3747
diff changeset
86 if (tlen > 0 && tmp(0).is_defined ())
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
87 {
4140
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
88 if (! warned_fcn_imaginary && tmp(0).is_complex_type ())
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
89 {
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
90 warning ("dassl: ignoring imaginary part returned from user-supplied function");
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
91 warned_fcn_imaginary = true;
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
92 }
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
93
3419
e71b3d1dd327 [project @ 2000-01-12 05:23:34 by jwe]
jwe
parents: 3373
diff changeset
94 retval = ColumnVector (tmp(0).vector_value ());
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
95
3849
5266e351a19c [project @ 2001-11-02 04:50:09 by jwe]
jwe
parents: 3747
diff changeset
96 if (tlen > 1)
5266e351a19c [project @ 2001-11-02 04:50:09 by jwe]
jwe
parents: 3747
diff changeset
97 ires = tmp(1).int_value ();
5266e351a19c [project @ 2001-11-02 04:50:09 by jwe]
jwe
parents: 3747
diff changeset
98
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
99 if (error_state || retval.length () == 0)
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
100 gripe_user_supplied_eval ("dassl");
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
101 }
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
102 else
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
103 gripe_user_supplied_eval ("dassl");
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
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
106 return retval;
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
107 }
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
108
3991
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
109 Matrix
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
110 dassl_user_jacobian (const ColumnVector& x, const ColumnVector& xdot,
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
111 double t, double cj)
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
112 {
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
113 Matrix retval;
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
114
4628
c0121a3b9cbe [project @ 2003-11-17 20:19:07 by jwe]
jwe
parents: 4140
diff changeset
115 assert (x.capacity () == xdot.capacity ());
3991
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
116
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
117 octave_value_list args;
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
118
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
119 args(3) = cj;
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
120 args(2) = t;
4628
c0121a3b9cbe [project @ 2003-11-17 20:19:07 by jwe]
jwe
parents: 4140
diff changeset
121 args(1) = xdot;
c0121a3b9cbe [project @ 2003-11-17 20:19:07 by jwe]
jwe
parents: 4140
diff changeset
122 args(0) = x;
3991
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
123
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
124 if (dassl_jac)
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
125 {
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
126 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
127
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
128 if (error_state)
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
129 {
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
130 gripe_user_supplied_eval ("dassl");
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
131 return retval;
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
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
134 int tlen = tmp.length ();
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
135 if (tlen > 0 && tmp(0).is_defined ())
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
136 {
4140
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
137 if (! warned_jac_imaginary && tmp(0).is_complex_type ())
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
138 {
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
139 warning ("dassl: ignoring imaginary part returned from user-supplied jacobian function");
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
140 warned_jac_imaginary = true;
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
141 }
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
142
3991
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
143 retval = tmp(0).matrix_value ();
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
144
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
145 if (error_state || retval.length () == 0)
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
146 gripe_user_supplied_eval ("dassl");
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
147 }
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
148 else
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
149 gripe_user_supplied_eval ("dassl");
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
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
152 return retval;
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
153 }
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
154
3323
511caaa5e98e [project @ 1999-10-27 02:21:46 by jwe]
jwe
parents: 3321
diff changeset
155 #define DASSL_ABORT() \
511caaa5e98e [project @ 1999-10-27 02:21:46 by jwe]
jwe
parents: 3321
diff changeset
156 do \
511caaa5e98e [project @ 1999-10-27 02:21:46 by jwe]
jwe
parents: 3321
diff changeset
157 { \
511caaa5e98e [project @ 1999-10-27 02:21:46 by jwe]
jwe
parents: 3321
diff changeset
158 unwind_protect::run_frame ("Fdassl"); \
511caaa5e98e [project @ 1999-10-27 02:21:46 by jwe]
jwe
parents: 3321
diff changeset
159 return retval; \
511caaa5e98e [project @ 1999-10-27 02:21:46 by jwe]
jwe
parents: 3321
diff changeset
160 } \
511caaa5e98e [project @ 1999-10-27 02:21:46 by jwe]
jwe
parents: 3321
diff changeset
161 while (0)
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 #define DASSL_ABORT1(msg) \
511caaa5e98e [project @ 1999-10-27 02:21:46 by jwe]
jwe
parents: 3321
diff changeset
164 do \
511caaa5e98e [project @ 1999-10-27 02:21:46 by jwe]
jwe
parents: 3321
diff changeset
165 { \
3747
50f30e40abca [project @ 2000-12-07 05:47:06 by jwe]
jwe
parents: 3568
diff changeset
166 ::error ("dassl: " msg); \
3323
511caaa5e98e [project @ 1999-10-27 02:21:46 by jwe]
jwe
parents: 3321
diff changeset
167 DASSL_ABORT (); \
511caaa5e98e [project @ 1999-10-27 02:21:46 by jwe]
jwe
parents: 3321
diff changeset
168 } \
511caaa5e98e [project @ 1999-10-27 02:21:46 by jwe]
jwe
parents: 3321
diff changeset
169 while (0)
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 #define DASSL_ABORT2(fmt, arg) \
511caaa5e98e [project @ 1999-10-27 02:21:46 by jwe]
jwe
parents: 3321
diff changeset
172 do \
511caaa5e98e [project @ 1999-10-27 02:21:46 by jwe]
jwe
parents: 3321
diff changeset
173 { \
3747
50f30e40abca [project @ 2000-12-07 05:47:06 by jwe]
jwe
parents: 3568
diff changeset
174 ::error ("dassl: " fmt, arg); \
3323
511caaa5e98e [project @ 1999-10-27 02:21:46 by jwe]
jwe
parents: 3321
diff changeset
175 DASSL_ABORT (); \
511caaa5e98e [project @ 1999-10-27 02:21:46 by jwe]
jwe
parents: 3321
diff changeset
176 } \
511caaa5e98e [project @ 1999-10-27 02:21:46 by jwe]
jwe
parents: 3321
diff changeset
177 while (0)
511caaa5e98e [project @ 1999-10-27 02:21:46 by jwe]
jwe
parents: 3321
diff changeset
178
3991
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
179 DEFUN_DLD (dassl, args, nargout,
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3325
diff changeset
180 "-*- texinfo -*-\n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
181 @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
182 Solve the set of differential-algebraic equations\n\
4912
048db020498c [project @ 2004-07-22 20:45:59 by jwe]
jwe
parents: 4888
diff changeset
183 @iftex\n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
184 @tex\n\
4852
404c7122853e [project @ 2004-04-06 17:23:37 by jwe]
jwe
parents: 4698
diff changeset
185 $$ 0 = f (x, \\dot{x}, t) $$\n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
186 with\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
187 $$ 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
188 @end tex\n\
4912
048db020498c [project @ 2004-07-22 20:45:59 by jwe]
jwe
parents: 4888
diff changeset
189 @end iftex\n\
8517
81d6ab3ac93c Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents: 7562
diff changeset
190 @ifnottex\n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
191 \n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
192 @example\n\
4698
737fd5c0ae06 [project @ 2004-01-19 19:25:26 by jwe]
jwe
parents: 4628
diff changeset
193 0 = f (x, xdot, t)\n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
194 @end example\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
195 \n\
4912
048db020498c [project @ 2004-07-22 20:45:59 by jwe]
jwe
parents: 4888
diff changeset
196 @noindent\n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
197 with\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
198 \n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
199 @example\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
200 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
201 @end example\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
202 \n\
8517
81d6ab3ac93c Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents: 7562
diff changeset
203 @end ifnottex\n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
204 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
205 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
206 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
207 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
208 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
209 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
210 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
211 \n\
8787
5b23faa8113c Documentation fixes.
Olaf Till <olaf.till@uni-jena.de>
parents: 8517
diff changeset
212 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
213 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
214 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
215 \n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3325
diff changeset
216 @example\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3325
diff changeset
217 @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
218 @end example\n\
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
219 \n\
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3325
diff changeset
220 @noindent\n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
221 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
222 scalar.\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3325
diff changeset
223 \n\
8787
5b23faa8113c Documentation fixes.
Olaf Till <olaf.till@uni-jena.de>
parents: 8517
diff changeset
224 If @var{fcn} is a two-element string array or a two-element cell array\n\
5b23faa8113c Documentation fixes.
Olaf Till <olaf.till@uni-jena.de>
parents: 8517
diff changeset
225 of strings, inlines, or function handles, the first element names\n\
5b23faa8113c Documentation fixes.
Olaf Till <olaf.till@uni-jena.de>
parents: 8517
diff changeset
226 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
227 function to compute the modified Jacobian\n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
228 \n\
4912
048db020498c [project @ 2004-07-22 20:45:59 by jwe]
jwe
parents: 4888
diff changeset
229 @iftex\n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
230 @tex\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
231 $$\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
232 J = {\\partial f \\over \\partial x}\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
233 + c {\\partial f \\over \\partial \\dot{x}}\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
234 $$\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
235 @end tex\n\
4912
048db020498c [project @ 2004-07-22 20:45:59 by jwe]
jwe
parents: 4888
diff changeset
236 @end iftex\n\
8517
81d6ab3ac93c Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents: 7562
diff changeset
237 @ifnottex\n\
4888
4a796c5fc7a3 [project @ 2004-04-30 18:27:07 by jwe]
jwe
parents: 4852
diff changeset
238 @example\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
239 @group\n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
240 df df\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
241 jac = -- + c ------\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
242 dx d xdot\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
243 @end group\n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
244 @end example\n\
8517
81d6ab3ac93c Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents: 7562
diff changeset
245 @end ifnottex\n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
246 \n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
247 The modified Jacobian function must have the form\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
248 \n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
249 @example\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
250 @group\n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
251 \n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
252 @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
253 \n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
254 @end group\n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
255 @end example\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
256 \n\
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3325
diff changeset
257 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
258 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
259 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
260 including the time corresponding to the initial condition.\n\
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
261 \n\
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3325
diff changeset
262 The set of initial states and derivatives are not strictly required to\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3325
diff changeset
263 be consistent. In practice, however, @sc{Dassl} is not very good at\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3325
diff changeset
264 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
265 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
266 \n\
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3325
diff changeset
267 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
268 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
269 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
270 discontinuity in the derivative.\n\
3964
3030cb6cb559 [project @ 2002-06-28 17:17:55 by jwe]
jwe
parents: 3849
diff changeset
271 \n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
272 After a successful computation, the value of @var{istate} will be\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
273 greater than zero (consistent with the Fortran version of @sc{Dassl}).\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
274 \n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
275 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
276 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
277 \n\
3964
3030cb6cb559 [project @ 2002-06-28 17:17:55 by jwe]
jwe
parents: 3849
diff changeset
278 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
279 parameters for @code{dassl}.\n\
5694
95d90f781ca8 [project @ 2006-03-20 18:29:20 by jwe]
jwe
parents: 5642
diff changeset
280 @seealso{daspk, dasrt, lsode}\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5307
diff changeset
281 @end deftypefn")
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
282 {
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
283 octave_value_list retval;
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
284
4140
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
285 warned_fcn_imaginary = false;
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
286 warned_jac_imaginary = false;
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
287
3243
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
288 unwind_protect::begin_frame ("Fdassl");
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
289
3243
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
290 unwind_protect_int (call_depth);
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
291 call_depth++;
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
292
3243
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
293 if (call_depth > 1)
3323
511caaa5e98e [project @ 1999-10-27 02:21:46 by jwe]
jwe
parents: 3321
diff changeset
294 DASSL_ABORT1 ("invalid recursive call");
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
295
3243
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
296 int nargin = args.length ();
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
297
3991
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
298 if (nargin > 3 && nargin < 6 && nargout < 5)
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
299 {
5729
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
300 std::string fcn_name, fname, jac_name, jname;
3991
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
301 dassl_fcn = 0;
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
302 dassl_jac = 0;
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
303
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
304 octave_value f_arg = args(0);
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
305
5729
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
306 if (f_arg.is_cell ())
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
307 {
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
308 Cell c = f_arg.cell_value ();
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
309 if (c.length() == 1)
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
310 f_arg = c(0);
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
311 else if (c.length() == 2)
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
312 {
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
313 if (c(0).is_function_handle () || c(0).is_inline_function ())
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
314 dassl_fcn = c(0).function_value ();
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
315 else
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
316 {
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
317 fcn_name = unique_symbol_name ("__dassl_fcn__");
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
318 fname = "function y = ";
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
319 fname.append (fcn_name);
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
320 fname.append (" (x, xdot, t) y = ");
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
321 dassl_fcn = extract_function
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
322 (c(0), "dassl", fcn_name, fname, "; endfunction");
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
323 }
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
324
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
325 if (dassl_fcn)
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
326 {
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
327 if (c(1).is_function_handle () || c(1).is_inline_function ())
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
328 dassl_jac = c(1).function_value ();
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
329 else
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
330 {
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
331 jac_name = unique_symbol_name ("__dassl_jac__");
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
332 jname = "function jac = ";
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
333 jname.append(jac_name);
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
334 jname.append (" (x, xdot, t, cj) jac = ");
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
335 dassl_jac = extract_function
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
336 (c(1), "dassl", jac_name, jname, "; endfunction");
3991
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
337
5729
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
338 if (!dassl_jac)
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
339 {
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
340 if (fcn_name.length())
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
341 clear_function (fcn_name);
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
342 dassl_fcn = 0;
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
343 }
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
344 }
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
345 }
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
346 }
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
347 else
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
348 DASSL_ABORT1 ("incorrect number of elements in cell array");
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
349 }
3243
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
350
5729
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
351 if (!dassl_fcn && ! f_arg.is_cell())
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
352 {
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
353 if (f_arg.is_function_handle () || f_arg.is_inline_function ())
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
354 dassl_fcn = f_arg.function_value ();
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
355 else
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
356 {
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
357 switch (f_arg.rows ())
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
358 {
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
359 case 1:
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
360 do
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
361 {
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
362 fcn_name = unique_symbol_name ("__dassl_fcn__");
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
363 fname = "function y = ";
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
364 fname.append (fcn_name);
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
365 fname.append (" (x, xdot, t) y = ");
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
366 dassl_fcn = extract_function
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
367 (f_arg, "dassl", fcn_name, fname, "; endfunction");
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
368 }
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
369 while (0);
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
370 break;
3991
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
371
5729
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
372 case 2:
3991
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
373 {
5729
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
374 string_vector tmp = f_arg.all_strings ();
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
375
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
376 if (! error_state)
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
377 {
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
378 fcn_name = unique_symbol_name ("__dassl_fcn__");
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
379 fname = "function y = ";
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
380 fname.append (fcn_name);
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
381 fname.append (" (x, xdot, t) y = ");
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
382 dassl_fcn = extract_function
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
383 (tmp(0), "dassl", fcn_name, fname, "; endfunction");
3991
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
384
5729
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
385 if (dassl_fcn)
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
386 {
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
387 jac_name = unique_symbol_name ("__dassl_jac__");
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
388 jname = "function jac = ";
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
389 jname.append(jac_name);
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
390 jname.append (" (x, xdot, t, cj) jac = ");
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
391 dassl_jac = extract_function
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
392 (tmp(1), "dassl", jac_name, jname,
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
393 "; endfunction");
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
394
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
395 if (!dassl_jac)
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
396 {
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
397 if (fcn_name.length())
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
398 clear_function (fcn_name);
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
399 dassl_fcn = 0;
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
400 }
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
401 }
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
402 }
3991
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
403 }
5729
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
404 }
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
405 }
3991
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
406 }
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
407
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
408 if (error_state || ! dassl_fcn)
3323
511caaa5e98e [project @ 1999-10-27 02:21:46 by jwe]
jwe
parents: 3321
diff changeset
409 DASSL_ABORT ();
3243
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
410
3419
e71b3d1dd327 [project @ 2000-01-12 05:23:34 by jwe]
jwe
parents: 3373
diff changeset
411 ColumnVector state = ColumnVector (args(1).vector_value ());
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
412
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
413 if (error_state)
3323
511caaa5e98e [project @ 1999-10-27 02:21:46 by jwe]
jwe
parents: 3321
diff changeset
414 DASSL_ABORT1 ("expecting state vector as second argument");
3243
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
415
3419
e71b3d1dd327 [project @ 2000-01-12 05:23:34 by jwe]
jwe
parents: 3373
diff changeset
416 ColumnVector deriv (args(2).vector_value ());
3243
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
417
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
418 if (error_state)
3323
511caaa5e98e [project @ 1999-10-27 02:21:46 by jwe]
jwe
parents: 3321
diff changeset
419 DASSL_ABORT1 ("expecting derivative vector as third argument");
3243
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
420
3419
e71b3d1dd327 [project @ 2000-01-12 05:23:34 by jwe]
jwe
parents: 3373
diff changeset
421 ColumnVector out_times (args(3).vector_value ());
3243
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
422
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
423 if (error_state)
3323
511caaa5e98e [project @ 1999-10-27 02:21:46 by jwe]
jwe
parents: 3321
diff changeset
424 DASSL_ABORT1 ("expecting output time vector as fourth argument");
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
425
3243
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
426 ColumnVector crit_times;
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
427 int crit_times_set = 0;
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
428 if (nargin > 4)
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
429 {
3419
e71b3d1dd327 [project @ 2000-01-12 05:23:34 by jwe]
jwe
parents: 3373
diff changeset
430 crit_times = ColumnVector (args(4).vector_value ());
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
431
3243
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
432 if (error_state)
3323
511caaa5e98e [project @ 1999-10-27 02:21:46 by jwe]
jwe
parents: 3321
diff changeset
433 DASSL_ABORT1 ("expecting critical time vector as fifth argument");
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 crit_times_set = 1;
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
436 }
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
437
3243
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
438 if (state.capacity () != deriv.capacity ())
3323
511caaa5e98e [project @ 1999-10-27 02:21:46 by jwe]
jwe
parents: 3321
diff changeset
439 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
440
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
441 double tzero = out_times (0);
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 DAEFunc func (dassl_user_function);
3991
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
444 if (dassl_jac)
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
445 func.set_jacobian_function (dassl_user_jacobian);
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
446
3243
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
447 DASSL dae (state, deriv, tzero, func);
3991
48d2bc4a3729 [project @ 2002-07-16 17:46:50 by jwe]
jwe
parents: 3964
diff changeset
448
4122
19a1626b8d57 [project @ 2002-10-23 22:10:53 by jwe]
jwe
parents: 4117
diff changeset
449 dae.set_options (dassl_opts);
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
450
3243
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
451 Matrix output;
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
452 Matrix deriv_output;
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
453
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
454 if (crit_times_set)
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
455 output = dae.integrate (out_times, deriv_output, crit_times);
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
456 else
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
457 output = dae.integrate (out_times, deriv_output);
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
458
5729
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
459 if (fcn_name.length())
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
460 clear_function (fcn_name);
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
461 if (jac_name.length())
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
462 clear_function (jac_name);
e065f7c18bdc [project @ 2006-04-03 19:03:30 by jwe]
jwe
parents: 5694
diff changeset
463
3243
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
464 if (! error_state)
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
465 {
3997
d4091aff6468 [project @ 2002-07-17 18:00:06 by jwe]
jwe
parents: 3991
diff changeset
466 std::string msg = dae.error_message ();
d4091aff6468 [project @ 2002-07-17 18:00:06 by jwe]
jwe
parents: 3991
diff changeset
467
d4091aff6468 [project @ 2002-07-17 18:00:06 by jwe]
jwe
parents: 3991
diff changeset
468 retval(3) = msg;
d4091aff6468 [project @ 2002-07-17 18:00:06 by jwe]
jwe
parents: 3991
diff changeset
469 retval(2) = static_cast<double> (dae.integration_state ());
d4091aff6468 [project @ 2002-07-17 18:00:06 by jwe]
jwe
parents: 3991
diff changeset
470
d4091aff6468 [project @ 2002-07-17 18:00:06 by jwe]
jwe
parents: 3991
diff changeset
471 if (dae.integration_ok ())
d4091aff6468 [project @ 2002-07-17 18:00:06 by jwe]
jwe
parents: 3991
diff changeset
472 {
d4091aff6468 [project @ 2002-07-17 18:00:06 by jwe]
jwe
parents: 3991
diff changeset
473 retval(1) = deriv_output;
d4091aff6468 [project @ 2002-07-17 18:00:06 by jwe]
jwe
parents: 3991
diff changeset
474 retval(0) = output;
d4091aff6468 [project @ 2002-07-17 18:00:06 by jwe]
jwe
parents: 3991
diff changeset
475 }
d4091aff6468 [project @ 2002-07-17 18:00:06 by jwe]
jwe
parents: 3991
diff changeset
476 else
d4091aff6468 [project @ 2002-07-17 18:00:06 by jwe]
jwe
parents: 3991
diff changeset
477 {
d4091aff6468 [project @ 2002-07-17 18:00:06 by jwe]
jwe
parents: 3991
diff changeset
478 retval(1) = Matrix ();
d4091aff6468 [project @ 2002-07-17 18:00:06 by jwe]
jwe
parents: 3991
diff changeset
479 retval(0) = Matrix ();
d4091aff6468 [project @ 2002-07-17 18:00:06 by jwe]
jwe
parents: 3991
diff changeset
480
d4091aff6468 [project @ 2002-07-17 18:00:06 by jwe]
jwe
parents: 3991
diff changeset
481 if (nargout < 3)
d4091aff6468 [project @ 2002-07-17 18:00:06 by jwe]
jwe
parents: 3991
diff changeset
482 error ("dassl: %s", msg.c_str ());
d4091aff6468 [project @ 2002-07-17 18:00:06 by jwe]
jwe
parents: 3991
diff changeset
483 }
3243
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
484 }
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
485 }
3243
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
486 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5729
diff changeset
487 print_usage ();
3243
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
488
dd00769643ae [project @ 1999-05-28 04:19:00 by jwe]
jwe
parents: 3131
diff changeset
489 unwind_protect::run_frame ("Fdassl");
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
490
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
491 return retval;
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
492 }
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
493
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
494 /*
7562
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 %% dassl-1.m
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
497 %%
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
498 %% Test dassl() function
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
499 %%
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
500 %% 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
501 %% Comalco Research and Technology
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
502 %% 20 May 1998
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
503 %%
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
504 %% Problem
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
505 %%
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
506 %% y1' = -y2, y1(0) = 1
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
507 %% y2' = y1, y2(0) = 0
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
508 %%
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
509 %% Solution
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
510 %%
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
511 %% y1(t) = cos(t)
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
512 %% y2(t) = sin(t)
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
513 %!function res = f (x, xdot, t)
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
514 %! res = [xdot(1)+x(2); xdot(2)-x(1)];
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
515 %!test
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
516 %!
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
517 %! x0 = [1; 0];
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
518 %! xdot0 = [0; 1];
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
519 %! t = (0:1:10)';
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
520 %!
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
521 %! tol = 100 * dassl_options ("relative tolerance");
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 %!
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
524 %! [x, xdot] = dassl ("f", x0, xdot0, t);
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
525 %!
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
526 %! y = [cos(t), sin(t)];
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
527 %!
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
528 %! assert(all (all (abs (x - y) < tol)));
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
529
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
530 %% dassl-2.m
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
531 %%
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
532 %% Test dassl() function
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
533 %%
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
534 %% 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
535 %% Comalco Research and Technology
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
536 %% 20 May 1998
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
537 %%
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
538 %% 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
539 %%
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
540 %% Problem
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
541 %%
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
542 %% x1' + 10*x1 = 0, x1(0) = 1
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
543 %% x1 + x2 = 1, x2(0) = 0
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
544 %%
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
545 %%
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
546 %% Solution
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
547 %%
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
548 %% x1(t) = exp(-10*t)
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
549 %% x2(t) = 1 - x(1)
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
550 %!function res = f (x, xdot, t)
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
551 %! res = [xdot(1)+10*x(1); x(1)+x(2)-1];
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
552 %!test
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
553 %!
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
554 %! x0 = [1; 0];
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
555 %! xdot0 = [-10; 10];
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
556 %! t = (0:0.2:1)';
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
557 %!
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
558 %! tol = 500 * dassl_options ("relative tolerance");
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
559 %!
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
560 %!
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
561 %! [x, xdot] = dassl ("f", x0, xdot0, t);
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 %! y = [exp(-10*t), 1-exp(-10*t)];
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
564 %!
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
565 %! assert(all (all (abs (x - y) < tol)));
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
566
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
567 %!test
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
568 %! dassl_options ("absolute tolerance", eps);
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
569 %! assert(dassl_options ("absolute tolerance") == eps);
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
570
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
571 %!error <Invalid call to dassl_options.*> dassl_options ("foo", 1, 2);
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
572
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
573 */
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
574
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
575 /*
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
576 ;;; Local Variables: ***
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
577 ;;; mode: C++ ***
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
578 ;;; End: ***
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
579 */