Mercurial > octave
annotate scripts/ode/ode23.m @ 31265:c332a2f2959f
Clean up odeplot tests and demos (bug #63063)
* ode23.m, ode23s.m, ode45.m: Remove odeplot tests.
* odeplot.m: Convert inpot syntax test into a demo.
author | Ken Marek <marek_ka@mercer.edu> |
---|---|
date | Thu, 06 Oct 2022 16:36:29 -0400 |
parents | 449ed6f427cb |
children | 88fff8521d76 |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 ######################################################################## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 ## |
30564
796f54d4ddbf
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
3 ## Copyright (C) 2006-2022 The Octave Project Developers |
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
4 ## |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 ## See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 ## distribution or <https://octave.org/copyright/>. |
20901
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
7 ## |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
8 ## 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
|
9 ## |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23407
diff
changeset
|
10 ## Octave is free software: you can redistribute it and/or modify it |
20901
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
11 ## under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23407
diff
changeset
|
12 ## the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22707
diff
changeset
|
13 ## (at your option) any later version. |
20901
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
14 ## |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
15 ## 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
|
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22707
diff
changeset
|
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22707
diff
changeset
|
18 ## GNU General Public License for more details. |
20901
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
19 ## |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
20 ## 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
|
21 ## along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23407
diff
changeset
|
22 ## <https://www.gnu.org/licenses/>. |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 ## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 ######################################################################## |
20901
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
25 |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
26 ## -*- texinfo -*- |
30893
e1788b1a315f
maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
27 ## @deftypefn {} {[@var{t}, @var{y}] =} ode23 (@var{fcn}, @var{trange}, @var{init}) |
e1788b1a315f
maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
28 ## @deftypefnx {} {[@var{t}, @var{y}] =} ode23 (@var{fcn}, @var{trange}, @var{init}, @var{ode_opt}) |
21319
8880d93010d8
Remove further uses of CLASS field in @deftypefn macro.
Rik <rik@octave.org>
parents:
21123
diff
changeset
|
29 ## @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
|
30 ## @deftypefnx {} {@var{solution} =} ode23 (@dots{}) |
22939
54302b670139
doc: Document nargout=0 calling mode for ode23, ode45.
Rik <rik@octave.org>
parents:
22937
diff
changeset
|
31 ## @deftypefnx {} {} 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
|
32 ## |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
33 ## 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
|
34 ## with the well known explicit @nospell{Bogacki-Shampine} method of 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
|
35 ## |
30893
e1788b1a315f
maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
36 ## @var{fcn} is a function handle, inline function, or string containing the |
20901
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
37 ## 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
|
38 ## 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
|
39 ## 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
|
40 ## |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
41 ## @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
|
42 ## 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
|
43 ## 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
|
44 ## 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
|
45 ## 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
|
46 ## |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
47 ## 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
|
48 ## @code{integrate_adaptive} algorithm. The tolerance for the timestep |
25026
f886561f9696
doc: improve differential eqtn docs and mention ode15i/ode15s (bug #51965).
Colin Macdonald <cbm@m.fsf.org>
parents:
24534
diff
changeset
|
49 ## computation may be changed by using the options @qcode{"RelTol"} and |
f886561f9696
doc: improve differential eqtn docs and mention ode15i/ode15s (bug #51965).
Colin Macdonald <cbm@m.fsf.org>
parents:
24534
diff
changeset
|
50 ## @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
|
51 ## |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
52 ## @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
|
53 ## 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
|
54 ## 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
|
55 ## |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
56 ## 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
|
57 ## 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
|
58 ## |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
59 ## 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
|
60 ## 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
|
61 ## 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
|
62 ## 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
|
63 ## |
25026
f886561f9696
doc: improve differential eqtn docs and mention ode15i/ode15s (bug #51965).
Colin Macdonald <cbm@m.fsf.org>
parents:
24534
diff
changeset
|
64 ## The output can also be returned as a structure @var{solution} which has a |
f886561f9696
doc: improve differential eqtn docs and mention ode15i/ode15s (bug #51965).
Colin Macdonald <cbm@m.fsf.org>
parents:
24534
diff
changeset
|
65 ## field @var{x} containing a row vector of times where the solution was |
f886561f9696
doc: improve differential eqtn docs and mention ode15i/ode15s (bug #51965).
Colin Macdonald <cbm@m.fsf.org>
parents:
24534
diff
changeset
|
66 ## evaluated and a field @var{y} containing the solution matrix such that each |
f886561f9696
doc: improve differential eqtn docs and mention ode15i/ode15s (bug #51965).
Colin Macdonald <cbm@m.fsf.org>
parents:
24534
diff
changeset
|
67 ## column corresponds to a time in @var{x}. Use |
f886561f9696
doc: improve differential eqtn docs and mention ode15i/ode15s (bug #51965).
Colin Macdonald <cbm@m.fsf.org>
parents:
24534
diff
changeset
|
68 ## @w{@code{fieldnames (@var{solution})}} to see the other fields and |
21546
f7f97d7e9294
doc: Wrap m-file docstrings to 79 characters + newline (80 total).
Rik <rik@octave.org>
parents:
21443
diff
changeset
|
69 ## 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
|
70 ## |
28713
28d2511f2af2
maint: grammarcheck documentation ahead of 6.1 release.
Rik <rik@octave.org>
parents:
28045
diff
changeset
|
71 ## If no output arguments are requested, and no @qcode{"OutputFcn"} is |
28d2511f2af2
maint: grammarcheck documentation ahead of 6.1 release.
Rik <rik@octave.org>
parents:
28045
diff
changeset
|
72 ## specified in @var{ode_opt}, then the @qcode{"OutputFcn"} is set to |
28d2511f2af2
maint: grammarcheck documentation ahead of 6.1 release.
Rik <rik@octave.org>
parents:
28045
diff
changeset
|
73 ## @code{odeplot} and the results of the solver are plotted immediately. |
22939
54302b670139
doc: Document nargout=0 calling mode for ode23, ode45.
Rik <rik@octave.org>
parents:
22937
diff
changeset
|
74 ## |
25026
f886561f9696
doc: improve differential eqtn docs and mention ode15i/ode15s (bug #51965).
Colin Macdonald <cbm@m.fsf.org>
parents:
24534
diff
changeset
|
75 ## If using the @qcode{"Events"} option then three additional outputs may be |
f886561f9696
doc: improve differential eqtn docs and mention ode15i/ode15s (bug #51965).
Colin Macdonald <cbm@m.fsf.org>
parents:
24534
diff
changeset
|
76 ## returned. @var{te} holds the time when an Event function returned a zero. |
f886561f9696
doc: improve differential eqtn docs and mention ode15i/ode15s (bug #51965).
Colin Macdonald <cbm@m.fsf.org>
parents:
24534
diff
changeset
|
77 ## @var{ye} holds the value of the solution at time @var{te}. @var{ie} |
20901
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
78 ## 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
|
79 ## 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
|
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 |
25026
f886561f9696
doc: improve differential eqtn docs and mention ode15i/ode15s (bug #51965).
Colin Macdonald <cbm@m.fsf.org>
parents:
24534
diff
changeset
|
89 ## |
f886561f9696
doc: improve differential eqtn docs and mention ode15i/ode15s (bug #51965).
Colin Macdonald <cbm@m.fsf.org>
parents:
24534
diff
changeset
|
90 ## Reference: For the definition of this method see |
25143
13fd0610480f
doc: Use https whenever possible in @url entries.
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
91 ## @url{https://en.wikipedia.org/wiki/List_of_Runge%E2%80%93Kutta_methods}. |
25026
f886561f9696
doc: improve differential eqtn docs and mention ode15i/ode15s (bug #51965).
Colin Macdonald <cbm@m.fsf.org>
parents:
24534
diff
changeset
|
92 ## @seealso{odeset, odeget, ode45, ode15s} |
20901
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
93 ## @end deftypefn |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
94 |
30893
e1788b1a315f
maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
95 function varargout = ode23 (fcn, trange, init, 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
|
96 |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
97 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
|
98 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
|
99 endif |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
100 |
28045
13dba3c069f8
Update input validation for odeXXX.m functions.
Rik <rik@octave.org>
parents:
28041
diff
changeset
|
101 solver = "ode23"; |
22593
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
102 order = 3; |
20928
2b8447888e0a
strip trailing whitespace from files
John W. Eaton <jwe@octave.org>
parents:
20908
diff
changeset
|
103 |
20901
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
104 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
|
105 if (! isstruct (varargin{1})) |
30893
e1788b1a315f
maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
106 ## varargin{1:len} are parameters for fcn |
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 odeopts = odeset (); |
22593
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
108 funarguments = varargin; |
22626 | 109 elseif (numel (varargin) > 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
|
110 ## 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
|
111 odeopts = varargin{1}; |
22626 | 112 funarguments = {varargin{2:numel (varargin)}}; |
28045
13dba3c069f8
Update input validation for odeXXX.m functions.
Rik <rik@octave.org>
parents:
28041
diff
changeset
|
113 else |
13dba3c069f8
Update input validation for odeXXX.m functions.
Rik <rik@octave.org>
parents:
28041
diff
changeset
|
114 ## 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
|
115 odeopts = varargin{1}; |
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
116 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
|
117 endif |
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 # 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
|
119 odeopts = odeset (); |
22593
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 |
21443
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
123 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
|
124 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
|
125 "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
|
126 endif |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
127 |
22626 | 128 if (numel (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
|
129 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
|
130 "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
|
131 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
|
132 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
|
133 "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
|
134 else |
22593
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
135 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
|
136 endif |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
137 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
|
138 |
21443
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
139 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
|
140 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
|
141 "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
|
142 endif |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
143 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
|
144 |
30893
e1788b1a315f
maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
145 if (ischar (fcn)) |
e1788b1a315f
maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
146 if (! exist (fcn)) |
28041
5e44268dca6f
Replace input validation relying on str2func with alternatives (bug #57351).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
147 error ("Octave:invalid-input-arg", |
30893
e1788b1a315f
maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
148 ['ode23: function "' fcn '" not found']); |
28041
5e44268dca6f
Replace input validation relying on str2func with alternatives (bug #57351).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
149 endif |
30893
e1788b1a315f
maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
150 fcn = str2func (fcn); |
20901
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
151 endif |
30893
e1788b1a315f
maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
152 if (! is_function_handle (fcn)) |
20901
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
153 error ("Octave:invalid-input-arg", |
30893
e1788b1a315f
maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
154 "ode23: FCN must be a valid function handle"); |
20901
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 |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
157 ## Start preprocessing, have a look which options are set in odeopts, |
22626 | 158 ## check if an invalid or unused option is set. |
159 [defaults, classes, attributes] = odedefaults (numel (init), | |
160 trange(1), 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
|
161 |
22660
7eb3f8ec1aed
Remove FIXME comment about missing tests for ignored ODE options.
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22659
diff
changeset
|
162 persistent ode23_ignore_options = ... |
7eb3f8ec1aed
Remove FIXME comment about missing tests for ignored ODE options.
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22659
diff
changeset
|
163 {"BDF", "InitialSlope", "Jacobian", "JPattern", |
7eb3f8ec1aed
Remove FIXME comment about missing tests for ignored ODE options.
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22659
diff
changeset
|
164 "MassSingular", "MaxOrder", "MvPattern", "Vectorized"}; |
22707
413a19bca7f3
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22661
diff
changeset
|
165 |
22660
7eb3f8ec1aed
Remove FIXME comment about missing tests for ignored ODE options.
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22659
diff
changeset
|
166 defaults = rmfield (defaults, ode23_ignore_options); |
7eb3f8ec1aed
Remove FIXME comment about missing tests for ignored ODE options.
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22659
diff
changeset
|
167 classes = rmfield (classes, ode23_ignore_options); |
7eb3f8ec1aed
Remove FIXME comment about missing tests for ignored ODE options.
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22659
diff
changeset
|
168 attributes = rmfield (attributes, ode23_ignore_options); |
20901
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
169 |
22626 | 170 odeopts = odemergeopts ("ode23", odeopts, defaults, classes, attributes); |
20901
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
171 |
22593
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
172 odeopts.funarguments = funarguments; |
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
173 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
|
174 |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
175 if (! 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
|
176 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
|
177 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
|
178 else |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
179 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
|
180 warning ("Octave:invalid-input-arg", |
22626 | 181 ['ode23: option "NonNegative" is ignored', ... |
20901
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
182 " 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
|
183 endif |
20928
2b8447888e0a
strip trailing whitespace from files
John W. Eaton <jwe@octave.org>
parents:
20908
diff
changeset
|
184 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
|
185 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
|
186 endif |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
187 |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
188 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
|
189 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
|
190 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
|
191 else |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
192 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
|
193 endif |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
194 |
22593
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
195 if (isempty (odeopts.InitialStep)) |
20908
0fb9de5b7903
remove verbose warnings from ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
20902
diff
changeset
|
196 odeopts.InitialStep = odeopts.direction * ... |
30893
e1788b1a315f
maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
197 starting_stepsize (order, fcn, trange(1), init, |
22626 | 198 odeopts.AbsTol, odeopts.RelTol, |
31263
449ed6f427cb
ode45/23/23s: Implement Events, OutputFcn, & Refine options (bug #49408 and #63063)
Ken Marek <marek_ka@mercer.edu>
parents:
30893
diff
changeset
|
199 strcmpi (odeopts.NormControl, |
449ed6f427cb
ode45/23/23s: Implement Events, OutputFcn, & Refine options (bug #49408 and #63063)
Ken Marek <marek_ka@mercer.edu>
parents:
30893
diff
changeset
|
200 "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
|
201 endif |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
202 |
28045
13dba3c069f8
Update input validation for odeXXX.m functions.
Rik <rik@octave.org>
parents:
28041
diff
changeset
|
203 if (! isempty (odeopts.Mass)) |
13dba3c069f8
Update input validation for odeXXX.m functions.
Rik <rik@octave.org>
parents:
28041
diff
changeset
|
204 if (isnumeric (odeopts.Mass)) |
13dba3c069f8
Update input validation for odeXXX.m functions.
Rik <rik@octave.org>
parents:
28041
diff
changeset
|
205 havemasshandle = false; |
13dba3c069f8
Update input validation for odeXXX.m functions.
Rik <rik@octave.org>
parents:
28041
diff
changeset
|
206 mass = odeopts.Mass; # constant mass |
13dba3c069f8
Update input validation for odeXXX.m functions.
Rik <rik@octave.org>
parents:
28041
diff
changeset
|
207 elseif (is_function_handle (odeopts.Mass)) |
13dba3c069f8
Update input validation for odeXXX.m functions.
Rik <rik@octave.org>
parents:
28041
diff
changeset
|
208 havemasshandle = true; # mass defined by a function handle |
13dba3c069f8
Update input validation for odeXXX.m functions.
Rik <rik@octave.org>
parents:
28041
diff
changeset
|
209 else |
13dba3c069f8
Update input validation for odeXXX.m functions.
Rik <rik@octave.org>
parents:
28041
diff
changeset
|
210 error ("Octave:invalid-input-arg", |
13dba3c069f8
Update input validation for odeXXX.m functions.
Rik <rik@octave.org>
parents:
28041
diff
changeset
|
211 'ode45: "Mass" field must be a function handle or square matrix'); |
13dba3c069f8
Update input validation for odeXXX.m functions.
Rik <rik@octave.org>
parents:
28041
diff
changeset
|
212 endif |
13dba3c069f8
Update input validation for odeXXX.m functions.
Rik <rik@octave.org>
parents:
28041
diff
changeset
|
213 else # no mass matrix - create a diag-matrix of ones for mass |
13dba3c069f8
Update input validation for odeXXX.m functions.
Rik <rik@octave.org>
parents:
28041
diff
changeset
|
214 havemasshandle = false; # mass = diag (ones (length (init), 1), 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
|
215 endif |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
216 |
21443
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
217 ## 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
|
218 |
20901
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 (havemasshandle) # Handle only the dynamic mass matrix, |
22626 | 220 if (! strcmp (odeopts.MStateDependence, "none")) |
22661
c00578ac8dda
Resolve FIXME notes in ode code base.
Rik <rik@octave.org>
parents:
22660
diff
changeset
|
221 ## constant mass matrices have already been handled |
20901
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
222 mass = @(t,x) odeopts.Mass (t, x, odeopts.funarguments{:}); |
30893
e1788b1a315f
maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
223 fcn = @(t,x) mass (t, x, odeopts.funarguments{:}) ... |
e1788b1a315f
maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
224 \ fcn (t, x, odeopts.funarguments{:}); |
22626 | 225 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
|
226 mass = @(t) odeopts.Mass (t, odeopts.funarguments{:}); |
30893
e1788b1a315f
maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
227 fcn = @(t,x) mass (t, odeopts.funarguments{:}) ... |
e1788b1a315f
maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
228 \ fcn (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
|
229 endif |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
230 endif |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
231 |
31263
449ed6f427cb
ode45/23/23s: Implement Events, OutputFcn, & Refine options (bug #49408 and #63063)
Ken Marek <marek_ka@mercer.edu>
parents:
30893
diff
changeset
|
232 if (numel (trange) > 2) |
22659
04fc7e9c5f96
Disable Refine option of ode solvers for certain input/output combinations (partial fix bug #49408).
Rik <rik@octave.org>
parents:
22658
diff
changeset
|
233 odeopts.Refine = []; # disable Refine when specific times requested |
22658
56d7d423aff9
Return intermediate integration times when single output argument used in ode solver (bug #49417).
Rik <rik@octave.org>
parents:
22655
diff
changeset
|
234 endif |
56d7d423aff9
Return intermediate integration times when single output argument used in ode solver (bug #49417).
Rik <rik@octave.org>
parents:
22655
diff
changeset
|
235 |
22626 | 236 solution = integrate_adaptive (@runge_kutta_23, |
30893
e1788b1a315f
maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
237 order, fcn, 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
|
238 |
20901
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
239 ## 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
|
240 if (odeopts.haveoutputfunction) # Cleanup plotter |
22639
7efa2d0e22c9
More Matlab-compatible implementation of OutputFcn. Clean up odeplot.m.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
241 feval (odeopts.OutputFcn, [], [], "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
|
242 endif |
22593
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
243 if (! isempty (odeopts.Events)) # Cleanup event function handling |
31263
449ed6f427cb
ode45/23/23s: Implement Events, OutputFcn, & Refine options (bug #49408 and #63063)
Ken Marek <marek_ka@mercer.edu>
parents:
30893
diff
changeset
|
244 ode_event_handler (odeopts.Events, solution.ode_t(end), ... |
449ed6f427cb
ode45/23/23s: Implement Events, OutputFcn, & Refine options (bug #49408 and #63063)
Ken Marek <marek_ka@mercer.edu>
parents:
30893
diff
changeset
|
245 solution.ode_x(end,:).', "done", ... |
449ed6f427cb
ode45/23/23s: Implement Events, OutputFcn, & Refine options (bug #49408 and #63063)
Ken Marek <marek_ka@mercer.edu>
parents:
30893
diff
changeset
|
246 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
|
247 endif |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
248 |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
249 ## Print additional information if option Stats is set |
22935
c9344df03da5
Allow case-insensitive option argument 'on' to ode solvers (bug #49918).
Rik <rik@octave.org>
parents:
22934
diff
changeset
|
250 if (strcmpi (odeopts.Stats, "on")) |
21955
0f3e875d9078
Fix statistics on solution solving for ode45, ode23 (bug #48243).
jcorno <jacopo.corno@gmail.com>
parents:
21751
diff
changeset
|
251 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
|
252 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
|
253 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
|
254 ndecomps = 0; # number of LU decompositions |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
255 npds = 0; # number of partial derivatives |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
256 nlinsols = 0; # no. of solutions of linear systems |
22934
bb452f84a299
Fix printing of solution stats in ode23/ode45 solvers (bug #49918).
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22900
diff
changeset
|
257 |
bb452f84a299
Fix printing of solution stats in ode23/ode45 solvers (bug #49918).
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22900
diff
changeset
|
258 printf ("Number of successful steps: %d\n", nsteps); |
bb452f84a299
Fix printing of solution stats in ode23/ode45 solvers (bug #49918).
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22900
diff
changeset
|
259 printf ("Number of failed attempts: %d\n", nfailed); |
bb452f84a299
Fix printing of solution stats in ode23/ode45 solvers (bug #49918).
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22900
diff
changeset
|
260 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
|
261 endif |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
262 |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
263 if (nargout == 2) |
31263
449ed6f427cb
ode45/23/23s: Implement Events, OutputFcn, & Refine options (bug #49408 and #63063)
Ken Marek <marek_ka@mercer.edu>
parents:
30893
diff
changeset
|
264 varargout{1} = solution.output_t; # Time stamps are first output argument |
449ed6f427cb
ode45/23/23s: Implement Events, OutputFcn, & Refine options (bug #49408 and #63063)
Ken Marek <marek_ka@mercer.edu>
parents:
30893
diff
changeset
|
265 varargout{2} = solution.output_x; # Results are second output argument |
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 elseif (nargout == 1) |
31263
449ed6f427cb
ode45/23/23s: Implement Events, OutputFcn, & Refine options (bug #49408 and #63063)
Ken Marek <marek_ka@mercer.edu>
parents:
30893
diff
changeset
|
267 varargout{1}.x = solution.ode_t.'; #Time stamps saved in field x (row vect.) |
449ed6f427cb
ode45/23/23s: Implement Events, OutputFcn, & Refine options (bug #49408 and #63063)
Ken Marek <marek_ka@mercer.edu>
parents:
30893
diff
changeset
|
268 varargout{1}.y = solution.ode_x.'; #Results are saved in field y (row vect.) |
449ed6f427cb
ode45/23/23s: Implement Events, OutputFcn, & Refine options (bug #49408 and #63063)
Ken Marek <marek_ka@mercer.edu>
parents:
30893
diff
changeset
|
269 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
|
270 if (! isempty (odeopts.Events)) |
31263
449ed6f427cb
ode45/23/23s: Implement Events, OutputFcn, & Refine options (bug #49408 and #63063)
Ken Marek <marek_ka@mercer.edu>
parents:
30893
diff
changeset
|
271 varargout{1}.xe = solution.event{3}.'; # Time info when an event occurred |
449ed6f427cb
ode45/23/23s: Implement Events, OutputFcn, & Refine options (bug #49408 and #63063)
Ken Marek <marek_ka@mercer.edu>
parents:
30893
diff
changeset
|
272 varargout{1}.ye = solution.event{4}.'; # Results when an event occurred |
449ed6f427cb
ode45/23/23s: Implement Events, OutputFcn, & Refine options (bug #49408 and #63063)
Ken Marek <marek_ka@mercer.edu>
parents:
30893
diff
changeset
|
273 varargout{1}.ie = solution.event{2}.'; # Index info which event occurred |
20901
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
274 endif |
22935
c9344df03da5
Allow case-insensitive option argument 'on' to ode solvers (bug #49918).
Rik <rik@octave.org>
parents:
22934
diff
changeset
|
275 if (strcmpi (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
|
276 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
|
277 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
|
278 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
|
279 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
|
280 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
|
281 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
|
282 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
|
283 endif |
22937
2b2ac017c901
Fix undefined return argument for more than 2 outputs from ode solver (bug #49890).
Rik <rik@octave.org>
parents:
22707
diff
changeset
|
284 elseif (nargout > 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
|
285 varargout = cell (1,5); |
31263
449ed6f427cb
ode45/23/23s: Implement Events, OutputFcn, & Refine options (bug #49408 and #63063)
Ken Marek <marek_ka@mercer.edu>
parents:
30893
diff
changeset
|
286 varargout{1} = solution.output_t; |
449ed6f427cb
ode45/23/23s: Implement Events, OutputFcn, & Refine options (bug #49408 and #63063)
Ken Marek <marek_ka@mercer.edu>
parents:
30893
diff
changeset
|
287 varargout{2} = solution.output_x; |
22593
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
288 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
|
289 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
|
290 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
|
291 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
|
292 endif |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
293 endif |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
294 |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
295 endfunction |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
296 |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
297 |
21599
f29d68e24c5a
ode23.m, ode45.m: More reformatting of demos to Octave coding standards.
Rik <rik@octave.org>
parents:
21596
diff
changeset
|
298 %!demo |
f29d68e24c5a
ode23.m, ode45.m: More reformatting of demos to Octave coding standards.
Rik <rik@octave.org>
parents:
21596
diff
changeset
|
299 %! ## 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
|
300 %! 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
|
301 %! 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
|
302 %! 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
|
303 %! [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
|
304 %! 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
|
305 %! 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
|
306 %! endfor |
f29d68e24c5a
ode23.m, ode45.m: More reformatting of demos to Octave coding standards.
Rik <rik@octave.org>
parents:
21596
diff
changeset
|
307 %! |
f29d68e24c5a
ode23.m, ode45.m: More reformatting of demos to Octave coding standards.
Rik <rik@octave.org>
parents:
21596
diff
changeset
|
308 %! ## Estimate order visually |
f29d68e24c5a
ode23.m, ode45.m: More reformatting of demos to Octave coding standards.
Rik <rik@octave.org>
parents:
21596
diff
changeset
|
309 %! 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
|
310 %! h, err, "-b", |
f29d68e24c5a
ode23.m, ode45.m: More reformatting of demos to Octave coding standards.
Rik <rik@octave.org>
parents:
21596
diff
changeset
|
311 %! 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
|
312 %! 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
|
313 %! axis tight |
f29d68e24c5a
ode23.m, ode45.m: More reformatting of demos to Octave coding standards.
Rik <rik@octave.org>
parents:
21596
diff
changeset
|
314 %! xlabel ("h"); |
f29d68e24c5a
ode23.m, ode45.m: More reformatting of demos to Octave coding standards.
Rik <rik@octave.org>
parents:
21596
diff
changeset
|
315 %! ylabel ("err(h)"); |
f29d68e24c5a
ode23.m, ode45.m: More reformatting of demos to Octave coding standards.
Rik <rik@octave.org>
parents:
21596
diff
changeset
|
316 %! 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
|
317 %! 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
|
318 %! "order 2", "order 3", "location", "northwest"); |
22647
cf8ec7abb4ae
Clean up demo and test blocks for ode functions.
Rik <rik@octave.org>
parents:
22644
diff
changeset
|
319 %! |
cf8ec7abb4ae
Clean up demo and test blocks for ode functions.
Rik <rik@octave.org>
parents:
22644
diff
changeset
|
320 %! ## Estimate order numerically |
cf8ec7abb4ae
Clean up demo and test blocks for ode functions.
Rik <rik@octave.org>
parents:
22644
diff
changeset
|
321 %! p = diff (log (err)) ./ diff (log (h)) |
21599
f29d68e24c5a
ode23.m, ode45.m: More reformatting of demos to Octave coding standards.
Rik <rik@octave.org>
parents:
21596
diff
changeset
|
322 |
22934
bb452f84a299
Fix printing of solution stats in ode23/ode45 solvers (bug #49918).
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22900
diff
changeset
|
323 ## We are using the Van der Pol equation for all tests. |
bb452f84a299
Fix printing of solution stats in ode23/ode45 solvers (bug #49918).
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22900
diff
changeset
|
324 ## Further tests also define a reference solution (computed at high accuracy) |
28563
5a07c798eb08
avoid function call input or output argument number mismatch
John W. Eaton <jwe@octave.org>
parents:
28045
diff
changeset
|
325 %!function ydot = fpol (t, y, varargin) # The Van der Pol ODE |
22626 | 326 %! ydot = [y(2); (1 - y(1)^2) * y(2) - y(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
|
327 %!endfunction |
21443
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
328 %!function ref = fref () # The computed reference sol |
22626 | 329 %! ref = [0.32331666704577, -1.83297456798624]; |
20901
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
330 %!endfunction |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
331 %!function [val, trm, dir] = feve (t, y, varargin) |
28563
5a07c798eb08
avoid function call input or output argument number mismatch
John W. Eaton <jwe@octave.org>
parents:
28045
diff
changeset
|
332 %! val = fpol (t, y, varargin{:}); # We use the derivatives |
22934
bb452f84a299
Fix printing of solution stats in ode23/ode45 solvers (bug #49918).
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22900
diff
changeset
|
333 %! trm = zeros (2,1); # that's why component 2 |
bb452f84a299
Fix printing of solution stats in ode23/ode45 solvers (bug #49918).
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22900
diff
changeset
|
334 %! dir = ones (2,1); # does not seem to be exact |
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 %!endfunction |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
336 %!function [val, trm, dir] = fevn (t, y, varargin) |
28563
5a07c798eb08
avoid function call input or output argument number mismatch
John W. Eaton <jwe@octave.org>
parents:
28045
diff
changeset
|
337 %! val = fpol (t, y, varargin{:}); # We use the derivatives |
22934
bb452f84a299
Fix printing of solution stats in ode23/ode45 solvers (bug #49918).
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22900
diff
changeset
|
338 %! trm = ones (2,1); # that's why component 2 |
bb452f84a299
Fix printing of solution stats in ode23/ode45 solvers (bug #49918).
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22900
diff
changeset
|
339 %! dir = ones (2,1); # does not seem to be exact |
20901
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
340 %!endfunction |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
341 %!function mas = fmas (t, y, varargin) |
22934
bb452f84a299
Fix printing of solution stats in ode23/ode45 solvers (bug #49918).
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22900
diff
changeset
|
342 %! mas = [1, 0; 0, 1]; # Dummy mass matrix for tests |
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 %!endfunction |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
344 %!function mas = fmsa (t, y, varargin) |
22934
bb452f84a299
Fix printing of solution stats in ode23/ode45 solvers (bug #49918).
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22900
diff
changeset
|
345 %! mas = sparse ([1, 0; 0, 1]); # A sparse dummy matrix |
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 %!endfunction |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
347 %!function out = fout (t, y, flag, varargin) |
22639
7efa2d0e22c9
More Matlab-compatible implementation of OutputFcn. Clean up odeplot.m.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
348 %! out = false; |
7efa2d0e22c9
More Matlab-compatible implementation of OutputFcn. Clean up odeplot.m.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
349 %! if (strcmp (flag, "init")) |
7efa2d0e22c9
More Matlab-compatible implementation of OutputFcn. Clean up odeplot.m.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
350 %! if (! isequal (size (t), [2, 1])) |
7efa2d0e22c9
More Matlab-compatible implementation of OutputFcn. Clean up odeplot.m.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
351 %! error ('fout: step "init"'); |
7efa2d0e22c9
More Matlab-compatible implementation of OutputFcn. Clean up odeplot.m.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
352 %! endif |
22626 | 353 %! elseif (isempty (flag)) |
31263
449ed6f427cb
ode45/23/23s: Implement Events, OutputFcn, & Refine options (bug #49408 and #63063)
Ken Marek <marek_ka@mercer.edu>
parents:
30893
diff
changeset
|
354 %! # Multiple steps can be sent in one function call |
449ed6f427cb
ode45/23/23s: Implement Events, OutputFcn, & Refine options (bug #49408 and #63063)
Ken Marek <marek_ka@mercer.edu>
parents:
30893
diff
changeset
|
355 %! if (! isequal ( size (t), size (y))) |
22639
7efa2d0e22c9
More Matlab-compatible implementation of OutputFcn. Clean up odeplot.m.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
356 %! error ('fout: step "calc"'); |
7efa2d0e22c9
More Matlab-compatible implementation of OutputFcn. Clean up odeplot.m.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
357 %! endif |
7efa2d0e22c9
More Matlab-compatible implementation of OutputFcn. Clean up odeplot.m.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
358 %! elseif (strcmp (flag, "done")) |
7efa2d0e22c9
More Matlab-compatible implementation of OutputFcn. Clean up odeplot.m.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
359 %! if (! isempty (t)) |
7efa2d0e22c9
More Matlab-compatible implementation of OutputFcn. Clean up odeplot.m.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
360 %! warning ('fout: step "done"'); |
7efa2d0e22c9
More Matlab-compatible implementation of OutputFcn. Clean up odeplot.m.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
361 %! endif |
22626 | 362 %! else |
22639
7efa2d0e22c9
More Matlab-compatible implementation of OutputFcn. Clean up odeplot.m.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
363 %! error ("fout: invalid flag <%s>", flag); |
22626 | 364 %! endif |
20901
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
365 %!endfunction |
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
366 %! |
21443
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
367 %!test # two output arguments |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
368 %! [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
|
369 %! assert ([t(end), y(end,:)], [2, fref], 1e-3); |
31263
449ed6f427cb
ode45/23/23s: Implement Events, OutputFcn, & Refine options (bug #49408 and #63063)
Ken Marek <marek_ka@mercer.edu>
parents:
30893
diff
changeset
|
370 %!test # correct number of steps with Refine |
449ed6f427cb
ode45/23/23s: Implement Events, OutputFcn, & Refine options (bug #49408 and #63063)
Ken Marek <marek_ka@mercer.edu>
parents:
30893
diff
changeset
|
371 %! [t1, y1] = ode23 (@fpol, [0 2], [2 0], odeset ("Refine", 1)); |
449ed6f427cb
ode45/23/23s: Implement Events, OutputFcn, & Refine options (bug #49408 and #63063)
Ken Marek <marek_ka@mercer.edu>
parents:
30893
diff
changeset
|
372 %! [t2, y2] = ode23 (@fpol, [0 2], [2 0], odeset ("Refine", 4)); |
449ed6f427cb
ode45/23/23s: Implement Events, OutputFcn, & Refine options (bug #49408 and #63063)
Ken Marek <marek_ka@mercer.edu>
parents:
30893
diff
changeset
|
373 %! [t3, y3] = ode23 (@fpol, [0 2], [2 0]); #default Refine=1 |
449ed6f427cb
ode45/23/23s: Implement Events, OutputFcn, & Refine options (bug #49408 and #63063)
Ken Marek <marek_ka@mercer.edu>
parents:
30893
diff
changeset
|
374 %! s = ode23 (@fpol, [0 2], [2 0], odeset ("Refine", 4)); |
449ed6f427cb
ode45/23/23s: Implement Events, OutputFcn, & Refine options (bug #49408 and #63063)
Ken Marek <marek_ka@mercer.edu>
parents:
30893
diff
changeset
|
375 %! assert (length (t1) == length (t3)); |
449ed6f427cb
ode45/23/23s: Implement Events, OutputFcn, & Refine options (bug #49408 and #63063)
Ken Marek <marek_ka@mercer.edu>
parents:
30893
diff
changeset
|
376 %! assert (length (t2) == 4*length (t1) - 3); |
449ed6f427cb
ode45/23/23s: Implement Events, OutputFcn, & Refine options (bug #49408 and #63063)
Ken Marek <marek_ka@mercer.edu>
parents:
30893
diff
changeset
|
377 %! assert (length (s.x) == length (t1)); |
21443
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
378 %!test # anonymous function instead of real function |
22644
23941beb44cd
Cleanup variable names, obsolete ChangeLog info in ode23, ode45.
Rik <rik@octave.org>
parents:
22643
diff
changeset
|
379 %! fvdp = @(t,y) [y(2); (1 - y(1)^2) * y(2) - y(1)]; |
23941beb44cd
Cleanup variable names, obsolete ChangeLog info in ode23, ode45.
Rik <rik@octave.org>
parents:
22643
diff
changeset
|
380 %! [t, y] = ode23 (fvdp, [0 2], [2 0]); |
21443
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
381 %! 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
|
382 %!test # extra input arguments passed through |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
383 %! [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
|
384 %! 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
|
385 %!test # empty OdePkg structure *but* extra input arguments |
28892
3cac3ceb9629
maint: Use coding style with parentheses after function name to distinguish from a variable.
Rik <rik@octave.org>
parents:
28715
diff
changeset
|
386 %! opt = odeset (); |
21443
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
387 %! [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
|
388 %! 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
|
389 %!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
|
390 %! ref = [0, 14.77810590694212]; |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
391 %! [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
|
392 %! 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
|
393 %!test # InitialStep option |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
394 %! opt = odeset ("InitialStep", 1e-8); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
395 %! [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
|
396 %! 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
|
397 %!test # MaxStep option |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
398 %! opt = odeset ("MaxStep", 1e-3); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
399 %! 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
|
400 %! 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
|
401 %!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
|
402 %! ref = [-1.205364552835178, 0.951542399860817]; |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
403 %! sol = ode23 (@fpol, [0 -2], [2 0]); |
22654
bc61ed076549
Change orientation of output fields in struct returned from ode solvers (bug #49402).
Sebastian Schöps <sebastian@schoeps.org>
parents:
22647
diff
changeset
|
404 %! assert ([sol.x(end); sol.y(:,end)], [-2; ref'], 5e-3); |
21443
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
405 %!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
|
406 %! ref = [-1.205364552835178, 0.951542399860817]; |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
407 %! sol = ode23 (@fpol, [2 0 -2], fref); |
22654
bc61ed076549
Change orientation of output fields in struct returned from ode solvers (bug #49402).
Sebastian Schöps <sebastian@schoeps.org>
parents:
22647
diff
changeset
|
408 %! assert ([sol.x(end); sol.y(:,end)], [-2; ref'], 2e-2); |
21443
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
409 %!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
|
410 %! ref = [-1, 0.367879437558975]; |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
411 %! sol = ode23 (@(t,y) y, [0 -1], 1); |
22654
bc61ed076549
Change orientation of output fields in struct returned from ode solvers (bug #49402).
Sebastian Schöps <sebastian@schoeps.org>
parents:
22647
diff
changeset
|
412 %! assert ([sol.x(end); sol.y(:,end)], ref', 1e-2); |
21443
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
413 %!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
|
414 %! ref = [0, 14.77810590694212]; |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
415 %! sol = ode23 (@(t,y) y, [-2 0], 2); |
22654
bc61ed076549
Change orientation of output fields in struct returned from ode solvers (bug #49402).
Sebastian Schöps <sebastian@schoeps.org>
parents:
22647
diff
changeset
|
416 %! assert ([sol.x(end); sol.y(:,end)], ref', 1e-2); |
21443
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
417 %!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
|
418 %! ref = [-1.205364552835178, 0.951542399860817]; |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
419 %! opt = odeset ("MaxStep", 1e-3); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
420 %! 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
|
421 %! assert ([abs(sol.x(8)-sol.x(7))], [1e-3], 1e-3); |
22654
bc61ed076549
Change orientation of output fields in struct returned from ode solvers (bug #49402).
Sebastian Schöps <sebastian@schoeps.org>
parents:
22647
diff
changeset
|
422 %! assert ([sol.x(end); sol.y(:,end)], [-2; ref'], 1e-3); |
21443
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
423 %!test # AbsTol option |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
424 %! opt = odeset ("AbsTol", 1e-5); |
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); |
22654
bc61ed076549
Change orientation of output fields in struct returned from ode solvers (bug #49402).
Sebastian Schöps <sebastian@schoeps.org>
parents:
22647
diff
changeset
|
426 %! assert ([sol.x(end); sol.y(:,end)], [2; fref'], 1e-3); |
21443
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
427 %!test # AbsTol and RelTol option |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
428 %! 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
|
429 %! sol = ode23 (@fpol, [0 2], [2 0], opt); |
22654
bc61ed076549
Change orientation of output fields in struct returned from ode solvers (bug #49402).
Sebastian Schöps <sebastian@schoeps.org>
parents:
22647
diff
changeset
|
430 %! assert ([sol.x(end); sol.y(:,end)], [2; fref'], 1e-3); |
23407
e265ae9e7a6c
Fix hermite cubic interpolation in ode23
Andreas Stahel <Andreas.Stahel@bfh.ch>
parents:
23220
diff
changeset
|
431 %!test # hermite_cubic_interpolation |
e265ae9e7a6c
Fix hermite cubic interpolation in ode23
Andreas Stahel <Andreas.Stahel@bfh.ch>
parents:
23220
diff
changeset
|
432 %! opt = odeset ("RelTol", 1e-8, "NormControl", "on"); |
e265ae9e7a6c
Fix hermite cubic interpolation in ode23
Andreas Stahel <Andreas.Stahel@bfh.ch>
parents:
23220
diff
changeset
|
433 %! [t,sol] = ode23(@(t,x)[x(2);x(1)],linspace(0,1),[1;0],opt); |
28929
9e43deb9bfc3
maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents:
28912
diff
changeset
|
434 %! assert (max (abs (sol(:,1)-cosh (t))),0,1e-6); |
21443
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
435 %!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
|
436 %! 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
|
437 %! sol = ode23 (@fpol, [0 2], [2 0], opt); |
22654
bc61ed076549
Change orientation of output fields in struct returned from ode solvers (bug #49402).
Sebastian Schöps <sebastian@schoeps.org>
parents:
22647
diff
changeset
|
438 %! assert ([sol.x(end); sol.y(:,end)], [2; fref'], 1e-4); |
21443
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
439 %!test # Keeps initial values while integrating |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
440 %! opt = odeset ("NonNegative", 2); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
441 %! sol = ode23 (@fpol, [0 2], [2 0], opt); |
22654
bc61ed076549
Change orientation of output fields in struct returned from ode solvers (bug #49402).
Sebastian Schöps <sebastian@schoeps.org>
parents:
22647
diff
changeset
|
442 %! assert ([sol.x(end); sol.y(:,end)], [2; 2; 0], 1e-1); |
31263
449ed6f427cb
ode45/23/23s: Implement Events, OutputFcn, & Refine options (bug #49408 and #63063)
Ken Marek <marek_ka@mercer.edu>
parents:
30893
diff
changeset
|
443 %!test # Details of OutputSel can't be tested |
449ed6f427cb
ode45/23/23s: Implement Events, OutputFcn, & Refine options (bug #49408 and #63063)
Ken Marek <marek_ka@mercer.edu>
parents:
30893
diff
changeset
|
444 %! opt = odeset ("OutputFcn", @fout, "OutputSel", 1); |
21443
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
445 %! 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
|
446 %!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
|
447 %! opt = odeset ("Stats", "on"); |
22934
bb452f84a299
Fix printing of solution stats in ode23/ode45 solvers (bug #49918).
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22900
diff
changeset
|
448 %! stat_str = evalc ("sol = ode23 (@fpol, [0 2], [2 0], opt);"); |
bb452f84a299
Fix printing of solution stats in ode23/ode45 solvers (bug #49918).
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22900
diff
changeset
|
449 %! assert (strncmp (stat_str, "Number of successful steps:", 27)); |
21443
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 %! opt = odeset ("Events", @fevn, "NormControl", "on"); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
461 %! sol = ode23 (@fpol, [0 10], [2 0], opt); |
31263
449ed6f427cb
ode45/23/23s: Implement Events, OutputFcn, & Refine options (bug #49408 and #63063)
Ken Marek <marek_ka@mercer.edu>
parents:
30893
diff
changeset
|
462 %! assert ([sol.ie, sol.xe, sol.ye.'], |
21580
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21546
diff
changeset
|
463 %! [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
|
464 %!test # Events option, five output arguments |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
465 %! opt = odeset ("Events", @fevn, "NormControl", "on"); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
466 %! [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
|
467 %! 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
|
468 %!test # Mass option as function |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
469 %! opt = odeset ("Mass", @fmas); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
470 %! sol = ode23 (@fpol, [0 2], [2 0], opt); |
22654
bc61ed076549
Change orientation of output fields in struct returned from ode solvers (bug #49402).
Sebastian Schöps <sebastian@schoeps.org>
parents:
22647
diff
changeset
|
471 %! assert ([sol.x(end); sol.y(:,end)], [2; fref'], 1e-3); |
21443
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
472 %!test # Mass option as matrix |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
473 %! opt = odeset ("Mass", eye (2,2)); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
474 %! sol = ode23 (@fpol, [0 2], [2 0], opt); |
22654
bc61ed076549
Change orientation of output fields in struct returned from ode solvers (bug #49402).
Sebastian Schöps <sebastian@schoeps.org>
parents:
22647
diff
changeset
|
475 %! assert ([sol.x(end); sol.y(:,end)], [2; fref'], 1e-3); |
21443
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
476 %!test # Mass option as sparse matrix |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
477 %! 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
|
478 %! sol = ode23 (@fpol, [0 2], [2 0], opt); |
22654
bc61ed076549
Change orientation of output fields in struct returned from ode solvers (bug #49402).
Sebastian Schöps <sebastian@schoeps.org>
parents:
22647
diff
changeset
|
479 %! assert ([sol.x(end); sol.y(:,end)], [2; fref'], 1e-3); |
21443
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
480 %!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
|
481 %! opt = odeset ("Mass", @fmsa); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
482 %! sol = ode23 (@fpol, [0 2], [2 0], opt); |
22654
bc61ed076549
Change orientation of output fields in struct returned from ode solvers (bug #49402).
Sebastian Schöps <sebastian@schoeps.org>
parents:
22647
diff
changeset
|
483 %! assert ([sol.x(end); sol.y(:,end)], [2; fref'], 1e-3); |
21443
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
484 %!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
|
485 %! opt = odeset ("Mass", @fmas, "MStateDependence", "strong"); |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
486 %! sol = ode23 (@fpol, [0 2], [2 0], opt); |
22654
bc61ed076549
Change orientation of output fields in struct returned from ode solvers (bug #49402).
Sebastian Schöps <sebastian@schoeps.org>
parents:
22647
diff
changeset
|
487 %! assert ([sol.x(end); sol.y(:,end)], [2; fref'], 1e-3); |
22626 | 488 |
22660
7eb3f8ec1aed
Remove FIXME comment about missing tests for ignored ODE options.
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22659
diff
changeset
|
489 ## Note: The following options have no effect on this solver |
7eb3f8ec1aed
Remove FIXME comment about missing tests for ignored ODE options.
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22659
diff
changeset
|
490 ## therefore it makes no sense to test them here: |
7eb3f8ec1aed
Remove FIXME comment about missing tests for ignored ODE options.
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22659
diff
changeset
|
491 ## |
7eb3f8ec1aed
Remove FIXME comment about missing tests for ignored ODE options.
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22659
diff
changeset
|
492 ## "BDF" |
7eb3f8ec1aed
Remove FIXME comment about missing tests for ignored ODE options.
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22659
diff
changeset
|
493 ## "InitialSlope" |
7eb3f8ec1aed
Remove FIXME comment about missing tests for ignored ODE options.
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22659
diff
changeset
|
494 ## "JPattern" |
7eb3f8ec1aed
Remove FIXME comment about missing tests for ignored ODE options.
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22659
diff
changeset
|
495 ## "Jacobian" |
7eb3f8ec1aed
Remove FIXME comment about missing tests for ignored ODE options.
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22659
diff
changeset
|
496 ## "MassSingular" |
7eb3f8ec1aed
Remove FIXME comment about missing tests for ignored ODE options.
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22659
diff
changeset
|
497 ## "MaxOrder" |
7eb3f8ec1aed
Remove FIXME comment about missing tests for ignored ODE options.
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22659
diff
changeset
|
498 ## "MvPattern" |
7eb3f8ec1aed
Remove FIXME comment about missing tests for ignored ODE options.
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22659
diff
changeset
|
499 ## "Vectorized" |
20901
afe9c529760d
2015 Code Sprint: move ode23 and runge_kutta_23 from odepkg to core
Stefan Miereis <stefan.miereis@gmx.de>
parents:
diff
changeset
|
500 |
22655
6b134d294d61
ode solvers: use ordinary transpose instead of Hermitian conjugate (bug #49410).
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22654
diff
changeset
|
501 %!test # Check that imaginary part of solution does not get inverted |
6b134d294d61
ode solvers: use ordinary transpose instead of Hermitian conjugate (bug #49410).
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22654
diff
changeset
|
502 %! sol = ode23 (@(x,y) 1, [0 1], 1i); |
28929
9e43deb9bfc3
maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents:
28912
diff
changeset
|
503 %! assert (imag (sol.y), ones (size (sol.y))); |
22655
6b134d294d61
ode solvers: use ordinary transpose instead of Hermitian conjugate (bug #49410).
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22654
diff
changeset
|
504 %! [x, y] = ode23 (@(x,y) 1, [0 1], 1i); |
28929
9e43deb9bfc3
maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents:
28912
diff
changeset
|
505 %! assert (imag (y), ones (size (y))); |
22655
6b134d294d61
ode solvers: use ordinary transpose instead of Hermitian conjugate (bug #49410).
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22654
diff
changeset
|
506 |
21443
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
21319
diff
changeset
|
507 ## Test input validation |
28896
90fea9cc9caa
test: Add expected error message <Invalid call> to BIST tests for nargin.
Rik <rik@octave.org>
parents:
28892
diff
changeset
|
508 %!error <Invalid call> ode23 () |
90fea9cc9caa
test: Add expected error message <Invalid call> to BIST tests for nargin.
Rik <rik@octave.org>
parents:
28892
diff
changeset
|
509 %!error <Invalid call> ode23 (1) |
90fea9cc9caa
test: Add expected error message <Invalid call> to BIST tests for nargin.
Rik <rik@octave.org>
parents:
28892
diff
changeset
|
510 %!error <Invalid call> ode23 (1,2) |
22626 | 511 %!error <TRANGE must be a numeric> ode23 (@fpol, {[0 25]}, [3 15 1]) |
512 %!error <TRANGE must be a .* vector> ode23 (@fpol, [0 25; 25 0], [3 15 1]) | |
513 %!error <TRANGE must contain at least 2 elements> ode23 (@fpol, [1], [3 15 1]) | |
514 %!error <invalid time span> ode23 (@fpol, [1 1], [3 15 1]) | |
515 %!error <INIT must be a numeric> ode23 (@fpol, [0 25], {[3 15 1]}) | |
516 %!error <INIT must be a .* vector> ode23 (@fpol, [0 25], [3 15 1; 3 15 1]) | |
30893
e1788b1a315f
maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
517 %!error <FCN must be a valid function handle> ode23 (1, [0 25], [3 15 1]) |