Mercurial > octave
annotate scripts/ode/ode23.m @ 22625:081a201b77c7 stable
Clean up ode options implementation to follow Octave coding standards.
* known_option_names.m: Delete file
* scripts/ode/module.mk: Remove known_option_names from build system.
* ode23.m, ode45.m: Fix typo in docstring. Correct indentation.
Remove trailing whitespace.
* AbsRel_Norm.m: Use default for input argument to simplify function.
Remove input validation for private, internal function.
* odedefaults.m: Add docstring. Use persistent variables for performance.
* odemergeopts.m: Fix indentation.
* starting_stepsize.m: Show input func as '@func' in docstring.
author | Carlo de Falco <carlo.defalco@polimi.it> |
---|---|
date | Sat, 15 Oct 2016 10:30:48 +0200 |
parents | 177e0c71bcc0 |
children | 869c02fde46c |
rev | line source |
---|---|
22625
081a201b77c7
Clean up ode options implementation to follow Octave coding standards.
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22605
diff
changeset
|
1 ## Copyright (C) 2016, Carlo de Falco |
22593
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
2 ## Copyright (C) 2016, Francesco Faccio <francesco.faccio@mail.polimi.it> |
22323
bac0d6f07a3e
maint: Update copyright notices for 2016.
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
3 ## Copyright (C) 2014-2016 Jacopo Corno <jacopo.corno@gmail.com> |
bac0d6f07a3e
maint: Update copyright notices for 2016.
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
4 ## Copyright (C) 2013-2016 Roberto Porcu' <roberto.porcu@polimi.it> |
bac0d6f07a3e
maint: Update copyright notices for 2016.
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
5 ## Copyright (C) 2006-2016 Thomas Treichl <treichl@users.sourceforge.net> |
20901
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 ## 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
|
8 ## |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
9 ## 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
|
10 ## 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
|
11 ## 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
|
12 ## 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
|
13 ## |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
14 ## 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
|
15 ## 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
|
16 ## 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
|
17 ## 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
|
18 ## |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
19 ## 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
|
20 ## 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
|
21 ## <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
|
22 |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
23 ## -*- texinfo -*- |
21319
8880d93010d8
Remove further uses of CLASS field in @deftypefn macro.
Rik <rik@octave.org>
parents:
21123
diff
changeset
|
24 ## @deftypefn {} {[@var{t}, @var{y}] =} ode23 (@var{fun}, @var{trange}, @var{init}) |
8880d93010d8
Remove further uses of CLASS field in @deftypefn macro.
Rik <rik@octave.org>
parents:
21123
diff
changeset
|
25 ## @deftypefnx {} {[@var{t}, @var{y}] =} ode23 (@var{fun}, @var{trange}, @var{init}, @var{ode_opt}) |
8880d93010d8
Remove further uses of CLASS field in @deftypefn macro.
Rik <rik@octave.org>
parents:
21123
diff
changeset
|
26 ## @deftypefnx {} {[@var{t}, @var{y}, @var{te}, @var{ye}, @var{ie}] =} ode23 (@dots{}) |
8880d93010d8
Remove further uses of CLASS field in @deftypefn macro.
Rik <rik@octave.org>
parents:
21123
diff
changeset
|
27 ## @deftypefnx {} {@var{solution} =} ode23 (@dots{}) |
20901
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
28 ## |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
29 ## Solve a set of non-stiff Ordinary Differential Equations (non-stiff ODEs) |
21123
71408ab5071e
doc: Periodic spellcheck of documentation.
Rik <rik@octave.org>
parents:
20928
diff
changeset
|
30 ## with the well known explicit @nospell{Bogacki-Shampine} method of order 3. |
71408ab5071e
doc: Periodic spellcheck of documentation.
Rik <rik@octave.org>
parents:
20928
diff
changeset
|
31 ## For the definition of this method see |
20901
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
32 ## @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
|
33 ## |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
34 ## @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
|
35 ## 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
|
36 ## 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
|
37 ## 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
|
38 ## |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
39 ## @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
|
40 ## 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
|
41 ## 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
|
42 ## then the solution will also be evaluated at these intermediate time |
22594
b8d525710075
cleanup ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22593
diff
changeset
|
43 ## instances. |
20901
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 |
22625
081a201b77c7
Clean up ode options implementation to follow Octave coding standards.
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22605
diff
changeset
|
47 ## computation may be changed by using the options @qcode{"RelTol"} |
081a201b77c7
Clean up ode options implementation to follow Octave coding standards.
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22605
diff
changeset
|
48 ## and @qcode{"AbsTol"}. |
20901
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
49 ## |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
50 ## @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
|
51 ## 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
|
52 ## 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
|
53 ## |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
54 ## 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
|
55 ## 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
|
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 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
|
58 ## 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
|
59 ## 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
|
60 ## 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
|
61 ## |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
62 ## 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
|
63 ## 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
|
64 ## field @var{y} containing the solution matrix for the times in @var{x}. |
21546
f7f97d7e9294
doc: Wrap m-file docstrings to 79 characters + newline (80 total).
Rik <rik@octave.org>
parents:
21443
diff
changeset
|
65 ## Use @code{fieldnames (@var{solution})} to see the other fields and |
f7f97d7e9294
doc: Wrap m-file docstrings to 79 characters + newline (80 total).
Rik <rik@octave.org>
parents:
21443
diff
changeset
|
66 ## additional information returned. |
20901
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
67 ## |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
68 ## 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
|
69 ## 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
|
70 ## 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
|
71 ## 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
|
72 ## 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
|
73 ## |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
74 ## 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
|
75 ## Variable @var{t} is a column vector and contains the time stamps, instead |
21546
f7f97d7e9294
doc: Wrap m-file docstrings to 79 characters + newline (80 total).
Rik <rik@octave.org>
parents:
21443
diff
changeset
|
76 ## @var{y} is a matrix in which each column refers to a different unknown of |
f7f97d7e9294
doc: Wrap m-file docstrings to 79 characters + newline (80 total).
Rik <rik@octave.org>
parents:
21443
diff
changeset
|
77 ## the problem and the rows number is the same of @var{t} rows number so |
f7f97d7e9294
doc: Wrap m-file docstrings to 79 characters + newline (80 total).
Rik <rik@octave.org>
parents:
21443
diff
changeset
|
78 ## that each row of @var{y} contains the values of all unknowns at the time |
f7f97d7e9294
doc: Wrap m-file docstrings to 79 characters + newline (80 total).
Rik <rik@octave.org>
parents:
21443
diff
changeset
|
79 ## value contained in the corresponding row in @var{t}. |
20901
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
80 ## |
21123
71408ab5071e
doc: Periodic spellcheck of documentation.
Rik <rik@octave.org>
parents:
20928
diff
changeset
|
81 ## Example: Solve the @nospell{Van der Pol} equation |
20901
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
82 ## |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
83 ## @example |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
84 ## @group |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
85 ## fvdp = @@(@var{t},@var{y}) [@var{y}(2); (1 - @var{y}(1)^2) * @var{y}(2) - @var{y}(1)]; |
21443
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
86 ## [@var{t},@var{y}] = ode23 (fvdp, [0, 20], [2, 0]); |
20901
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
87 ## @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
|
88 ## @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
|
89 ## @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
|
90 ## @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
|
91 |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
92 ## ChangeLog: |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
93 ## 20010703 the function file "ode23.m" was written by Marc Compere |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21634
diff
changeset
|
94 ## under the GPL for the use with this software. This function has been |
20901
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
95 ## 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
|
96 ## 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
|
97 ## 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
|
98 ## 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
|
99 |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
100 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
|
101 |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
102 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
|
103 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
|
104 endif |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
105 |
22593
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
106 order = 3; |
20901
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
107 solver = "ode23"; |
20928
2b8447888e0a
strip trailing whitespace from files
John W. Eaton <jwe@octave.org>
parents:
20908
diff
changeset
|
108 |
20901
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
109 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
|
110 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
|
111 ## 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
|
112 odeopts = odeset (); |
22593
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
113 funarguments = varargin; |
20901
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
114 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
|
115 ## varargin{1} is an ODE options structure opt |
22593
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
116 odeopts = varargin{1}; |
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
117 funarguments = {varargin{2:length(varargin)}}; |
20901
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
118 else # if (isstruct (varargin{1})) |
22593
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
119 odeopts = varargin{1}; |
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
120 funarguments = {}; |
20901
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
121 endif |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
122 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
|
123 odeopts = odeset (); |
22593
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
124 funarguments = {}; |
20901
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
125 endif |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
126 |
21443
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
127 if (! isnumeric (trange) || ! isvector (trange)) |
20901
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
128 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
|
129 "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
|
130 endif |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
131 |
22593
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
132 if (length (trange) < 2) |
20901
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
133 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
|
134 "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
|
135 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
|
136 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
|
137 "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
|
138 else |
22593
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
139 direction = sign (trange(2) - trange(1)); |
20901
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
140 endif |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
141 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
|
142 |
21443
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
143 if (! isnumeric (init) || ! isvector (init)) |
20901
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
144 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
|
145 "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
|
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 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
|
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 (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
|
150 try |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
151 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
|
152 catch |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
153 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
|
154 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
|
155 endif |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
156 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
|
157 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
|
158 "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
|
159 endif |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
160 |
22593
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
161 |
20901
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
162 ## 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
|
163 ## check if an invalid or unused option is set |
22593
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
164 |
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
165 |
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
166 persistent defaults = []; |
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
167 persistent classes = []; |
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
168 persistent attributes = []; |
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
169 |
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
170 |
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
171 [defaults, classes, attributes] = odedefaults (numel (init), trange(1), |
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
172 trange(end)); |
20901
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
173 |
22593
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
174 defaults = rmfield (defaults, {"Jacobian", "JPattern", "Vectorized", ... |
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
175 "MvPattern", "MassSingular", ... |
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
176 "InitialSlope", "MaxOrder", "BDF"}); |
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
177 classes = rmfield (classes, {"Jacobian", "JPattern", "Vectorized", ... |
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
178 "MvPattern", "MassSingular", ... |
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
179 "InitialSlope", "MaxOrder", "BDF"}); |
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
180 attributes = rmfield (attributes, {"Jacobian", "JPattern", "Vectorized", ... |
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
181 "MvPattern", "MassSingular", ... |
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
182 "InitialSlope", "MaxOrder", "BDF"}); |
20901
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
183 |
22593
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
184 odeopts = odemergeopts (odeopts, defaults, classes, attributes, 'ode23'); |
20901
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
185 |
22593
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
186 odeopts.funarguments = funarguments; |
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
187 odeopts.direction = direction; |
20901
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
188 |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
189 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
|
190 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
|
191 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
|
192 else |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
193 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
|
194 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
|
195 ["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
|
196 " 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
|
197 endif |
20928
2b8447888e0a
strip trailing whitespace from files
John W. Eaton <jwe@octave.org>
parents:
20908
diff
changeset
|
198 else |
20901
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
199 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
|
200 endif |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
201 |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
202 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
|
203 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
|
204 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
|
205 else |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
206 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
|
207 endif |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
208 |
22593
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
209 if (isempty (odeopts.InitialStep)) |
20908
0fb9de5b7903
remove verbose warnings from ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
20902
diff
changeset
|
210 odeopts.InitialStep = odeopts.direction * ... |
0fb9de5b7903
remove verbose warnings from ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
20902
diff
changeset
|
211 starting_stepsize (order, fun, trange(1), |
0fb9de5b7903
remove verbose warnings from ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
20902
diff
changeset
|
212 init, odeopts.AbsTol, |
0fb9de5b7903
remove verbose warnings from ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
20902
diff
changeset
|
213 odeopts.RelTol, |
22593
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
214 strcmp (odeopts.NormControl, |
22625
081a201b77c7
Clean up ode options implementation to follow Octave coding standards.
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22605
diff
changeset
|
215 "on"), odeopts.funarguments); |
20901
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
216 endif |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
217 |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
218 |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
219 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
|
220 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
|
221 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
|
222 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
|
223 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
|
224 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
|
225 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
|
226 endif |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
227 |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
228 |
21443
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
229 ## Starting the initialization of the core solver ode23 |
20928
2b8447888e0a
strip trailing whitespace from files
John W. Eaton <jwe@octave.org>
parents:
20908
diff
changeset
|
230 |
20901
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
231 if (havemasshandle) # Handle only the dynamic mass matrix, |
22593
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
232 if (! strcmp (odeopts.MStateDependence, "none")) # constant mass matrices have already |
20901
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
233 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
|
234 fun = @(t,x) mass (t, x, odeopts.funarguments{:}) ... |
22625
081a201b77c7
Clean up ode options implementation to follow Octave coding standards.
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22605
diff
changeset
|
235 \ fun (t, x, odeopts.funarguments{:}); |
22593
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
236 else # if ((! strcmp (odeopts.MStateDependence, "none")) == false) |
20901
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
237 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
|
238 fun = @(t,x) mass (t, odeopts.funarguments{:}) ... |
22625
081a201b77c7
Clean up ode options implementation to follow Octave coding standards.
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22605
diff
changeset
|
239 \ fun (t, x, odeopts.funarguments{:}); |
20901
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 endif |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
242 |
22625
081a201b77c7
Clean up ode options implementation to follow Octave coding standards.
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22605
diff
changeset
|
243 |
22593
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
244 solution = integrate_adaptive (@runge_kutta_23, ... |
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
245 order, fun, trange, init, odeopts); |
22625
081a201b77c7
Clean up ode options implementation to follow Octave coding standards.
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22605
diff
changeset
|
246 |
20901
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
247 |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
248 ## 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
|
249 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
|
250 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
|
251 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
|
252 endif |
22593
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
253 if (! isempty (odeopts.Events)) # Cleanup event function handling |
20901
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
254 ode_event_handler (odeopts.Events, solution.t(end), ... |
22593
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
255 solution.x(end,:)', "done", odeopts.funarguments{:}); |
20901
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
256 endif |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
257 |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
258 ## 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
|
259 if (strcmp (odeopts.Stats, "on")) |
21955
0f3e875d9078
Fix statistics on solution solving for ode45, ode23 (bug #48243).
jcorno <jacopo.corno@gmail.com>
parents:
21751
diff
changeset
|
260 nsteps = solution.cntloop; # cntloop from 2..end |
0f3e875d9078
Fix statistics on solution solving for ode45, ode23 (bug #48243).
jcorno <jacopo.corno@gmail.com>
parents:
21751
diff
changeset
|
261 nfailed = solution.cntcycles - nsteps; # cntcycl from 1..end |
0f3e875d9078
Fix statistics on solution solving for ode45, ode23 (bug #48243).
jcorno <jacopo.corno@gmail.com>
parents:
21751
diff
changeset
|
262 nfevals = 3 * solution.cntcycles + 1; # number of ode evaluations |
21443
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
263 ndecomps = 0; # number of LU decompositions |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
264 npds = 0; # number of partial derivatives |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
265 nlinsols = 0; # no. of solutions of linear systems |
20901
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
266 ## 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
|
267 if (nargout == 0) |
21634
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
268 printf ("Number of successful steps: %d\n", nsteps); |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
269 printf ("Number of failed attempts: %d\n", nfailed); |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
270 printf ("Number of function calls: %d\n", nfevals); |
20901
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
271 endif |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
272 endif |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
273 |
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 (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
|
275 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
|
276 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
|
277 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
|
278 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
|
279 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
|
280 varargout{1}.solver = solver; # Solver name is saved in field solver |
22593
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
281 if (! isempty (odeopts.Events)) |
20901
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
282 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
|
283 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
|
284 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
|
285 endif |
22593
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
286 if (strcmp (odeopts.Stats, "on")) |
20901
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
287 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
|
288 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
|
289 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
|
290 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
|
291 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
|
292 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
|
293 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
|
294 endif |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
295 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
|
296 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
|
297 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
|
298 varargout{2} = solution.x; |
22593
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
299 if (! isempty (odeopts.Events)) |
20901
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
300 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
|
301 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
|
302 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
|
303 endif |
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 endfunction |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
307 |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
308 |
21599
f29d68e24c5a
ode23.m, ode45.m: More reformatting of demos to Octave coding standards.
Rik <rik@octave.org>
parents:
21596
diff
changeset
|
309 %!demo |
f29d68e24c5a
ode23.m, ode45.m: More reformatting of demos to Octave coding standards.
Rik <rik@octave.org>
parents:
21596
diff
changeset
|
310 %! |
f29d68e24c5a
ode23.m, ode45.m: More reformatting of demos to Octave coding standards.
Rik <rik@octave.org>
parents:
21596
diff
changeset
|
311 %! ## Demonstrate convergence order for ode23 |
f29d68e24c5a
ode23.m, ode45.m: More reformatting of demos to Octave coding standards.
Rik <rik@octave.org>
parents:
21596
diff
changeset
|
312 %! tol = 1e-5 ./ 10.^[0:8]; |
f29d68e24c5a
ode23.m, ode45.m: More reformatting of demos to Octave coding standards.
Rik <rik@octave.org>
parents:
21596
diff
changeset
|
313 %! for i = 1 : numel (tol) |
f29d68e24c5a
ode23.m, ode45.m: More reformatting of demos to Octave coding standards.
Rik <rik@octave.org>
parents:
21596
diff
changeset
|
314 %! opt = odeset ("RelTol", tol(i), "AbsTol", realmin); |
f29d68e24c5a
ode23.m, ode45.m: More reformatting of demos to Octave coding standards.
Rik <rik@octave.org>
parents:
21596
diff
changeset
|
315 %! [t, y] = ode23 (@(t, y) -y, [0, 1], 1, opt); |
f29d68e24c5a
ode23.m, ode45.m: More reformatting of demos to Octave coding standards.
Rik <rik@octave.org>
parents:
21596
diff
changeset
|
316 %! h(i) = 1 / (numel (t) - 1); |
f29d68e24c5a
ode23.m, ode45.m: More reformatting of demos to Octave coding standards.
Rik <rik@octave.org>
parents:
21596
diff
changeset
|
317 %! err(i) = norm (y .* exp (t) - 1, Inf); |
f29d68e24c5a
ode23.m, ode45.m: More reformatting of demos to Octave coding standards.
Rik <rik@octave.org>
parents:
21596
diff
changeset
|
318 %! endfor |
f29d68e24c5a
ode23.m, ode45.m: More reformatting of demos to Octave coding standards.
Rik <rik@octave.org>
parents:
21596
diff
changeset
|
319 %! |
f29d68e24c5a
ode23.m, ode45.m: More reformatting of demos to Octave coding standards.
Rik <rik@octave.org>
parents:
21596
diff
changeset
|
320 %! ## Estimate order numerically |
f29d68e24c5a
ode23.m, ode45.m: More reformatting of demos to Octave coding standards.
Rik <rik@octave.org>
parents:
21596
diff
changeset
|
321 %! p = diff (log (err)) ./ diff (log (h)) |
f29d68e24c5a
ode23.m, ode45.m: More reformatting of demos to Octave coding standards.
Rik <rik@octave.org>
parents:
21596
diff
changeset
|
322 %! |
f29d68e24c5a
ode23.m, ode45.m: More reformatting of demos to Octave coding standards.
Rik <rik@octave.org>
parents:
21596
diff
changeset
|
323 %! ## Estimate order visually |
f29d68e24c5a
ode23.m, ode45.m: More reformatting of demos to Octave coding standards.
Rik <rik@octave.org>
parents:
21596
diff
changeset
|
324 %! loglog (h, tol, "-ob", |
f29d68e24c5a
ode23.m, ode45.m: More reformatting of demos to Octave coding standards.
Rik <rik@octave.org>
parents:
21596
diff
changeset
|
325 %! h, err, "-b", |
f29d68e24c5a
ode23.m, ode45.m: More reformatting of demos to Octave coding standards.
Rik <rik@octave.org>
parents:
21596
diff
changeset
|
326 %! h, (h/h(end)) .^ 2 .* tol(end), "k--", |
f29d68e24c5a
ode23.m, ode45.m: More reformatting of demos to Octave coding standards.
Rik <rik@octave.org>
parents:
21596
diff
changeset
|
327 %! h, (h/h(end)) .^ 3 .* tol(end), "k-"); |
f29d68e24c5a
ode23.m, ode45.m: More reformatting of demos to Octave coding standards.
Rik <rik@octave.org>
parents:
21596
diff
changeset
|
328 %! axis tight |
f29d68e24c5a
ode23.m, ode45.m: More reformatting of demos to Octave coding standards.
Rik <rik@octave.org>
parents:
21596
diff
changeset
|
329 %! xlabel ("h"); |
f29d68e24c5a
ode23.m, ode45.m: More reformatting of demos to Octave coding standards.
Rik <rik@octave.org>
parents:
21596
diff
changeset
|
330 %! ylabel ("err(h)"); |
f29d68e24c5a
ode23.m, ode45.m: More reformatting of demos to Octave coding standards.
Rik <rik@octave.org>
parents:
21596
diff
changeset
|
331 %! title ("Convergence plot for ode23"); |
f29d68e24c5a
ode23.m, ode45.m: More reformatting of demos to Octave coding standards.
Rik <rik@octave.org>
parents:
21596
diff
changeset
|
332 %! legend ("imposed tolerance", "ode23 (relative) error", |
f29d68e24c5a
ode23.m, ode45.m: More reformatting of demos to Octave coding standards.
Rik <rik@octave.org>
parents:
21596
diff
changeset
|
333 %! "order 2", "order 3", "location", "northwest"); |
f29d68e24c5a
ode23.m, ode45.m: More reformatting of demos to Octave coding standards.
Rik <rik@octave.org>
parents:
21596
diff
changeset
|
334 |
20901
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
335 ## 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
|
336 ## 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
|
337 ## 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
|
338 ## accuracy) |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
339 %!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
|
340 %! 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
|
341 %!endfunction |
21443
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
342 %!function ref = fref () # The computed reference sol |
20901
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
343 %! 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
|
344 %!endfunction |
21443
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
345 %!function jac = fjac (t, y, varargin) # its Jacobian |
20901
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
346 %! 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
|
347 %!endfunction |
21443
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
348 %!function jac = fjcc (t, y, varargin) # sparse type |
21580
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21546
diff
changeset
|
349 %! jac = sparse ([0, 1; -1 - 2 * y(1) * y(2), 1 - y(1)^2]); |
20901
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
350 %!endfunction |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
351 %!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
|
352 %! 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
|
353 %! 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
|
354 %! 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
|
355 %!endfunction |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
356 %!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
|
357 %! 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
|
358 %! 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
|
359 %! 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
|
360 %!endfunction |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
361 %!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
|
362 %! 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
|
363 %!endfunction |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
364 %!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
|
365 %! 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
|
366 %!endfunction |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
367 %!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
|
368 %! 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
|
369 %! 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
|
370 %! 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
|
371 %! 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
|
372 %! 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
|
373 %! 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
|
374 %! 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
|
375 %! else |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
376 %! 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
|
377 %! endif |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
378 %!endfunction |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
379 %! |
21443
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
380 %!test # two output arguments |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
381 %! [t, y] = ode23 (@fpol, [0 2], [2 0]); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
382 %! assert ([t(end), y(end,:)], [2, fref], 1e-3); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
383 %!test # anonymous function instead of real function |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
384 %! fvdb = @(t,y) [y(2); (1 - y(1)^2) * y(2) - y(1)]; |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
385 %! [t, y] = ode23 (fvdb, [0 2], [2 0]); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
386 %! assert ([t(end), y(end,:)], [2, fref], 1e-3); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
387 %!test # extra input arguments passed through |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
388 %! [t, y] = ode23 (@fpol, [0 2], [2 0], 12, 13, "KL"); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
389 %! assert ([t(end), y(end,:)], [2, fref], 1e-3); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
390 %!test # empty OdePkg structure *but* extra input arguments |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
391 %! opt = odeset; |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
392 %! [t, y] = ode23 (@fpol, [0 2], [2 0], opt, 12, 13, "KL"); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
393 %! assert ([t(end), y(end,:)], [2, fref], 1e-2); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
394 %!test # Solve another anonymous function below zero |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
395 %! ref = [0, 14.77810590694212]; |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
396 %! [t, y] = ode23 (@(t,y) y, [-2 0], 2); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
397 %! assert ([t(end), y(end,:)], ref, 1e-2); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
398 %!test # InitialStep option |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
399 %! opt = odeset ("InitialStep", 1e-8); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
400 %! [t, y] = ode23 (@fpol, [0 0.2], [2 0], opt); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
401 %! assert ([t(2)-t(1)], [1e-8], 1e-9); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
402 %!test # MaxStep option |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
403 %! opt = odeset ("MaxStep", 1e-3); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
404 %! sol = ode23 (@fpol, [0 0.2], [2 0], opt); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
405 %! assert ([sol.x(5)-sol.x(4)], [1e-3], 1e-4); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
406 %!test # Solve in backward direction starting at t=0 |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
407 %! ref = [-1.205364552835178, 0.951542399860817]; |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
408 %! sol = ode23 (@fpol, [0 -2], [2 0]); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
409 %! assert ([sol.x(end), sol.y(end,:)], [-2, ref], 5e-3); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
410 %!test # Solve in backward direction starting at t=2 |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
411 %! ref = [-1.205364552835178, 0.951542399860817]; |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
412 %! sol = ode23 (@fpol, [2 0 -2], fref); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
413 %! assert ([sol.x(end), sol.y(end,:)], [-2, ref], 2e-2); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
414 %!test # Solve another anonymous function in backward direction |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
415 %! ref = [-1, 0.367879437558975]; |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
416 %! sol = ode23 (@(t,y) y, [0 -1], 1); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
417 %! assert ([sol.x(end), sol.y(end,:)], ref, 1e-2); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
418 %!test # Solve another anonymous function below zero |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
419 %! ref = [0, 14.77810590694212]; |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
420 %! sol = ode23 (@(t,y) y, [-2 0], 2); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
421 %! assert ([sol.x(end), sol.y(end,:)], ref, 1e-2); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
422 %!test # Solve in backward direction starting at t=0 with MaxStep option |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
423 %! ref = [-1.205364552835178, 0.951542399860817]; |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
424 %! opt = odeset ("MaxStep", 1e-3); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
425 %! sol = ode23 (@fpol, [0 -2], [2 0], opt); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
426 %! assert ([abs(sol.x(8)-sol.x(7))], [1e-3], 1e-3); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
427 %! assert ([sol.x(end), sol.y(end,:)], [-2, ref], 1e-3); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
428 %!test # AbsTol option |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
429 %! opt = odeset ("AbsTol", 1e-5); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
430 %! sol = ode23 (@fpol, [0 2], [2 0], opt); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
431 %! assert ([sol.x(end), sol.y(end,:)], [2, fref], 1e-3); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
432 %!test # AbsTol and RelTol option |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
433 %! opt = odeset ("AbsTol", 1e-8, "RelTol", 1e-8); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
434 %! sol = ode23 (@fpol, [0 2], [2 0], opt); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
435 %! assert ([sol.x(end), sol.y(end,:)], [2, fref], 1e-3); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
436 %!test # RelTol and NormControl option -- higher accuracy |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
437 %! opt = odeset ("RelTol", 1e-8, "NormControl", "on"); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
438 %! sol = ode23 (@fpol, [0 2], [2 0], opt); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
439 %! assert ([sol.x(end), sol.y(end,:)], [2, fref], 1e-4); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
440 %!test # Keeps initial values while integrating |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
441 %! opt = odeset ("NonNegative", 2); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
442 %! sol = ode23 (@fpol, [0 2], [2 0], opt); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
443 %! assert ([sol.x(end), sol.y(end,:)], [2, 2, 0], 1e-1); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
444 %!test # Details of OutputSel and Refine can't be tested |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
445 %! opt = odeset ("OutputFcn", @fout, "OutputSel", 1, "Refine", 5); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
446 %! sol = ode23 (@fpol, [0 2], [2 0], opt); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
447 %!test # Stats must add further elements in sol |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
448 %! opt = odeset ("Stats", "on"); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
449 %! sol = ode23 (@fpol, [0 2], [2 0], opt); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
450 %! assert (isfield (sol, "stats")); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
451 %! assert (isfield (sol.stats, "nsteps")); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
452 %!test # Events option add further elements in sol |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
453 %! opt = odeset ("Events", @feve); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
454 %! sol = ode23 (@fpol, [0 10], [2 0], opt); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
455 %! assert (isfield (sol, "ie")); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
456 %! assert (sol.ie(1), 2); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
457 %! assert (isfield (sol, "xe")); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
458 %! assert (isfield (sol, "ye")); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
459 %!test # Events option, now stop integration |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
460 %! warning ("off", "integrate_adaptive:unexpected_termination", "local"); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
461 %! opt = odeset ("Events", @fevn, "NormControl", "on"); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
462 %! sol = ode23 (@fpol, [0 10], [2 0], opt); |
21580
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21546
diff
changeset
|
463 %! assert ([sol.ie, sol.xe, sol.ye], |
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21546
diff
changeset
|
464 %! [2.0, 2.496110, -0.830550, -2.677589], .5e-1); |
21443
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
465 %!test # Events option, five output arguments |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
466 %! warning ("off", "integrate_adaptive:unexpected_termination", "local"); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
467 %! opt = odeset ("Events", @fevn, "NormControl", "on"); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
468 %! [t, y, vxe, ye, vie] = ode23 (@fpol, [0 10], [2 0], opt); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
469 %! assert ([vie, vxe, ye], [2.0, 2.496110, -0.830550, -2.677589], 1e-1); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
470 %!test # Mass option as function |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
471 %! opt = odeset ("Mass", @fmas); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
472 %! sol = ode23 (@fpol, [0 2], [2 0], opt); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
473 %! assert ([sol.x(end), sol.y(end,:)], [2, fref], 1e-3); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
474 %!test # Mass option as matrix |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
475 %! opt = odeset ("Mass", eye (2,2)); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
476 %! sol = ode23 (@fpol, [0 2], [2 0], opt); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
477 %! assert ([sol.x(end), sol.y(end,:)], [2, fref], 1e-3); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
478 %!test # Mass option as sparse matrix |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
479 %! opt = odeset ("Mass", sparse (eye (2,2))); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
480 %! sol = ode23 (@fpol, [0 2], [2 0], opt); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
481 %! assert ([sol.x(end), sol.y(end,:)], [2, fref], 1e-3); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
482 %!test # Mass option as function and sparse matrix |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
483 %! opt = odeset ("Mass", @fmsa); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
484 %! sol = ode23 (@fpol, [0 2], [2 0], opt); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
485 %! assert ([sol.x(end), sol.y(end,:)], [2, fref], 1e-3); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
486 %!test # Mass option as function and MStateDependence |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
487 %! opt = odeset ("Mass", @fmas, "MStateDependence", "strong"); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
488 %! sol = ode23 (@fpol, [0 2], [2 0], opt); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
489 %! assert ([sol.x(end), sol.y(end,:)], [2, fref], 1e-3); |
20901
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
490 %! |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
491 %! ## 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
|
492 %! ## 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
|
493 %! ## 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
|
494 |
21443
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
495 ## Test input validation |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
496 %!error ode23 () |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
497 %!error ode23 (1) |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
498 %!error ode23 (1,2) |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
499 %!error <TRANGE must be a numeric> |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
500 %! ode23 (@fpol, {[0 25]}, [3 15 1]); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
501 %!error <TRANGE must be a .* vector> |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
502 %! ode23 (@fpol, [0 25; 25 0], [3 15 1]); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
503 %!error <TRANGE must contain at least 2 elements> |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
504 %! ode23 (@fpol, [1], [3 15 1]); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
505 %!error <invalid time span> |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
506 %! ode23 (@fpol, [1 1], [3 15 1]); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
507 %!error <INIT must be a numeric> |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
508 %! ode23 (@fpol, [0 25], {[3 15 1]}); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
509 %!error <INIT must be a .* vector> |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
510 %! ode23 (@fpol, [0 25], [3 15 1; 3 15 1]); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
511 %!error <FUN must be a valid function handle> |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
512 %! ode23 (1, [0 25], [3 15 1]); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
513 |