1 @c -*- Mode: texinfo -*-
4 * Introduction to ODEPACK::
5 * Getting Started with ODEPACK::
6 * Functions and Variables for odepack::
9 @node Introduction to ODEPACK, Getting Started with ODEPACK, numericalio-pkg, odepack-pkg
10 @section Introduction to ODEPACK
13 ODEPACK is a collection of Fortran solvers for the initial value
14 problem for ordinary differential equation systems. It consists of nine
15 solvers, namely a basic solver called LSODE and eight variants of it --
16 LSODES, LSODA, LSODAR, LSODPK, LSODKR, LSODI, LSOIBT, and LSODIS.
17 The collection is suitable for both stiff and nonstiff systems. It
18 includes solvers for systems given in explicit form, dy/dt = f(t,y),
19 and also solvers for systems given in linearly implicit form,
20 A(t,y) dy/dt = g(t,y). Two of the solvers use general sparse matrix
21 solvers for the linear systems that arise. Two others use iterative
22 (preconditioned Krylov) methods instead of direct methods for these
23 linear systems. The most recent addition is LSODIS, which solves
24 implicit problems with general sparse treatment of all matrices involved.
26 @footnote{From @url{https://www.netlib.org/odepack/opkd-sum}}
29 [1] Fortran Code is from @url{https://www.netlib.org/odepack/}
31 @opencatbox{Categories:}
32 @category{Numerical methods}
33 @category{Share packages}
34 @category{Package odepack}
37 @node Getting Started with ODEPACK, Functions and Variables for odepack, Introduction to ODEPACK, odepack-pkg
38 @subsection Getting Started with ODEPACK
40 Of the eight variants of the solver, Maxima currently only has an
41 interface the @code{dlsode}.
43 Let's say we have this system of equations to solve:
45 f1 = -.04d0*y1 + 1d4*y2*y3
51 The independent variable is t; the dependent variables are y1, y2,
54 To start the solution, set up the differential equations to solved:
57 f1: -.04d0*y1 + 1d4*y2*y3$
63 Initialize the solver, where we have selected method 21
65 (%i6) state : dlsode_init(fex, ['t,y1,y2,y3], 21);
66 (%o6) [[f, #<Function "LAMBDA ($T $Y1 $Y2 $Y3)" @{49DAC061@}>],
67 [vars, [t, y1, y2, y3]], [mf, 21], [neq, 3], [lrw, 58], [liw, 23], [rwork, @{Li\
68 sp Array: #(0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
69 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
70 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
71 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0)@}],
72 [iwork, @{Lisp Array: #(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0)@}],
73 [fjac, #<Function "LAMBDA ($T $Y1 $Y2 $Y3)" @{49D52AC9@}>]]
75 The arrays rwork and iwork carry state between calls to
76 @mref{dlsode_step}, so they should not be modified by the user. In
77 fact, this state should not be modified by the user at all.
79 Now that the algorithm has been initialized we can compute solutions
80 to the differential equation, using the @var{state} returned above.
82 For this example, we want to compute the solution at times
83 @code{0.4*10^k} for k from 0 to 11, with the initial values of 1, 0, 0
84 for the dependent variables and with a relative tolerance of 1d-4 and
85 absolute tolerances of 1e-6, 1e-10, and 1d-6 for the dependent
93 atol: [1d-6, 1d-10, 1d-6];
100 result: dlsode_step(y, t, tout, rtol, atol, istate, state),
101 printf(true, "At t = ~12,4,2e y = ~@{~14,6,2e~@}~%", result[1], result[2]),
106 This produces the output:
108 At t = 4.0000e-01 y = 9.851726e-01 3.386406e-05 1.479357e-02
109 At t = 4.0000e+00 y = 9.055142e-01 2.240418e-05 9.446344e-02
110 At t = 4.0000e+01 y = 7.158050e-01 9.184616e-06 2.841858e-01
111 At t = 4.0000e+02 y = 4.504846e-01 3.222434e-06 5.495122e-01
112 At t = 4.0000e+03 y = 1.831701e-01 8.940379e-07 8.168290e-01
113 At t = 4.0000e+04 y = 3.897016e-02 1.621193e-07 9.610297e-01
114 At t = 4.0000e+05 y = 4.935213e-03 1.983756e-08 9.950648e-01
115 At t = 4.0000e+06 y = 5.159269e-04 2.064759e-09 9.994841e-01
116 At t = 4.0000e+07 y = 5.306413e-05 2.122677e-10 9.999469e-01
117 At t = 4.0000e+08 y = 5.494530e-06 2.197824e-11 9.999945e-01
118 At t = 4.0000e+09 y = 5.129458e-07 2.051784e-12 9.999995e-01
119 At t = 4.0000e+10 y = -7.170563e-08 -2.868225e-13 1.000000e+00
123 @node Functions and Variables for odepack, operatingsystem-pkg, Getting Started with ODEPACK, odepack-pkg
124 @section Functions and Variables for odepack
127 @deffn {Function} dlsode_init (@var{fex}, @var{vars}, @var{method})
129 This must be called before running the solver. This function returns
130 a state object for use in the solver. The user must not modify the
133 The ODE to be solved is given in @var{fex}, which is a list of the
134 equations. @var{vars} is a list of independent variable and the
135 dependent variables. The list of dependent variables must be in the
136 same order as the equations if @var{fex}. Finally, @var{method}
137 indicates the method to be used by the solver:
141 Nonstiff (Adams) method, no Jacobian used.
143 Stiff (BDF) method, user-supplied full Jacobian.
145 Stiff method, internally generated full Jacobian.
148 The returned state object is a list of lists. The sublist is a list
152 The compiled function for the ODE.
154 The list independent and dependent variables (@var{vars}).
156 The method to be used (@var{method}).
158 The number of equations.
160 Length of the work vector for real values.
162 Length of the work vector for integer values.
164 Lisp array holding the real-valued work vector.
166 Lisp array holding the integer-valued work vector.
168 Compiled analytical Jacobian of the equations
171 See also @mrefdot{dlsode_step}
176 @deffn {Function} dlsode_step (@var{inity}, @var{t}, @var{tout}, @var{rtol}, @var{atol}, @var{istate}, @var{state})
178 Performs one step of the solver, returning the values of the
179 independent and dependent variables, a success or error code.
183 For the first call (when istate = 1), the initial values
185 Current value of the independent value
187 Next point where output is desired which must not be equal to @var{t}.
189 relative tolerance parameter
191 Absolute tolerance parameter, scalar of vector. If
192 scalar, it applies to all dependent variables.
193 Otherwise it must be the tolerance for each dependent
196 Use @var{rtol} = 0 for pure absolute error and use @var{atol} = 0
197 for pure relative error.
200 1 for the first call to dlsode, 2 for subsequent calls.
202 state returned by dlsode_init.
205 The output is a list of the following items:
208 independent variable value
210 list of values of the dependent variables at time t.
215 no work because tout = tt
219 Excess work done on this call
221 Excess accuracy requested
223 Illegal input detected
225 Repeated error test failures
227 Repeated convergence failures (perhaps bad Jacobian or wrong choice of
230 Error weight because zero during problem (solution component is
231 vanished and atol(i) = 0.
234 association list of various bits of information:
237 total steps taken thus far
239 total number of function evals
241 total number of Jacobian evals
245 Actual length used for real work array
247 Actual length used for integer work array
251 See also @mrefdot{dlsode_init}