3294
|
1 @c Copyright (C) 1996, 1997 John W. Eaton |
|
2 @c This is part of the Octave manual. |
|
3 @c For copying conditions, see the file gpl.texi. |
|
4 |
4167
|
5 @node Differential Equations |
3294
|
6 @chapter Differential Equations |
|
7 |
|
8 Octave has two built-in functions for solving differential equations. |
|
9 Both are based on reliable ODE solvers written in Fortran. |
|
10 |
|
11 @menu |
|
12 * Ordinary Differential Equations:: |
|
13 * Differential-Algebraic Equations:: |
|
14 @end menu |
|
15 |
|
16 @cindex Differential Equations |
|
17 @cindex ODE |
|
18 @cindex DAE |
|
19 |
4167
|
20 @node Ordinary Differential Equations |
3294
|
21 @section Ordinary Differential Equations |
|
22 |
|
23 The function @code{lsode} can be used to solve ODEs of the form |
|
24 @iftex |
|
25 @tex |
|
26 $$ |
|
27 {dx\over dt} = f (x, t) |
|
28 $$ |
|
29 @end tex |
|
30 @end iftex |
|
31 @ifinfo |
|
32 |
|
33 @example |
|
34 dx |
|
35 -- = f (x, t) |
|
36 dt |
|
37 @end example |
|
38 @end ifinfo |
|
39 |
|
40 @noindent |
|
41 using Hindmarsh's ODE solver @sc{Lsode}. |
|
42 |
3373
|
43 @DOCSTRING(lsode) |
3294
|
44 |
4115
|
45 @DOCSTRING(lsode_options) |
|
46 |
3294
|
47 Here is an example of solving a set of three differential equations using |
|
48 @code{lsode}. Given the function |
|
49 |
|
50 @cindex oregonator |
|
51 |
|
52 @example |
|
53 @group |
|
54 function xdot = f (x, t) |
|
55 |
|
56 xdot = zeros (3,1); |
|
57 |
|
58 xdot(1) = 77.27 * (x(2) - x(1)*x(2) + x(1) \ |
|
59 - 8.375e-06*x(1)^2); |
|
60 xdot(2) = (x(3) - x(1)*x(2) - x(2)) / 77.27; |
|
61 xdot(3) = 0.161*(x(1) - x(3)); |
|
62 |
|
63 endfunction |
|
64 @end group |
|
65 @end example |
|
66 |
|
67 @noindent |
|
68 and the initial condition @code{x0 = [ 4; 1.1; 4 ]}, the set of |
|
69 equations can be integrated using the command |
|
70 |
|
71 @example |
|
72 @group |
|
73 t = linspace (0, 500, 1000); |
|
74 |
|
75 y = lsode ("f", x0, t); |
|
76 @end group |
|
77 @end example |
|
78 |
|
79 If you try this, you will see that the value of the result changes |
|
80 dramatically between @var{t} = 0 and 5, and again around @var{t} = 305. |
|
81 A more efficient set of output points might be |
|
82 |
|
83 @example |
|
84 @group |
|
85 t = [0, logspace (-1, log10(303), 150), \ |
|
86 logspace (log10(304), log10(500), 150)]; |
|
87 @end group |
|
88 @end example |
|
89 |
|
90 See Alan C. Hindmarsh, @cite{ODEPACK, A Systematized Collection of ODE |
|
91 Solvers}, in Scientific Computing, R. S. Stepleman, editor, (1983) for |
|
92 more information about the inner workings of @code{lsode}. |
|
93 |
4167
|
94 @node Differential-Algebraic Equations |
3294
|
95 @section Differential-Algebraic Equations |
|
96 |
4115
|
97 The function @code{daspk} can be used to solve DAEs of the form |
3294
|
98 @iftex |
|
99 @tex |
|
100 $$ |
|
101 0 = f (\dot{x}, x, t), \qquad x(t=0) = x_0, \dot{x}(t=0) = \dot{x}_0 |
|
102 $$ |
|
103 @end tex |
|
104 @end iftex |
|
105 @ifinfo |
|
106 |
|
107 @example |
|
108 0 = f (x-dot, x, t), x(t=0) = x_0, x-dot(t=0) = x-dot_0 |
|
109 @end example |
|
110 @end ifinfo |
|
111 |
|
112 @noindent |
4115
|
113 using Petzold's DAE solver @sc{Daspk}. |
|
114 |
|
115 @DOCSTRING(daspk) |
|
116 |
|
117 @DOCSTRING(daspk_options) |
3294
|
118 |
4115
|
119 Octave also includes @sc{Dassl}, an earlier version of @var{Daspk}, |
|
120 and @var{dasrt}, which can be used to solve DAEs with constraints |
|
121 (stopping conditions). |
3294
|
122 |
4115
|
123 @DOCSTRING(dasrt) |
|
124 |
|
125 @DOCSTRING(dasrt_options) |
3294
|
126 |
|
127 See K. E. Brenan, et al., @cite{Numerical Solution of Initial-Value |
|
128 Problems in Differential-Algebraic Equations}, North-Holland (1989) for |
|
129 more information about the implementation of @sc{Dassl}. |