annotate scripts/ode/ode23.m @ 20901:afe9c529760d

2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core * scripts/ode/ode23.m: new file * scripts/ode/private/runge_kutta_23.m: new file * scripts/ode/module.mk: list new files * doc/interpreter/diffeq.txi: mention ode23 among available solvers * scripts/help/__unimplemented__.m: remove ode23 from list of unimplemented functions
author Stefan Miereis <stefan.miereis@gmx.de>
date Tue, 15 Dec 2015 13:59:17 +0100
parents
children 73cf3434e8c9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
20901
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
1 ## Copyright (C) 2014-2015, Jacopo Corno <jacopo.corno@gmail.com>
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
2 ## Copyright (C) 2013-2015, Roberto Porcu' <roberto.porcu@polimi.it>
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
3 ## Copyright (C) 2006-2015, Thomas Treichl <treichl@users.sourceforge.net>
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
4 ##
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
5 ## This file is part of Octave.
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
6 ##
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
7 ## Octave is free software; you can redistribute it and/or modify it
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
8 ## under the terms of the GNU General Public License as published by
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
9 ## the Free Software Foundation; either version 3 of the License, or (at
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
10 ## your option) any later version.
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
11 ##
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
12 ## Octave is distributed in the hope that it will be useful, but
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
13 ## WITHOUT ANY WARRANTY; without even the implied warranty of
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
14 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
15 ## General Public License for more details.
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
16 ##
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
17 ## You should have received a copy of the GNU General Public License
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
18 ## along with Octave; see the file COPYING. If not, see
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
19 ## <http://www.gnu.org/licenses/>.
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
20
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
21 ## -*- texinfo -*-
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
22 ## @deftypefn {Function File} {[@var{t}, @var{y}] =} ode23 (@var{fun}, @var{trange}, @var{init})
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
23 ## @deftypefnx {Function File} {[@var{t}, @var{y}] =} ode23 (@var{fun}, @var{trange}, @var{init}, @var{ode_opt})
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
24 ## @deftypefnx {Function File} {[@var{t}, @var{y}] =} ode23 (@dots{}, @var{par1}, @var{par2}, @dots{})
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
25 ## @deftypefnx {Function File} {[@var{t}, @var{y}, @var{te}, @var{ye}, @var{ie}] =} ode23 (@dots{})
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
26 ## @deftypefnx {Function File} {@var{solution} =} ode23 (@dots{})
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
27 ##
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
28 ## Solve a set of non-stiff Ordinary Differential Equations (non-stiff ODEs)
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
29 ## with the well known explicit Bogacki-Shampine method of order 3. For the
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
30 ## definition of this method see
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
31 ## @url{http://en.wikipedia.org/wiki/List_of_Runge%E2%80%93Kutta_methods}.
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
32 ##
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
33 ## @var{fun} is a function handle, inline function, or string containing the
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
34 ## name of the function that defines the ODE: @code{y' = f(t,y)}. The function
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
35 ## must accept two inputs where the first is time @var{t} and the second is a
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
36 ## column vector of unknowns @var{y}.
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
37 ##
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
38 ## @var{trange} specifies the time interval over which the ODE will be
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
39 ## evaluated. Typically, it is a two-element vector specifying the initial and
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
40 ## final times (@code{[tinit, tfinal]}). If there are more than two elements
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
41 ## then the solution will also be evaluated at these intermediate time
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
42 ## instances unless the integrate function specified is
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
43 ## @command{integrate_n_steps}.
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
44 ##
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
45 ## By default, @code{ode23} uses an adaptive timestep with the
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
46 ## @code{integrate_adaptive} algorithm. The tolerance for the timestep
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
47 ## computation may be changed by using the option @qcode{"Tau"}, that has a
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
48 ## default value of @math{1e-6}. If the ODE option @qcode{"TimeStepSize"} is
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
49 ## not empty, then the stepper called will be @code{integrate_const}. If, in
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
50 ## addition, the option @qcode{"TimeStepNumber"} is also specified then the
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
51 ## integrate function @code{integrate_n_steps} will be used.
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
52 ##
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
53 ## @var{init} contains the initial value for the unknowns. If it is a row
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
54 ## vector then the solution @var{y} will be a matrix in which each column is
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
55 ## the solution for the corresponding initial value in @var{init}.
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
56 ##
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
57 ## The optional fourth argument @var{ode_opt} specifies non-default options to
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
58 ## the ODE solver. It is a structure generated by @code{odeset}.
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
59 ##
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
60 ## The function typically returns two outputs. Variable @var{t} is a
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
61 ## column vector and contains the times where the solution was found. The
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
62 ## output @var{y} is a matrix in which each column refers to a different
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
63 ## unknown of the problem and each row corresponds to a time in @var{t}.
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
64 ##
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
65 ## The output can also be returned as a structure @var{solution} which
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
66 ## has field @var{x} containing the time where the solution was evaluated and
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
67 ## field @var{y} containing the solution matrix for the times in @var{x}.
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
68 ## Use @code{fieldnames (@var{solution})} to see the other fields and additional
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
69 ## information returned.
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
70 ##
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
71 ## If using the @qcode{"Events"} option then three additional outputs may
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
72 ## be returned. @var{te} holds the time when an Event function returned a
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
73 ## zero. @var{ye} holds the value of the solution at time @var{te}. @var{ie}
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
74 ## contains an index indicating which Event function was triggered in the case
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
75 ## of multiple Event functions.
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
76 ##
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
77 ## This function can be called with two output arguments: @var{t} and @var{y}.
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
78 ## Variable @var{t} is a column vector and contains the time stamps, instead
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
79 ## @var{y} is a matrix in which each column refers to a different unknown of the
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
80 ## problem and the rows number is the same of @var{t} rows number so that each
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
81 ## row of @var{y} contains the values of all unknowns at the time value
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
82 ## contained in the corresponding row in @var{t}.
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
83 ##
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
84 ## Example: Solve the Van der Pol equation
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
85 ##
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
86 ## @example
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
87 ## @group
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
88 ## fvdp = @@(@var{t},@var{y}) [@var{y}(2); (1 - @var{y}(1)^2) * @var{y}(2) - @var{y}(1)];
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
89 ## [@var{t},@var{y}] = ode23 (fvdp, [0 20], [2 0]);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
90 ## @end group
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
91 ## @end example
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
92 ## @seealso{odeset, odeget}
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
93 ## @end deftypefn
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
94
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
95 ## ChangeLog:
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
96 ## 20010703 the function file "ode23.m" was written by Marc Compere
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
97 ## under the GPL for the use with this software. This function has been
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
98 ## taken as a base for the following implementation.
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
99 ## 20060810, Thomas Treichl
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
100 ## This function was adapted to the new syntax that is used by the
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
101 ## new OdePkg for Octave and is compatible to Matlab's ode23.
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
102
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
103 function varargout = ode23 (fun, trange, init, varargin)
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
104
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
105 if (nargin < 3)
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
106 print_usage ();
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
107 endif
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
108
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
109 order = 3;
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
110 solver = "ode23";
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
111
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
112 if (nargin >= 4)
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
113 if (! isstruct (varargin{1}))
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
114 ## varargin{1:len} are parameters for fun
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
115 odeopts = odeset ();
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
116 odeopts.funarguments = varargin;
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
117 elseif (length (varargin) > 1)
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
118 ## varargin{1} is an ODE options structure opt
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
119 odeopts = ode_struct_value_check ("ode23", varargin{1}, "ode23");
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
120 odeopts.funarguments = {varargin{2:length(varargin)}};
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
121 else # if (isstruct (varargin{1}))
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
122 odeopts = ode_struct_value_check ("ode23", varargin{1}, "ode23");
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
123 odeopts.funarguments = {};
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
124 endif
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
125 else # nargin == 3
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
126 odeopts = odeset ();
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
127 odeopts.funarguments = {};
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
128 endif
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
129
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
130 if (! isvector (trange) || ! isnumeric (trange))
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
131 error ("Octave:invalid-input-arg",
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
132 "ode23: TRANGE must be a numeric vector");
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
133 endif
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
134
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
135 TimeStepNumber = odeget (odeopts, "TimeStepNumber", [], "fast");
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
136 TimeStepSize = odeget (odeopts, "TimeStepSize", [], "fast");
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
137 if (length (trange) < 2
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
138 && (isempty (TimeStepSize) || isempty (TimeStepNumber)))
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
139 error ("Octave:invalid-input-arg",
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
140 "ode23: TRANGE must contain at least 2 elements");
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
141 elseif (trange(2) == trange(1))
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
142 error ("Octave:invalid-input-arg",
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
143 "ode23: invalid time span, TRANGE(1) == TRANGE(2)");
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
144 else
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
145 odeopts.direction = sign (trange(2) - trange(1));
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
146 endif
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
147 trange = trange(:);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
148
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
149 if (! isvector (init) || ! isnumeric (init))
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
150 error ("Octave:invalid-input-arg",
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
151 "ode23: INIT must be a numeric vector");
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
152 endif
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
153 init = init(:);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
154
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
155 if (ischar (fun))
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
156 try
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
157 fun = str2func (fun);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
158 catch
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
159 warning (lasterr);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
160 end_try_catch
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
161 endif
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
162 if (! isa (fun, "function_handle"))
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
163 error ("Octave:invalid-input-arg",
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
164 "ode23: FUN must be a valid function handle");
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
165 endif
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
166
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
167 ## Start preprocessing, have a look which options are set in odeopts,
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
168 ## check if an invalid or unused option is set
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
169 if (isempty (TimeStepNumber) && isempty (TimeStepSize))
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
170 integrate_func = "adaptive";
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
171 odeopts.stepsizefixed = false;
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
172 elseif (! isempty (TimeStepNumber) && ! isempty (TimeStepSize))
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
173 integrate_func = "n_steps";
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
174 odeopts.stepsizefixed = true;
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
175 if (sign (TimeStepSize) != odeopts.direction)
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
176 warning ("Octave:invalid-input-arg",
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
177 ["ode23: option \"TimeStepSize\" has the wrong sign, ", ...
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
178 "but will be corrected automatically\n"]);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
179 TimeStepSize = -TimeStepSize;
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
180 endif
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
181 elseif (isempty (TimeStepNumber) && ! isempty (TimeStepSize))
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
182 integrate_func = "const";
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
183 odeopts.stepsizefixed = true;
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
184 if (sign (TimeStepSize) != odeopts.direction)
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
185 warning ("Octave:invalid-input-arg",
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
186 ["ode23: option \"TimeStepSize\" has the wrong sign, ",
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
187 "but will be corrected automatically\n"]);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
188 TimeStepSize = -TimeStepSize;
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
189 endif
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
190 else
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
191 warning ("Octave:invalid-input-arg",
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
192 "ode23: assuming an adaptive integrate function\n");
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
193 integrate_func = "adaptive";
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
194 endif
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
195
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
196 if (isempty (odeopts.RelTol) && ! odeopts.stepsizefixed)
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
197 odeopts.RelTol = 1e-3;
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
198 warning ("Octave:invalid-input-arg",
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
199 "ode23: option \"RelTol\" not set, new value %f will be used\n",
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
200 odeopts.RelTol);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
201 elseif (! isempty (odeopts.RelTol) && odeopts.stepsizefixed)
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
202 warning ("Octave:invalid-input-arg",
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
203 ["ode23: option \"RelTol\" is ignored", ...
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
204 " when fixed time stamps are given\n"]);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
205 endif
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
206
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
207 if (isempty (odeopts.AbsTol) && ! odeopts.stepsizefixed)
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
208 odeopts.AbsTol = 1e-6;
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
209 warning ("Octave:invalid-input-arg",
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
210 "ode23: option \"AbsTol\" not set, new value %f will be used\n",
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
211 odeopts.AbsTol);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
212 elseif (! isempty (odeopts.AbsTol) && odeopts.stepsizefixed)
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
213 warning ("Octave:invalid-input-arg",
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
214 ["ode23: option \"AbsTol\" is ignored", ...
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
215 " when fixed time stamps are given\n"]);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
216 else
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
217 odeopts.AbsTol = odeopts.AbsTol(:); # Create column vector
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
218 endif
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
219
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
220 odeopts.normcontrol = strcmp (odeopts.NormControl, "on");
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
221
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
222 if (! isempty (odeopts.NonNegative))
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
223 if (isempty (odeopts.Mass))
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
224 odeopts.havenonnegative = true;
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
225 else
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
226 odeopts.havenonnegative = false;
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
227 warning ("Octave:invalid-input-arg",
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
228 ["ode23: option \"NonNegative\" is ignored", ...
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
229 " when mass matrix is set\n"]);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
230 endif
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
231 else
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
232 odeopts.havenonnegative = false;
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
233 endif
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
234
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
235 if (isempty (odeopts.OutputFcn) && nargout == 0)
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
236 odeopts.OutputFcn = @odeplot;
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
237 odeopts.haveoutputfunction = true;
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
238 else
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
239 odeopts.haveoutputfunction = ! isempty (odeopts.OutputFcn);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
240 endif
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
241
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
242 odeopts.haveoutputselection = ! isempty (odeopts.OutputSel);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
243
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
244 if (odeopts.Refine > 0)
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
245 odeopts.haverefine = true;
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
246 else
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
247 odeopts.haverefine = false;
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
248 endif
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
249
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
250 if (isempty (odeopts.InitialStep) && strcmp (integrate_func, "adaptive"))
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
251 odeopts.InitialStep = odeopts.direction* ...
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
252 starting_stepsize (order, fun, trange(1), init, odeopts.AbsTol,
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
253 odeopts.RelTol, odeopts.normcontrol);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
254 warning ("Octave:invalid-input-arg",
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
255 ["ode23: option \"InitialStep\" not set,", ...
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
256 " estimated value %f will be used\n"],
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
257 odeopts.InitialStep);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
258 elseif (isempty (odeopts.InitialStep))
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
259 odeopts.InitialStep = TimeStepSize;
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
260 endif
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
261
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
262 if (isempty (odeopts.MaxStep) && ! odeopts.stepsizefixed)
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
263 odeopts.MaxStep = abs (trange(end) - trange(1)) / 10;
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
264 warning ("Octave:invalid-input-arg",
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
265 "ode23: option \"MaxStep\" not set, new value %f will be used\n",
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
266 odeopts.MaxStep);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
267 endif
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
268
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
269 odeopts.haveeventfunction = ! isempty (odeopts.Events);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
270
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
271 ## The options 'Jacobian', 'JPattern' and 'Vectorized' will be ignored
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
272 ## by this solver because this solver uses an explicit Runge-Kutta method
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
273 ## and therefore no Jacobian calculation is necessary
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
274 if (! isempty (odeopts.Jacobian))
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
275 warning ("Octave:invalid-input-arg",
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
276 "ode23: option \"Jacobian\" is ignored by this solver\n");
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
277 endif
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
278
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
279 if (! isempty (odeopts.JPattern))
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
280 warning ("Octave:invalid-input-arg",
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
281 "ode23: option \"JPattern\" is ignored by this solver\n");
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
282 endif
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
283
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
284 if (! isempty (odeopts.Vectorized))
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
285 warning ("Octave:invalid-input-arg",
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
286 "ode23: option \"Vectorized\" is ignored by this solver\n");
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
287 endif
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
288
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
289 if (! isempty (odeopts.Mass) && isnumeric (odeopts.Mass))
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
290 havemasshandle = false;
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
291 mass = odeopts.Mass; # constant mass
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
292 elseif (isa (odeopts.Mass, "function_handle"))
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
293 havemasshandle = true; # mass defined by a function handle
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
294 else # no mass matrix - creating a diag-matrix of ones for mass
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
295 havemasshandle = false; # mass = diag (ones (length (init), 1), 0);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
296 endif
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
297
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
298 massdependence = ! strcmp (odeopts.MStateDependence, "none");
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
299
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
300 ## Other options that are not used by this solver.
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
301 if (! isempty (odeopts.MvPattern))
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
302 warning ("Octave:invalid-input-arg",
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
303 "ode23: option \"MvPattern\" is ignored by this solver\n");
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
304 endif
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
305
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
306 if (! isempty (odeopts.MassSingular))
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
307 warning ("Octave:invalid-input-arg",
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
308 "ode23: option \"MassSingular\" is ignored by this solver\n");
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
309 endif
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
310
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
311 if (! isempty (odeopts.InitialSlope))
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
312 warning ("Octave:invalid-input-arg",
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
313 "ode23: option \"InitialSlope\" is ignored by this solver\n");
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
314 endif
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
315
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
316 if (! isempty (odeopts.MaxOrder))
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
317 warning ("Octave:invalid-input-arg",
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
318 "ode23: option \"MaxOrder\" is ignored by this solver\n");
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
319 endif
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
320
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
321 if (! isempty (odeopts.BDF))
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
322 warning ("Octave:invalid-input-arg",
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
323 "ode23: option \"BDF\" is ignored by this solver\n");
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
324 endif
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
325
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
326 ## Starting the initialisation of the core solver ode23
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
327
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
328 if (havemasshandle) # Handle only the dynamic mass matrix,
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
329 if (massdependence) # constant mass matrices have already
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
330 mass = @(t,x) odeopts.Mass (t, x, odeopts.funarguments{:});
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
331 fun = @(t,x) mass (t, x, odeopts.funarguments{:}) ...
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
332 \ fun (t, x, odeopts.funarguments{:});
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
333 else # if (massdependence == false)
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
334 mass = @(t) odeopts.Mass (t, odeopts.funarguments{:});
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
335 fun = @(t,x) mass (t, odeopts.funarguments{:}) ...
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
336 \ fun (t, x, odeopts.funarguments{:});
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
337 endif
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
338 endif
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
339
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
340 switch (integrate_func)
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
341 case "adaptive"
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
342 solution = integrate_adaptive (@runge_kutta_23, ...
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
343 order, fun, trange, init, odeopts);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
344 case "n_steps"
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
345 solution = integrate_n_steps (@runge_kutta_23, ...
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
346 fun, trange(1), init, ...
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
347 TimeStepSize, TimeStepNumber, odeopts);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
348 case "const"
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
349 solution = integrate_const (@runge_kutta_23, ...
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
350 fun, trange, init, ...
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
351 TimeStepSize, odeopts);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
352 endswitch
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
353
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
354 ## Postprocessing, do whatever when terminating integration algorithm
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
355 if (odeopts.haveoutputfunction) # Cleanup plotter
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
356 feval (odeopts.OutputFcn, solution.t(end), ...
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
357 solution.x(end,:)', "done", odeopts.funarguments{:});
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
358 endif
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
359 if (odeopts.haveeventfunction) # Cleanup event function handling
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
360 ode_event_handler (odeopts.Events, solution.t(end), ...
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
361 solution.x(end,:)', "done", odeopts.funarguments{:});
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
362 endif
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
363
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
364 ## Print additional information if option Stats is set
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
365 if (strcmp (odeopts.Stats, "on"))
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
366 havestats = true;
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
367 nsteps = solution.cntloop-2; # cntloop from 2..end
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
368 nfailed = (solution.cntcycles-1)-nsteps+1; # cntcycl from 1..end
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
369 nfevals = 4 * (solution.cntcycles-1); # number of ode evaluations
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
370 ndecomps = 0; # number of LU decompositions
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
371 npds = 0; # number of partial derivatives
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
372 nlinsols = 0; # no. of solutions of linear systems
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
373 ## Print cost statistics if no output argument is given
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
374 if (nargout == 0)
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
375 printf ("Number of successful steps: %d\n", nsteps);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
376 printf ("Number of failed attempts: %d\n", nfailed);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
377 printf ("Number of function calls: %d\n", nfevals);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
378 endif
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
379 else
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
380 havestats = false;
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
381 endif
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
382
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
383 if (nargout == 2)
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
384 varargout{1} = solution.t; # Time stamps are first output argument
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
385 varargout{2} = solution.x; # Results are second output argument
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
386 elseif (nargout == 1)
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
387 varargout{1}.x = solution.t; # Time stamps are saved in field x
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
388 varargout{1}.y = solution.x; # Results are saved in field y
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
389 varargout{1}.solver = solver; # Solver name is saved in field solver
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
390 if (odeopts.haveeventfunction)
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
391 varargout{1}.ie = solution.event{2}; # Index info which event occurred
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
392 varargout{1}.xe = solution.event{3}; # Time info when an event occurred
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
393 varargout{1}.ye = solution.event{4}; # Results when an event occurred
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
394 endif
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
395 if (havestats)
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
396 varargout{1}.stats = struct ();
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
397 varargout{1}.stats.nsteps = nsteps;
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
398 varargout{1}.stats.nfailed = nfailed;
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
399 varargout{1}.stats.nfevals = nfevals;
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
400 varargout{1}.stats.npds = npds;
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
401 varargout{1}.stats.ndecomps = ndecomps;
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
402 varargout{1}.stats.nlinsols = nlinsols;
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
403 endif
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
404 elseif (nargout == 5)
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
405 varargout = cell (1,5);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
406 varargout{1} = solution.t;
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
407 varargout{2} = solution.x;
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
408 if (odeopts.haveeventfunction)
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
409 varargout{3} = solution.event{3}; # Time info when an event occurred
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
410 varargout{4} = solution.event{4}; # Results when an event occurred
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
411 varargout{5} = solution.event{2}; # Index info which event occurred
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
412 endif
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
413 endif
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
414
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
415 endfunction
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
416
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
417
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
418 ## We are using the "Van der Pol" implementation for all tests that are done
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
419 ## for this function.
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
420 ## For further tests we also define a reference solution (computed at high
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
421 ## accuracy)
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
422 %!function ydot = fpol (t, y) # The Van der Pol
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
423 %! ydot = [y(2); (1 - y(1)^2) * y(2) - y(1)];
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
424 %!endfunction
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
425 %!function ref = fref () # The computed reference sol
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
426 %! ref = [0.32331666704577, -1.83297456798624];
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
427 %!endfunction
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
428 %!function jac = fjac (t, y, varargin) # its Jacobian
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
429 %! jac = [0, 1; -1 - 2 * y(1) * y(2), 1 - y(1)^2];
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
430 %!endfunction
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
431 %!function jac = fjcc (t, y, varargin) # sparse type
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
432 %! jac = sparse ([0, 1; -1 - 2 * y(1) * y(2), 1 - y(1)^2])
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
433 %!endfunction
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
434 %!function [val, trm, dir] = feve (t, y, varargin)
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
435 %! val = fpol (t, y, varargin); # We use the derivatives
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
436 %! trm = zeros (2,1); # that's why component 2
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
437 %! dir = ones (2,1); # seems to not be exact
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
438 %!endfunction
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
439 %!function [val, trm, dir] = fevn (t, y, varargin)
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
440 %! val = fpol (t, y, varargin); # We use the derivatives
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
441 %! trm = ones (2,1); # that's why component 2
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
442 %! dir = ones (2,1); # seems to not be exact
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
443 %!endfunction
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
444 %!function mas = fmas (t, y, varargin)
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
445 %! mas = [1, 0; 0, 1]; # Dummy mass matrix for tests
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
446 %!endfunction
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
447 %!function mas = fmsa (t, y, varargin)
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
448 %! mas = sparse ([1, 0; 0, 1]); # A sparse dummy matrix
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
449 %!endfunction
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
450 %!function out = fout (t, y, flag, varargin)
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
451 %! if (regexp (char (flag), "init") == 1)
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
452 %! if (any (size (t) != [2, 1])) error ("\"fout\" step \"init\""); endif
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
453 %! elseif (isempty (flag))
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
454 %! if (any (size (t) != [1, 1])) error ("\"fout\" step \"calc\""); endif
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
455 %! out = false;
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
456 %! elseif (regexp (char (flag), "done") == 1)
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
457 %! if (any (size (t) != [1, 1])) error ("\"fout\" step \"done\""); endif
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
458 %! else
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
459 %! error ("\"fout\" invalid flag");
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
460 %! endif
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
461 %!endfunction
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
462 %!
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
463 %! ## Turn off output of warning messages for all tests,
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
464 %! ## turn them on again after the last test is called
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
465 %!test
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
466 %! warning ("off", "Octave:invalid-input-arg", "local");
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
467 %!error ## ouput argument
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
468 %! B = ode23 (1, [0 25], [3 15 1]);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
469 %!error ## input argument number one
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
470 %! [t, y] = ode23 (1, [0 25], [3 15 1]);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
471 %!error ## input argument number two
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
472 %! [t, y] = ode23 (@fpol, 1, [3 15 1]);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
473 %!test ## two output arguments
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
474 %! [t, y] = ode23 (@fpol, [0 2], [2 0]);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
475 %! assert ([t(end), y(end,:)], [2, fref], 1e-3);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
476 %!test ## anonymous function instead of real function
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
477 %! fvdb = @(t,y) [y(2); (1 - y(1)^2) * y(2) - y(1)];
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
478 %! [t, y] = ode23 (fvdb, [0 2], [2 0]);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
479 %! assert ([t(end), y(end,:)], [2, fref], 1e-3);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
480 %!test ## extra input arguments passed through
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
481 %! [t, y] = ode23 (@fpol, [0 2], [2 0], 12, 13, "KL");
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
482 %! assert ([t(end), y(end,:)], [2, fref], 1e-3);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
483 %!test ## empty OdePkg structure *but* extra input arguments
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
484 %! opt = odeset;
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
485 %! [t, y] = ode23 (@fpol, [0 2], [2 0], opt, 12, 13, "KL");
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
486 %! assert ([t(end), y(end,:)], [2, fref], 1e-2);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
487 %!error ## strange OdePkg structure
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
488 %! opt = struct ("foo", 1);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
489 %! [t, y] = ode23 (@fpol, [0 2], [2 0], opt);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
490 %!test ## Solve vdp in fixed step sizes
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
491 %! opt = odeset("TimeStepSize",0.1);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
492 %! [t, y] = ode23 (@fpol, [0,2], [2 0], opt);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
493 %! assert (t(:), [0:0.1:2]', 1e-3);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
494 %!test ## Solve another anonymous function below zero
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
495 %! ref = [0, 14.77810590694212];
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
496 %! [t, y] = ode23 (@(t,y) y, [-2 0], 2);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
497 %! assert ([t(end), y(end,:)], ref, 1e-2);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
498 %!test ## InitialStep option
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
499 %! opt = odeset ("InitialStep", 1e-8);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
500 %! [t, y] = ode23 (@fpol, [0 0.2], [2 0], opt);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
501 %! assert ([t(2)-t(1)], [1e-8], 1e-9);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
502 %!test ## MaxStep option
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
503 %! opt = odeset ("MaxStep", 1e-3);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
504 %! sol = ode23 (@fpol, [0 0.2], [2 0], opt);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
505 %! assert ([sol.x(5)-sol.x(4)], [1e-3], 1e-4);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
506 %!test ## Solve in backward direction starting at t=0
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
507 %! ref = [-1.205364552835178, 0.951542399860817];
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
508 %! sol = ode23 (@fpol, [0 -2], [2 0]);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
509 %! assert ([sol.x(end), sol.y(end,:)], [-2, ref], 5e-3);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
510 %!test ## Solve in backward direction starting at t=2
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
511 %! ref = [-1.205364552835178, 0.951542399860817];
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
512 %! sol = ode23 (@fpol, [2 0 -2], fref);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
513 %! assert ([sol.x(end), sol.y(end,:)], [-2, ref], 2e-2);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
514 %!test ## Solve another anonymous function in backward direction
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
515 %! ref = [-1, 0.367879437558975];
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
516 %! sol = ode23 (@(t,y) y, [0 -1], 1);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
517 %! assert ([sol.x(end), sol.y(end,:)], ref, 1e-2);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
518 %!test ## Solve another anonymous function below zero
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
519 %! ref = [0, 14.77810590694212];
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
520 %! sol = ode23 (@(t,y) y, [-2 0], 2);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
521 %! assert ([sol.x(end), sol.y(end,:)], ref, 1e-2);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
522 %!test ## Solve in backward direction starting at t=0 with MaxStep option
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
523 %! ref = [-1.205364552835178, 0.951542399860817];
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
524 %! opt = odeset ("MaxStep", 1e-3);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
525 %! sol = ode23 (@fpol, [0 -2], [2 0], opt);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
526 %! assert ([abs(sol.x(8)-sol.x(7))], [1e-3], 1e-3);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
527 %! assert ([sol.x(end), sol.y(end,:)], [-2, ref], 1e-3);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
528 %!test ## AbsTol option
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
529 %! opt = odeset ("AbsTol", 1e-5);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
530 %! sol = ode23 (@fpol, [0 2], [2 0], opt);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
531 %! assert ([sol.x(end), sol.y(end,:)], [2, fref], 1e-3);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
532 %!test ## AbsTol and RelTol option
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
533 %! opt = odeset ("AbsTol", 1e-8, "RelTol", 1e-8);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
534 %! sol = ode23 (@fpol, [0 2], [2 0], opt);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
535 %! assert ([sol.x(end), sol.y(end,:)], [2, fref], 1e-3);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
536 %!test ## RelTol and NormControl option -- higher accuracy
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
537 %! opt = odeset ("RelTol", 1e-8, "NormControl", "on");
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
538 %! sol = ode23 (@fpol, [0 2], [2 0], opt);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
539 %! assert ([sol.x(end), sol.y(end,:)], [2, fref], 1e-4);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
540 %!test ## Keeps initial values while integrating
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
541 %! opt = odeset ("NonNegative", 2);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
542 %! sol = ode23 (@fpol, [0 2], [2 0], opt);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
543 %! assert ([sol.x(end), sol.y(end,:)], [2, 2, 0], 1e-1);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
544 %!test ## Details of OutputSel and Refine can't be tested
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
545 %! opt = odeset ("OutputFcn", @fout, "OutputSel", 1, "Refine", 5);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
546 %! sol = ode23 (@fpol, [0 2], [2 0], opt);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
547 %!test ## Stats must add further elements in sol
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
548 %! opt = odeset ("Stats", "on");
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
549 %! sol = ode23 (@fpol, [0 2], [2 0], opt);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
550 %! assert (isfield (sol, "stats"));
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
551 %! assert (isfield (sol.stats, "nsteps"));
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
552 %!test ## Events option add further elements in sol
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
553 %! opt = odeset ("Events", @feve);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
554 %! sol = ode23 (@fpol, [0 10], [2 0], opt);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
555 %! assert (isfield (sol, "ie"));
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
556 %! assert (sol.ie(1), 2);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
557 %! assert (isfield (sol, "xe"));
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
558 %! assert (isfield (sol, "ye"));
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
559 %!test ## Events option, now stop integration
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
560 %! opt = odeset ("Events", @fevn, "NormControl", "on");
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
561 %! sol = ode23 (@fpol, [0 10], [2 0], opt);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
562 %! assert ([sol.ie, sol.xe, sol.ye], ...
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
563 %! [2.0, 2.496110, -0.830550, -2.677589], .5e-1);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
564 %!test ## Events option, five output arguments
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
565 %! opt = odeset ("Events", @fevn, "NormControl", "on");
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
566 %! [t, y, vxe, ye, vie] = ode23 (@fpol, [0 10], [2 0], opt);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
567 %! assert ([vie, vxe, ye], ...
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
568 %! [2.0, 2.496110, -0.830550, -2.677589], 1e-1);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
569 %!test ## Jacobian option
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
570 %! opt = odeset ("Jacobian", @fjac);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
571 %! sol = ode23 (@fpol, [0 2], [2 0], opt);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
572 %! assert ([sol.x(end), sol.y(end,:)], [2, fref], 1e-3);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
573 %!test ## Jacobian option and sparse return value
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
574 %! opt = odeset ("Jacobian", @fjcc);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
575 %! sol = ode23 (@fpol, [0 2], [2 0], opt);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
576 %! assert ([sol.x(end), sol.y(end,:)], [2, fref], 1e-3);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
577 %!
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
578 %! ## test for JPattern option is missing
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
579 %! ## test for Vectorized option is missing
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
580 %!
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
581 %!test ## Mass option as function
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
582 %! opt = odeset ("Mass", @fmas);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
583 %! sol = ode23 (@fpol, [0 2], [2 0], opt);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
584 %! assert ([sol.x(end), sol.y(end,:)], [2, fref], 1e-3);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
585 %!test ## Mass option as matrix
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
586 %! opt = odeset ("Mass", eye (2,2));
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
587 %! sol = ode23 (@fpol, [0 2], [2 0], opt);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
588 %! assert ([sol.x(end), sol.y(end,:)], [2, fref], 1e-3);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
589 %!test ## Mass option as sparse matrix
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
590 %! opt = odeset ("Mass", sparse (eye (2,2)));
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
591 %! sol = ode23 (@fpol, [0 2], [2 0], opt);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
592 %! assert ([sol.x(end), sol.y(end,:)], [2, fref], 1e-3);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
593 %!test ## Mass option as function and sparse matrix
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
594 %! opt = odeset ("Mass", @fmsa);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
595 %! sol = ode23 (@fpol, [0 2], [2 0], opt);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
596 %! assert ([sol.x(end), sol.y(end,:)], [2, fref], 1e-3);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
597 %!test ## Mass option as function and MStateDependence
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
598 %! opt = odeset ("Mass", @fmas, "MStateDependence", "strong");
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
599 %! sol = ode23 (@fpol, [0 2], [2 0], opt);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
600 %! assert ([sol.x(end), sol.y(end,:)], [2, fref], 1e-3);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
601 %!test ## Set BDF option to something else than default
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
602 %! opt = odeset ("BDF", "on");
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
603 %! [t, y] = ode23 (@fpol, [0 2], [2 0], opt);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
604 %! assert ([t(end), y(end,:)], [2, fref], 1e-3);
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
605 %!
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
606 %! ## test for MvPattern option is missing
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
607 %! ## test for InitialSlope option is missing
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
608 %! ## test for MaxOrder option is missing
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
609 %!
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
610 %! warning ("on", "Octave:InvalidArgument");
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
611
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
612 ## Local Variables: ***
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
613 ## mode: octave ***
afe9c529760d 2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff changeset
614 ## End: ***