annotate src/DLD-FUNCTIONS/daspk.cc @ 5440:b73d469ef0c9

[project @ 2005-09-04 12:31:45 by dbateman] ChangeLog
author dbateman
date Sun, 04 Sep 2005 12:31:45 +0000
parents 4c8a2e4e0717
children 2618a0750ae6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3912
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
1 /*
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
2
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
3 Copyright (C) 1996, 1997, 2002 John W. Eaton
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
4
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
6
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
9 Free Software Foundation; either version 2, or (at your option) any
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
10 later version.
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
11
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
15 for more details.
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
16
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
18 along with Octave; see the file COPYING. If not, write to the Free
5307
4c8a2e4e0717 [project @ 2005-04-26 19:24:27 by jwe]
jwe
parents: 5275
diff changeset
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
4c8a2e4e0717 [project @ 2005-04-26 19:24:27 by jwe]
jwe
parents: 5275
diff changeset
20 02110-1301, USA.
3912
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
21
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
22 */
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
23
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
24 #ifdef HAVE_CONFIG_H
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
25 #include <config.h>
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
26 #endif
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
27
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
28 #include <string>
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
29
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
30 #include <iomanip>
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
31 #include <iostream>
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
32
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
33 #include "DASPK.h"
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
34
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
35 #include "defun-dld.h"
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
36 #include "error.h"
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
37 #include "gripes.h"
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
38 #include "oct-obj.h"
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
39 #include "ov-fcn.h"
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
40 #include "pager.h"
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
41 #include "unwind-prot.h"
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
42 #include "utils.h"
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
43 #include "variables.h"
f56cd411adb4 [project @ 2002-04-28 03:12:27 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 "DASPK-opts.cc"
f6df65db67f9 [project @ 2002-07-24 18:10:39 by jwe]
jwe
parents: 3997
diff changeset
46
3912
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
47 // Global pointer for user defined function required by daspk.
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
48 static octave_function *daspk_fcn;
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
49
4140
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
50 // Global pointer for optional user defined jacobian function.
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
51 static octave_function *daspk_jac;
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
52
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
3912
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
57 // Is this a recursive call?
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
58 static int call_depth = 0;
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
59
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
60 ColumnVector
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
61 daspk_user_function (const ColumnVector& x, const ColumnVector& xdot,
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 4852
diff changeset
62 double t, octave_idx_type& ires)
3912
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
63 {
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
64 ColumnVector retval;
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
65
4628
c0121a3b9cbe [project @ 2003-11-17 20:19:07 by jwe]
jwe
parents: 4144
diff changeset
66 assert (x.capacity () == xdot.capacity ());
3912
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
67
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
68 octave_value_list args;
4628
c0121a3b9cbe [project @ 2003-11-17 20:19:07 by jwe]
jwe
parents: 4144
diff changeset
69
3912
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
70 args(2) = t;
4628
c0121a3b9cbe [project @ 2003-11-17 20:19:07 by jwe]
jwe
parents: 4144
diff changeset
71 args(1) = xdot;
c0121a3b9cbe [project @ 2003-11-17 20:19:07 by jwe]
jwe
parents: 4144
diff changeset
72 args(0) = x;
3912
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
73
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
74 if (daspk_fcn)
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
75 {
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
76 octave_value_list tmp = daspk_fcn->do_multi_index_op (1, args);
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
77
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
78 if (error_state)
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
79 {
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
80 gripe_user_supplied_eval ("daspk");
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
81 return retval;
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
82 }
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
83
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
84 int tlen = tmp.length ();
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
85 if (tlen > 0 && tmp(0).is_defined ())
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
86 {
4140
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
87 if (! warned_fcn_imaginary && tmp(0).is_complex_type ())
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
88 {
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
89 warning ("daspk: ignoring imaginary part returned from user-supplied function");
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
90 warned_fcn_imaginary = true;
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
91 }
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
92
3912
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
93 retval = ColumnVector (tmp(0).vector_value ());
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
94
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
95 if (tlen > 1)
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
96 ires = tmp(1).int_value ();
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
97
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
98 if (error_state || retval.length () == 0)
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
99 gripe_user_supplied_eval ("daspk");
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
100 }
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
101 else
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
102 gripe_user_supplied_eval ("daspk");
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
103 }
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
104
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
105 return retval;
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
106 }
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
107
4140
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
108 Matrix
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
109 daspk_user_jacobian (const ColumnVector& x, const ColumnVector& xdot,
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
110 double t, double cj)
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
111 {
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
112 Matrix retval;
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
113
4628
c0121a3b9cbe [project @ 2003-11-17 20:19:07 by jwe]
jwe
parents: 4144
diff changeset
114 assert (x.capacity () == xdot.capacity ());
4140
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
115
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
116 octave_value_list args;
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
117
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
118 args(3) = cj;
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
119 args(2) = t;
4628
c0121a3b9cbe [project @ 2003-11-17 20:19:07 by jwe]
jwe
parents: 4144
diff changeset
120 args(1) = xdot;
c0121a3b9cbe [project @ 2003-11-17 20:19:07 by jwe]
jwe
parents: 4144
diff changeset
121 args(0) = x;
4140
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
122
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
123 if (daspk_jac)
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
124 {
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
125 octave_value_list tmp = daspk_jac->do_multi_index_op (1, args);
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
126
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
127 if (error_state)
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
128 {
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
129 gripe_user_supplied_eval ("daspk");
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
130 return retval;
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
131 }
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
132
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
133 int tlen = tmp.length ();
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
134 if (tlen > 0 && tmp(0).is_defined ())
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
135 {
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
136 if (! warned_jac_imaginary && tmp(0).is_complex_type ())
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
137 {
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
138 warning ("daspk: ignoring imaginary part returned from user-supplied jacobian function");
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
139 warned_jac_imaginary = true;
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
140 }
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 retval = tmp(0).matrix_value ();
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
143
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
144 if (error_state || retval.length () == 0)
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
145 gripe_user_supplied_eval ("daspk");
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
146 }
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
147 else
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
148 gripe_user_supplied_eval ("daspk");
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
149 }
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
150
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
151 return retval;
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
152 }
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
153
3912
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
154 #define DASPK_ABORT() \
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
155 do \
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
156 { \
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
157 unwind_protect::run_frame ("Fdaspk"); \
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
158 return retval; \
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
159 } \
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
160 while (0)
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
161
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
162 #define DASPK_ABORT1(msg) \
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
163 do \
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
164 { \
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
165 ::error ("daspk: " msg); \
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
166 DASPK_ABORT (); \
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
167 } \
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
168 while (0)
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
169
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
170 #define DASPK_ABORT2(fmt, arg) \
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
171 do \
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
172 { \
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
173 ::error ("daspk: " fmt, arg); \
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
174 DASPK_ABORT (); \
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
175 } \
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
176 while (0)
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
177
3997
d4091aff6468 [project @ 2002-07-17 18:00:06 by jwe]
jwe
parents: 3964
diff changeset
178 DEFUN_DLD (daspk, args, nargout,
3912
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
179 "-*- texinfo -*-\n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
180 @deftypefn {Loadable Function} {[@var{x}, @var{xdot}, @var{istate}, @var{msg}] =} daspk (@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
181 Solve the set of differential-algebraic equations\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
182 @tex\n\
4852
404c7122853e [project @ 2004-04-06 17:23:37 by jwe]
jwe
parents: 4698
diff changeset
183 $$ 0 = f (x, \\dot{x}, t) $$\n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
184 with\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
185 $$ 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
186 @end tex\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
187 @ifinfo\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
188 \n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
189 @example\n\
4698
737fd5c0ae06 [project @ 2004-01-19 19:25:26 by jwe]
jwe
parents: 4628
diff changeset
190 0 = f (x, xdot, t)\n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
191 @end example\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
192 \n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
193 with\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
194 \n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
195 @example\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
196 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
197 @end example\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 @end ifinfo\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
200 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
201 with each row in the result matrices corresponding to one of the\n\
3912
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
202 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
203 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
204 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
205 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
206 of the output @var{xdot} is @var{xdot_0}.\n\
3912
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
207 \n\
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
208 The first argument, @var{fcn}, is a string that names the function to\n\
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
209 call to compute the vector of residuals for the set of equations.\n\
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
210 It must have the form\n\
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
211 \n\
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
212 @example\n\
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
213 @var{res} = f (@var{x}, @var{xdot}, @var{t})\n\
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
214 @end example\n\
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
215 \n\
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
216 @noindent\n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
217 in which @var{x}, @var{xdot}, and @var{res} are vectors, and @var{t} is a\n\
3912
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
218 scalar.\n\
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
219 \n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
220 If @var{fcn} is a two-element string array, the first element names\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
221 the function @math{f} described above, and the second element names\n\
4117
944b276d8856 [project @ 2002-10-23 01:06:46 by jwe]
jwe
parents: 4115
diff changeset
222 a function to compute the modified Jacobian\n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
223 @tex\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
224 $$\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
225 J = {\\partial f \\over \\partial x}\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
226 + c {\\partial f \\over \\partial \\dot{x}}\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
227 $$\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
228 @end tex\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
229 @ifinfo\n\
4144
b02ada83de67 [project @ 2002-11-01 18:03:56 by jwe]
jwe
parents: 4140
diff changeset
230 \n\
b02ada83de67 [project @ 2002-11-01 18:03:56 by jwe]
jwe
parents: 4140
diff changeset
231 @example\n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
232 df df\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
233 jac = -- + c ------\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
234 dx d xdot\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
235 @end example\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
236 @end ifinfo\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
237 \n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
238 The modified Jacobian function must have the form\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
239 \n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
240 @example\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
241 \n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
242 @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
243 \n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
244 @end example\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
245 \n\
3912
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
246 The second and third arguments to @code{daspk} specify the initial\n\
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
247 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
248 specifies a vector of output times at which the solution is desired,\n\
3912
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
249 including the time corresponding to the initial condition.\n\
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
250 \n\
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
251 The set of initial states and derivatives are not strictly required to\n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
252 be consistent. If they are not consistent, you must use the\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
253 @code{daspk_options} function to provide additional information so\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
254 that @code{daspk} can compute a consistent starting point.\n\
3912
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
255 \n\
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
256 The fifth argument is optional, and may be used to specify a set of\n\
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
257 times that the DAE solver should not integrate past. It is useful for\n\
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
258 avoiding difficulties with singularities and points where there is a\n\
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
259 discontinuity in the derivative.\n\
3964
3030cb6cb559 [project @ 2002-06-28 17:17:55 by jwe]
jwe
parents: 3912
diff changeset
260 \n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
261 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
262 greater than zero (consistent with the Fortran version of @sc{Daspk}).\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
263 \n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
264 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
265 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
266 \n\
3964
3030cb6cb559 [project @ 2002-06-28 17:17:55 by jwe]
jwe
parents: 3912
diff changeset
267 You can use the function @code{daspk_options} to set optional\n\
3030cb6cb559 [project @ 2002-06-28 17:17:55 by jwe]
jwe
parents: 3912
diff changeset
268 parameters for @code{daspk}.\n\
4115
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
269 @end deftypefn\n\
fc2048d4cd21 [project @ 2002-10-22 21:28:42 by jwe]
jwe
parents: 3998
diff changeset
270 @seealso{dassl}")
3912
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
271 {
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
272 octave_value_list retval;
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
273
4140
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
274 warned_fcn_imaginary = false;
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
275 warned_jac_imaginary = false;
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
276
3912
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
277 unwind_protect::begin_frame ("Fdaspk");
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
278
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
279 unwind_protect_int (call_depth);
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
280 call_depth++;
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
281
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
282 if (call_depth > 1)
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
283 DASPK_ABORT1 ("invalid recursive call");
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
284
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
285 int nargin = args.length ();
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
286
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
287 if (nargin > 3 && nargin < 6)
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
288 {
4140
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
289 daspk_fcn = 0;
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
290 daspk_jac = 0;
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
291
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
292 octave_value f_arg = args(0);
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
293
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
294 switch (f_arg.rows ())
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
295 {
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
296 case 1:
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
297 daspk_fcn = extract_function
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
298 (args(0), "daspk", "__daspk_fcn__",
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
299 "function res = __daspk_fcn__ (x, xdot, t) res = ",
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
300 "; endfunction");
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
301 break;
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
302
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
303 case 2:
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
304 {
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
305 string_vector tmp = f_arg.all_strings ();
3912
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
306
4140
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
307 if (! error_state)
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
308 {
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
309 daspk_fcn = extract_function
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
310 (tmp(0), "daspk", "__daspk_fcn__",
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
311 "function res = __daspk_fcn__ (x, xdot, t) res = ",
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
312 "; endfunction");
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
313
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
314 if (daspk_fcn)
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
315 {
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
316 daspk_jac = extract_function
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
317 (tmp(1), "daspk", "__daspk_jac__",
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
318 "function jac = __daspk_jac__ (x, xdot, t, cj) jac = ",
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
319 "; endfunction");
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
320
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
321 if (! daspk_jac)
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
322 daspk_fcn = 0;
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
323 }
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
324 }
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
325 }
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
326 }
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
327
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
328 if (error_state || ! daspk_fcn)
3912
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
329 DASPK_ABORT ();
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
330
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
331 ColumnVector state = ColumnVector (args(1).vector_value ());
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
332
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
333 if (error_state)
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
334 DASPK_ABORT1 ("expecting state vector as second argument");
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
335
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
336 ColumnVector deriv (args(2).vector_value ());
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
337
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
338 if (error_state)
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
339 DASPK_ABORT1 ("expecting derivative vector as third argument");
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
340
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
341 ColumnVector out_times (args(3).vector_value ());
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
342
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
343 if (error_state)
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
344 DASPK_ABORT1 ("expecting output time vector as fourth argument");
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
345
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
346 ColumnVector crit_times;
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
347 int crit_times_set = 0;
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
348 if (nargin > 4)
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
349 {
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
350 crit_times = ColumnVector (args(4).vector_value ());
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
351
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
352 if (error_state)
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
353 DASPK_ABORT1 ("expecting critical time vector as fifth argument");
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
354
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
355 crit_times_set = 1;
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
356 }
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
357
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
358 if (state.capacity () != deriv.capacity ())
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
359 DASPK_ABORT1 ("x and xdot must have the same size");
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
360
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
361 double tzero = out_times (0);
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
362
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
363 DAEFunc func (daspk_user_function);
4140
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
364 if (daspk_jac)
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
365 func.set_jacobian_function (daspk_user_jacobian);
303b28a7a7e4 [project @ 2002-11-01 02:53:13 by jwe]
jwe
parents: 4122
diff changeset
366
3912
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
367 DASPK dae (state, deriv, tzero, func);
4122
19a1626b8d57 [project @ 2002-10-23 22:10:53 by jwe]
jwe
parents: 4117
diff changeset
368 dae.set_options (daspk_opts);
3912
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
369
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
370 Matrix output;
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
371 Matrix deriv_output;
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
372
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
373 if (crit_times_set)
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
374 output = dae.integrate (out_times, deriv_output, crit_times);
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
375 else
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
376 output = dae.integrate (out_times, deriv_output);
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
377
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
378 if (! error_state)
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
379 {
3997
d4091aff6468 [project @ 2002-07-17 18:00:06 by jwe]
jwe
parents: 3964
diff changeset
380 std::string msg = dae.error_message ();
d4091aff6468 [project @ 2002-07-17 18:00:06 by jwe]
jwe
parents: 3964
diff changeset
381
d4091aff6468 [project @ 2002-07-17 18:00:06 by jwe]
jwe
parents: 3964
diff changeset
382 retval(3) = msg;
d4091aff6468 [project @ 2002-07-17 18:00:06 by jwe]
jwe
parents: 3964
diff changeset
383 retval(2) = static_cast<double> (dae.integration_state ());
3912
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
384
3997
d4091aff6468 [project @ 2002-07-17 18:00:06 by jwe]
jwe
parents: 3964
diff changeset
385 if (dae.integration_ok ())
d4091aff6468 [project @ 2002-07-17 18:00:06 by jwe]
jwe
parents: 3964
diff changeset
386 {
d4091aff6468 [project @ 2002-07-17 18:00:06 by jwe]
jwe
parents: 3964
diff changeset
387 retval(1) = deriv_output;
d4091aff6468 [project @ 2002-07-17 18:00:06 by jwe]
jwe
parents: 3964
diff changeset
388 retval(0) = output;
d4091aff6468 [project @ 2002-07-17 18:00:06 by jwe]
jwe
parents: 3964
diff changeset
389 }
d4091aff6468 [project @ 2002-07-17 18:00:06 by jwe]
jwe
parents: 3964
diff changeset
390 else
d4091aff6468 [project @ 2002-07-17 18:00:06 by jwe]
jwe
parents: 3964
diff changeset
391 {
d4091aff6468 [project @ 2002-07-17 18:00:06 by jwe]
jwe
parents: 3964
diff changeset
392 retval(1) = Matrix ();
d4091aff6468 [project @ 2002-07-17 18:00:06 by jwe]
jwe
parents: 3964
diff changeset
393 retval(0) = Matrix ();
d4091aff6468 [project @ 2002-07-17 18:00:06 by jwe]
jwe
parents: 3964
diff changeset
394
d4091aff6468 [project @ 2002-07-17 18:00:06 by jwe]
jwe
parents: 3964
diff changeset
395 if (nargout < 3)
d4091aff6468 [project @ 2002-07-17 18:00:06 by jwe]
jwe
parents: 3964
diff changeset
396 error ("daspk: %s", msg.c_str ());
d4091aff6468 [project @ 2002-07-17 18:00:06 by jwe]
jwe
parents: 3964
diff changeset
397 }
3912
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
398 }
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
399 }
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
400 else
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
401 print_usage ("daspk");
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
402
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
403 unwind_protect::run_frame ("Fdaspk");
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
404
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
405 return retval;
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
406 }
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
407
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
408 /*
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
409 ;;; Local Variables: ***
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
410 ;;; mode: C++ ***
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
411 ;;; End: ***
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
412 */