Mercurial > octave
annotate scripts/ode/ode45.m @ 31263:449ed6f427cb
ode45/23/23s: Implement Events, OutputFcn, & Refine options (bug #49408 and #63063)
* scripts/ode/ode23.m: Remove disabling of Refine option with struct output.
Modify solution struct to output two sets of solution variables: output_t,
output_x and ode_t and ode_x, and transpose struct output variables for
improved Matlab compatibility. Update BISTs and perform minor code formatting.
* scripts/ode/ode23s.m: Make same changes as ode23.m.
* scripts/ode/ode45.m: Make same changes as ode23.m. Remove comment indicating
that Refine is not implemented.
* scripts/ode/private/integrate_adaptive.m: Update internal handling of
variables t and x, separating them into ode_t & ode_x for internal integration
and output_t & output_x for function output or calls to OutputFcn. Replace
prior attempt at Refine option with new implementation. Specify time output or
Refine != 0 are both interpolated from internal variables (ode_t, ode_x) for
output of non-struct variables and/or for use with OutputFcn. Improve event
handling when multiple Events (including at least one terminal Event) are
detected in a single simulation step so that all Events up to and including the
first terminal one are reported, and final data point is set to that of
terminal Event. Send multiple data points in a single call to OutputFcn if they
are all interpolated from a single integration step. Remove warning for
termination when term signal is received from Events or OutputFcn. Return both
internal variables (ode_t, ode_x) and interpolated variables (output_t,
output_x) to allow calling function to correctly return either struct or
separate variables.
* scripts/ode/private/ode_event_handler.m: Sort multiple Events in ascending
time order when they are encountered in one integration step. Remove any events
after the time of a terminal Event.
* scripts/ode/odeset.m: Update docstring to remove indication that Refine is
not implemented
* scripts/ode/odeplot.m: Update docstring to indicate that input t can be a
scalar or vector. Add file test.
* etc/NEWS.8.md: Add descriptions of changes under General improvements and
Matlab compatibility.
author | Ken Marek <marek_ka@mercer.edu> |
---|---|
date | Wed, 05 Oct 2022 16:53:01 -0400 |
parents | e1788b1a315f |
children | c332a2f2959f |
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/>. |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
7 ## |
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
8 ## This file is part of Octave. |
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
9 ## |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
10 ## Octave is free software: you can redistribute it and/or modify it |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
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:
23220
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:
22660
diff
changeset
|
13 ## (at your option) any later version. |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
14 ## |
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
15 ## Octave is distributed in the hope that it will be useful, but |
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22660
diff
changeset
|
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22660
diff
changeset
|
18 ## GNU General Public License for more details. |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
19 ## |
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
20 ## You should have received a copy of the GNU General Public License |
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
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:
23220
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 ######################################################################## |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
25 |
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
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}] =} ode45 (@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}] =} ode45 (@var{fcn}, @var{trange}, @var{init}, @var{ode_opt}) |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20719
diff
changeset
|
29 ## @deftypefnx {} {[@var{t}, @var{y}, @var{te}, @var{ye}, @var{ie}] =} ode45 (@dots{}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20719
diff
changeset
|
30 ## @deftypefnx {} {@var{solution} =} ode45 (@dots{}) |
22939
54302b670139
doc: Document nargout=0 calling mode for ode23, ode45.
Rik <rik@octave.org>
parents:
22937
diff
changeset
|
31 ## @deftypefnx {} {} ode45 (@dots{}) |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
32 ## |
20548
25623ef2ff4f
doc: Rewrite docstrings for ode* family of functions.
Rik <rik@octave.org>
parents:
20543
diff
changeset
|
33 ## Solve a set of non-stiff Ordinary Differential Equations (non-stiff ODEs) |
20719
d903cccb8de8
doc: Periodic spellcheck of documentation.
Rik <rik@octave.org>
parents:
20634
diff
changeset
|
34 ## with the well known explicit @nospell{Dormand-Prince} method of order 4. |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
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 |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
37 ## name of the function that defines the ODE: @code{y' = f(t,y)}. The function |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
38 ## must accept two inputs where the first is time @var{t} and the second is a |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
39 ## column vector of unknowns @var{y}. |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
40 ## |
20548
25623ef2ff4f
doc: Rewrite docstrings for ode* family of functions.
Rik <rik@octave.org>
parents:
20543
diff
changeset
|
41 ## @var{trange} specifies the time interval over which the ODE will be |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
42 ## evaluated. Typically, it is a two-element vector specifying the initial and |
20548
25623ef2ff4f
doc: Rewrite docstrings for ode* family of functions.
Rik <rik@octave.org>
parents:
20543
diff
changeset
|
43 ## final times (@code{[tinit, tfinal]}). If there are more than two elements |
25623ef2ff4f
doc: Rewrite docstrings for ode* family of functions.
Rik <rik@octave.org>
parents:
20543
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. |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
46 ## |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
47 ## By default, @code{ode45} uses an adaptive timestep with the |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
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"}. |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
51 ## |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
52 ## @var{init} contains the initial value for the unknowns. If it is a row |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
53 ## vector then the solution @var{y} will be a matrix in which each column is |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
54 ## the solution for the corresponding initial value in @var{init}. |
20548
25623ef2ff4f
doc: Rewrite docstrings for ode* family of functions.
Rik <rik@octave.org>
parents:
20543
diff
changeset
|
55 ## |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
56 ## The optional fourth argument @var{ode_opt} specifies non-default options to |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
57 ## the ODE solver. It is a structure generated by @code{odeset}. |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
58 ## |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
59 ## The function typically returns two outputs. Variable @var{t} is a |
20548
25623ef2ff4f
doc: Rewrite docstrings for ode* family of functions.
Rik <rik@octave.org>
parents:
20543
diff
changeset
|
60 ## column vector and contains the times where the solution was found. The |
25623ef2ff4f
doc: Rewrite docstrings for ode* family of functions.
Rik <rik@octave.org>
parents:
20543
diff
changeset
|
61 ## output @var{y} is a matrix in which each column refers to a different |
25623ef2ff4f
doc: Rewrite docstrings for ode* family of functions.
Rik <rik@octave.org>
parents:
20543
diff
changeset
|
62 ## unknown of the problem and each row corresponds to a time in @var{t}. |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
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. |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
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} |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
78 ## contains an index indicating which Event function was triggered in the case |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
79 ## of multiple Event functions. |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
80 ## |
20719
d903cccb8de8
doc: Periodic spellcheck of documentation.
Rik <rik@octave.org>
parents:
20634
diff
changeset
|
81 ## Example: Solve the @nospell{Van der Pol} equation |
20548
25623ef2ff4f
doc: Rewrite docstrings for ode* family of functions.
Rik <rik@octave.org>
parents:
20543
diff
changeset
|
82 ## |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
83 ## @example |
20548
25623ef2ff4f
doc: Rewrite docstrings for ode* family of functions.
Rik <rik@octave.org>
parents:
20543
diff
changeset
|
84 ## @group |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
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:
20908
diff
changeset
|
86 ## [@var{t},@var{y}] = ode45 (fvdp, [0, 20], [2, 0]); |
20548
25623ef2ff4f
doc: Rewrite docstrings for ode* family of functions.
Rik <rik@octave.org>
parents:
20543
diff
changeset
|
87 ## @end group |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
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 ## @seealso{odeset, odeget, ode23, ode15s} |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
90 ## @end deftypefn |
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
91 |
30893
e1788b1a315f
maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
92 function varargout = ode45 (fcn, trange, init, varargin) |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
93 |
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
94 if (nargin < 3) |
20553
45151de7423f
maint: Clean up implementations of ode45.m, odeget.m, odeset.m.
Rik <rik@octave.org>
parents:
20549
diff
changeset
|
95 print_usage (); |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
96 endif |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
97 |
28045
13dba3c069f8
Update input validation for odeXXX.m functions.
Rik <rik@octave.org>
parents:
28041
diff
changeset
|
98 solver = "ode45"; |
22593
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
99 order = 5; # runge_kutta_45_dorpri uses local extrapolation |
20631
00caf63edcdf
maint: Remove obsolete ODE options from odeset/odeget/ode45.
Rik <rik@octave.org>
parents:
20620
diff
changeset
|
100 |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
101 if (nargin >= 4) |
20549
e368ce72a844
maint: Use Octave coding conventions for ode* functions.
Rik <rik@octave.org>
parents:
20548
diff
changeset
|
102 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
|
103 ## varargin{1:len} are parameters for fcn |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
104 odeopts = odeset (); |
22593
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
105 funarguments = varargin; |
22626 | 106 elseif (numel (varargin) > 1) |
22593
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
107 ## varargin{1} is an ODE options structure opt |
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
108 odeopts = varargin{1}; |
22626 | 109 funarguments = {varargin{2:numel (varargin)}}; |
28045
13dba3c069f8
Update input validation for odeXXX.m functions.
Rik <rik@octave.org>
parents:
28041
diff
changeset
|
110 else |
13dba3c069f8
Update input validation for odeXXX.m functions.
Rik <rik@octave.org>
parents:
28041
diff
changeset
|
111 ## 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
|
112 odeopts = varargin{1}; |
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
113 funarguments = {}; |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
114 endif |
20549
e368ce72a844
maint: Use Octave coding conventions for ode* functions.
Rik <rik@octave.org>
parents:
20548
diff
changeset
|
115 else # nargin == 3 |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
116 odeopts = odeset (); |
22593
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
117 funarguments = {}; |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
118 endif |
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
119 |
21443
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
20908
diff
changeset
|
120 if (! isnumeric (trange) || ! isvector (trange)) |
20631
00caf63edcdf
maint: Remove obsolete ODE options from odeset/odeget/ode45.
Rik <rik@octave.org>
parents:
20620
diff
changeset
|
121 error ("Octave:invalid-input-arg", |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
122 "ode45: TRANGE must be a numeric vector"); |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
123 endif |
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
124 |
22626 | 125 if (numel (trange) < 2) |
20631
00caf63edcdf
maint: Remove obsolete ODE options from odeset/odeget/ode45.
Rik <rik@octave.org>
parents:
20620
diff
changeset
|
126 error ("Octave:invalid-input-arg", |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
127 "ode45: TRANGE must contain at least 2 elements"); |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
128 elseif (trange(1) == trange(2)) |
20631
00caf63edcdf
maint: Remove obsolete ODE options from odeset/odeget/ode45.
Rik <rik@octave.org>
parents:
20620
diff
changeset
|
129 error ("Octave:invalid-input-arg", |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
130 "ode45: invalid time span, TRANGE(1) == TRANGE(2)"); |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
131 else |
22593
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
132 direction = sign (trange(2) - trange(1)); |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
133 endif |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
134 trange = trange(:); |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
135 |
21443
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
20908
diff
changeset
|
136 if (! isnumeric (init) || ! isvector (init)) |
20631
00caf63edcdf
maint: Remove obsolete ODE options from odeset/odeget/ode45.
Rik <rik@octave.org>
parents:
20620
diff
changeset
|
137 error ("Octave:invalid-input-arg", |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
138 "ode45: INIT must be a numeric vector"); |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
139 endif |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
140 init = init(:); |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
141 |
30893
e1788b1a315f
maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
142 if (ischar (fcn)) |
e1788b1a315f
maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
143 if (! exist (fcn)) |
28041
5e44268dca6f
Replace input validation relying on str2func with alternatives (bug #57351).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
144 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
|
145 ['ode45: function "' fcn '" not found']); |
28041
5e44268dca6f
Replace input validation relying on str2func with alternatives (bug #57351).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
146 endif |
30893
e1788b1a315f
maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
147 fcn = str2func (fcn); |
20613
27c091f4b66d
allow first argument in ode45 to be a string
Carlo de Falco <carlo.defalco@polimi.it>
parents:
20612
diff
changeset
|
148 endif |
30893
e1788b1a315f
maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
149 if (! is_function_handle (fcn)) |
20631
00caf63edcdf
maint: Remove obsolete ODE options from odeset/odeget/ode45.
Rik <rik@octave.org>
parents:
20620
diff
changeset
|
150 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
|
151 "ode45: FCN must be a valid function handle"); |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
152 endif |
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
153 |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
154 ## Start preprocessing, have a look which options are set in odeopts, |
20549
e368ce72a844
maint: Use Octave coding conventions for ode* functions.
Rik <rik@octave.org>
parents:
20548
diff
changeset
|
155 ## check if an invalid or unused option is set |
22626 | 156 [defaults, classes, attributes] = odedefaults (numel (init), |
157 trange(1), trange(end)); | |
22593
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
158 |
22660
7eb3f8ec1aed
Remove FIXME comment about missing tests for ignored ODE options.
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22659
diff
changeset
|
159 defaults = odeset (defaults, "Refine", 4); |
7eb3f8ec1aed
Remove FIXME comment about missing tests for ignored ODE options.
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22659
diff
changeset
|
160 |
7eb3f8ec1aed
Remove FIXME comment about missing tests for ignored ODE options.
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22659
diff
changeset
|
161 persistent ode45_ignore_options = ... |
7eb3f8ec1aed
Remove FIXME comment about missing tests for ignored ODE options.
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22659
diff
changeset
|
162 {"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
|
163 "MassSingular", "MaxOrder", "MvPattern", "Vectorized"}; |
7eb3f8ec1aed
Remove FIXME comment about missing tests for ignored ODE options.
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22659
diff
changeset
|
164 |
7eb3f8ec1aed
Remove FIXME comment about missing tests for ignored ODE options.
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22659
diff
changeset
|
165 defaults = rmfield (defaults, ode45_ignore_options); |
7eb3f8ec1aed
Remove FIXME comment about missing tests for ignored ODE options.
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22659
diff
changeset
|
166 classes = rmfield (classes, ode45_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 attributes = rmfield (attributes, ode45_ignore_options); |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
168 |
22626 | 169 odeopts = odemergeopts ("ode45", odeopts, defaults, classes, attributes); |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
170 |
22593
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
171 odeopts.funarguments = funarguments; |
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
172 odeopts.direction = direction; |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
173 |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
174 if (! isempty (odeopts.NonNegative)) |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
175 if (isempty (odeopts.Mass)) |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
176 odeopts.havenonnegative = true; |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
177 else |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
178 odeopts.havenonnegative = false; |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
179 warning ("Octave:invalid-input-arg", |
22626 | 180 ['ode45: option "NonNegative" is ignored', ... |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
181 " when mass matrix is set\n"]); |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
182 endif |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
183 else |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
184 odeopts.havenonnegative = false; |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
185 endif |
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
186 |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
187 if (isempty (odeopts.OutputFcn) && nargout == 0) |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
188 odeopts.OutputFcn = @odeplot; |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
189 odeopts.haveoutputfunction = true; |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
190 else |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
191 odeopts.haveoutputfunction = ! isempty (odeopts.OutputFcn); |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
192 endif |
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
193 |
22593
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
194 if (isempty (odeopts.InitialStep)) |
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
195 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
|
196 starting_stepsize (order, fcn, trange(1), init, |
22626 | 197 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
|
198 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
|
199 "on"), odeopts.funarguments); |
22625
081a201b77c7
Clean up ode options implementation to follow Octave coding standards.
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22605
diff
changeset
|
200 endif |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
201 |
28045
13dba3c069f8
Update input validation for odeXXX.m functions.
Rik <rik@octave.org>
parents:
28041
diff
changeset
|
202 if (! isempty (odeopts.Mass)) |
13dba3c069f8
Update input validation for odeXXX.m functions.
Rik <rik@octave.org>
parents:
28041
diff
changeset
|
203 if (isnumeric (odeopts.Mass)) |
13dba3c069f8
Update input validation for odeXXX.m functions.
Rik <rik@octave.org>
parents:
28041
diff
changeset
|
204 havemasshandle = false; |
13dba3c069f8
Update input validation for odeXXX.m functions.
Rik <rik@octave.org>
parents:
28041
diff
changeset
|
205 mass = odeopts.Mass; # constant mass |
13dba3c069f8
Update input validation for odeXXX.m functions.
Rik <rik@octave.org>
parents:
28041
diff
changeset
|
206 elseif (is_function_handle (odeopts.Mass)) |
13dba3c069f8
Update input validation for odeXXX.m functions.
Rik <rik@octave.org>
parents:
28041
diff
changeset
|
207 havemasshandle = true; # mass defined by a function handle |
13dba3c069f8
Update input validation for odeXXX.m functions.
Rik <rik@octave.org>
parents:
28041
diff
changeset
|
208 else |
13dba3c069f8
Update input validation for odeXXX.m functions.
Rik <rik@octave.org>
parents:
28041
diff
changeset
|
209 error ("Octave:invalid-input-arg", |
13dba3c069f8
Update input validation for odeXXX.m functions.
Rik <rik@octave.org>
parents:
28041
diff
changeset
|
210 '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
|
211 endif |
13dba3c069f8
Update input validation for odeXXX.m functions.
Rik <rik@octave.org>
parents:
28041
diff
changeset
|
212 else # no mass matrix - create a diag-matrix of ones for mass |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
213 havemasshandle = false; # mass = diag (ones (length (init), 1), 0); |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
214 endif |
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
215 |
21443
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
20908
diff
changeset
|
216 ## Starting the initialization of the core solver ode45 |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
217 |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
218 if (havemasshandle) # Handle only the dynamic mass matrix, |
22626 | 219 if (! strcmp (odeopts.MStateDependence, "none")) |
220 ### constant mass matrices have already | |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
221 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
|
222 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
|
223 \ fcn (t, x, odeopts.funarguments{:}); |
22626 | 224 else |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
225 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
|
226 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
|
227 \ fcn (t, x, odeopts.funarguments{:}); |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
228 endif |
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
229 endif |
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
230 |
31263
449ed6f427cb
ode45/23/23s: Implement Events, OutputFcn, & Refine options (bug #49408 and #63063)
Ken Marek <marek_ka@mercer.edu>
parents:
30893
diff
changeset
|
231 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
|
232 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
|
233 endif |
56d7d423aff9
Return intermediate integration times when single output argument used in ode solver (bug #49417).
Rik <rik@octave.org>
parents:
22655
diff
changeset
|
234 |
22593
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
235 solution = integrate_adaptive (@runge_kutta_45_dorpri, |
30893
e1788b1a315f
maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
236 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
|
237 |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
238 ## Postprocessing, do whatever when terminating integration algorithm |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
239 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
|
240 feval (odeopts.OutputFcn, [], [], "done", odeopts.funarguments{:}); |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
241 endif |
22593
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
242 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
|
243 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
|
244 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
|
245 odeopts.funarguments{:}); |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
246 endif |
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
247 |
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
248 ## 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
|
249 if (strcmpi (odeopts.Stats, "on")) |
21955
0f3e875d9078
Fix statistics on solution solving for ode45, ode23 (bug #48243).
jcorno <jacopo.corno@gmail.com>
parents:
21634
diff
changeset
|
250 nsteps = solution.cntloop; # cntloop from 2..end |
0f3e875d9078
Fix statistics on solution solving for ode45, ode23 (bug #48243).
jcorno <jacopo.corno@gmail.com>
parents:
21634
diff
changeset
|
251 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:
21634
diff
changeset
|
252 nfevals = 6 * solution.cntcycles + 1; # number of ode evaluations |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
253 ndecomps = 0; # number of LU decompositions |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
254 npds = 0; # number of partial derivatives |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
255 nlinsols = 0; # no. of linear systems solutions |
22934
bb452f84a299
Fix printing of solution stats in ode23/ode45 solvers (bug #49918).
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22755
diff
changeset
|
256 |
bb452f84a299
Fix printing of solution stats in ode23/ode45 solvers (bug #49918).
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22755
diff
changeset
|
257 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:
22755
diff
changeset
|
258 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:
22755
diff
changeset
|
259 printf ("Number of function calls: %d\n", nfevals); |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
260 endif |
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
261 |
20553
45151de7423f
maint: Clean up implementations of ode45.m, odeget.m, odeset.m.
Rik <rik@octave.org>
parents:
20549
diff
changeset
|
262 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
|
263 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
|
264 varargout{2} = solution.output_x; # Results are second output argument |
20553
45151de7423f
maint: Clean up implementations of ode45.m, odeget.m, odeset.m.
Rik <rik@octave.org>
parents:
20549
diff
changeset
|
265 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
|
266 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
|
267 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
|
268 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
|
269 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
|
270 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
|
271 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
|
272 varargout{1}.ie = solution.event{2}.'; # Index info which event occurred |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
273 endif |
22935
c9344df03da5
Allow case-insensitive option argument 'on' to ode solvers (bug #49918).
Rik <rik@octave.org>
parents:
22934
diff
changeset
|
274 if (strcmpi (odeopts.Stats, "on")) |
20553
45151de7423f
maint: Clean up implementations of ode45.m, odeget.m, odeset.m.
Rik <rik@octave.org>
parents:
20549
diff
changeset
|
275 varargout{1}.stats = struct (); |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
276 varargout{1}.stats.nsteps = nsteps; |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
277 varargout{1}.stats.nfailed = nfailed; |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
278 varargout{1}.stats.nfevals = nfevals; |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
279 varargout{1}.stats.npds = npds; |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
280 varargout{1}.stats.ndecomps = ndecomps; |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
281 varargout{1}.stats.nlinsols = nlinsols; |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
282 endif |
22937
2b2ac017c901
Fix undefined return argument for more than 2 outputs from ode solver (bug #49890).
Rik <rik@octave.org>
parents:
22660
diff
changeset
|
283 elseif (nargout > 2) |
20553
45151de7423f
maint: Clean up implementations of ode45.m, odeget.m, odeset.m.
Rik <rik@octave.org>
parents:
20549
diff
changeset
|
284 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
|
285 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
|
286 varargout{2} = solution.output_x; |
22593
dba5074bdc79
simplify options management in ode solvers
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22445
diff
changeset
|
287 if (! isempty (odeopts.Events)) |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
288 varargout{3} = solution.event{3}; # Time info when an event occurred |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
289 varargout{4} = solution.event{4}; # Results when an event occurred |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
290 varargout{5} = solution.event{2}; # Index info which event occurred |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
291 endif |
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
292 endif |
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
293 |
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
294 endfunction |
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
295 |
20549
e368ce72a844
maint: Use Octave coding conventions for ode* functions.
Rik <rik@octave.org>
parents:
20548
diff
changeset
|
296 |
21599
f29d68e24c5a
ode23.m, ode45.m: More reformatting of demos to Octave coding standards.
Rik <rik@octave.org>
parents:
21596
diff
changeset
|
297 %!demo |
f29d68e24c5a
ode23.m, ode45.m: More reformatting of demos to Octave coding standards.
Rik <rik@octave.org>
parents:
21596
diff
changeset
|
298 %! ## Demonstrate convergence order for ode45 |
f29d68e24c5a
ode23.m, ode45.m: More reformatting of demos to Octave coding standards.
Rik <rik@octave.org>
parents:
21596
diff
changeset
|
299 %! 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
|
300 %! 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
|
301 %! 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
|
302 %! [t, y] = ode45 (@(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
|
303 %! 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
|
304 %! 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
|
305 %! endfor |
f29d68e24c5a
ode23.m, ode45.m: More reformatting of demos to Octave coding standards.
Rik <rik@octave.org>
parents:
21596
diff
changeset
|
306 %! |
f29d68e24c5a
ode23.m, ode45.m: More reformatting of demos to Octave coding standards.
Rik <rik@octave.org>
parents:
21596
diff
changeset
|
307 %! ## Estimate order visually |
f29d68e24c5a
ode23.m, ode45.m: More reformatting of demos to Octave coding standards.
Rik <rik@octave.org>
parents:
21596
diff
changeset
|
308 %! loglog (h, tol, "-ob", |
22445
cbac595d23ac
Fix %!demo blocks for ode23 and ode45
Mike Miller <mtmiller@octave.org>
parents:
22323
diff
changeset
|
309 %! h, err, "-b", |
21599
f29d68e24c5a
ode23.m, ode45.m: More reformatting of demos to Octave coding standards.
Rik <rik@octave.org>
parents:
21596
diff
changeset
|
310 %! h, (h/h(end)) .^ 4 .* tol(end), "k--", |
22626 | 311 %! h, (h/h(end)) .^ 5 .* tol(end), "k-"); |
21599
f29d68e24c5a
ode23.m, ode45.m: More reformatting of demos to Octave coding standards.
Rik <rik@octave.org>
parents:
21596
diff
changeset
|
312 %! axis tight |
f29d68e24c5a
ode23.m, ode45.m: More reformatting of demos to Octave coding standards.
Rik <rik@octave.org>
parents:
21596
diff
changeset
|
313 %! xlabel ("h"); |
f29d68e24c5a
ode23.m, ode45.m: More reformatting of demos to Octave coding standards.
Rik <rik@octave.org>
parents:
21596
diff
changeset
|
314 %! ylabel ("err(h)"); |
f29d68e24c5a
ode23.m, ode45.m: More reformatting of demos to Octave coding standards.
Rik <rik@octave.org>
parents:
21596
diff
changeset
|
315 %! title ("Convergence plot for ode45"); |
f29d68e24c5a
ode23.m, ode45.m: More reformatting of demos to Octave coding standards.
Rik <rik@octave.org>
parents:
21596
diff
changeset
|
316 %! legend ("imposed tolerance", "ode45 (relative) error", |
f29d68e24c5a
ode23.m, ode45.m: More reformatting of demos to Octave coding standards.
Rik <rik@octave.org>
parents:
21596
diff
changeset
|
317 %! "order 4", "order 5", "location", "northwest"); |
22647
cf8ec7abb4ae
Clean up demo and test blocks for ode functions.
Rik <rik@octave.org>
parents:
22644
diff
changeset
|
318 %! |
cf8ec7abb4ae
Clean up demo and test blocks for ode functions.
Rik <rik@octave.org>
parents:
22644
diff
changeset
|
319 %! ## Estimate order numerically |
cf8ec7abb4ae
Clean up demo and test blocks for ode functions.
Rik <rik@octave.org>
parents:
22644
diff
changeset
|
320 %! 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
|
321 |
22934
bb452f84a299
Fix printing of solution stats in ode23/ode45 solvers (bug #49918).
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22755
diff
changeset
|
322 ## 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:
22755
diff
changeset
|
323 ## 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
|
324 %!function ydot = fpol (t, y, varargin) # The Van der Pol ODE |
22626 | 325 %! ydot = [y(2); (1 - y(1)^2) * y(2) - y(1)]; |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
326 %!endfunction |
21443
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
20908
diff
changeset
|
327 %!function ref = fref () # The computed reference solution |
22626 | 328 %! ref = [0.32331666704577, -1.83297456798624]; |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
329 %!endfunction |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
330 %!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
|
331 %! 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:
22755
diff
changeset
|
332 %! 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:
22755
diff
changeset
|
333 %! dir = ones (2,1); # does not seem to be exact |
20549
e368ce72a844
maint: Use Octave coding conventions for ode* functions.
Rik <rik@octave.org>
parents:
20548
diff
changeset
|
334 %!endfunction |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
335 %!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
|
336 %! 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:
22755
diff
changeset
|
337 %! 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:
22755
diff
changeset
|
338 %! dir = ones (2,1); # does not seem to be exact |
20549
e368ce72a844
maint: Use Octave coding conventions for ode* functions.
Rik <rik@octave.org>
parents:
20548
diff
changeset
|
339 %!endfunction |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
340 %!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:
22755
diff
changeset
|
341 %! mas = [1, 0; 0, 1]; # Dummy mass matrix for tests |
20549
e368ce72a844
maint: Use Octave coding conventions for ode* functions.
Rik <rik@octave.org>
parents:
20548
diff
changeset
|
342 %!endfunction |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
343 %!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:
22755
diff
changeset
|
344 %! mas = sparse ([1, 0; 0, 1]); # A sparse dummy matrix |
20549
e368ce72a844
maint: Use Octave coding conventions for ode* functions.
Rik <rik@octave.org>
parents:
20548
diff
changeset
|
345 %!endfunction |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
346 %!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
|
347 %! out = false; |
7efa2d0e22c9
More Matlab-compatible implementation of OutputFcn. Clean up odeplot.m.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
348 %! if (strcmp (flag, "init")) |
7efa2d0e22c9
More Matlab-compatible implementation of OutputFcn. Clean up odeplot.m.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
349 %! 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
|
350 %! error ('fout: step "init"'); |
7efa2d0e22c9
More Matlab-compatible implementation of OutputFcn. Clean up odeplot.m.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
351 %! endif |
22626 | 352 %! 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
|
353 %! # 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
|
354 %! 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
|
355 %! error ('fout: step "calc"'); |
7efa2d0e22c9
More Matlab-compatible implementation of OutputFcn. Clean up odeplot.m.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
356 %! endif |
7efa2d0e22c9
More Matlab-compatible implementation of OutputFcn. Clean up odeplot.m.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
357 %! elseif (strcmp (flag, "done")) |
7efa2d0e22c9
More Matlab-compatible implementation of OutputFcn. Clean up odeplot.m.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
358 %! if (! isempty (t)) |
7efa2d0e22c9
More Matlab-compatible implementation of OutputFcn. Clean up odeplot.m.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
359 %! warning ('fout: step "done"'); |
7efa2d0e22c9
More Matlab-compatible implementation of OutputFcn. Clean up odeplot.m.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
360 %! endif |
22626 | 361 %! else |
22639
7efa2d0e22c9
More Matlab-compatible implementation of OutputFcn. Clean up odeplot.m.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
362 %! error ("fout: invalid flag <%s>", flag); |
22626 | 363 %! endif |
20549
e368ce72a844
maint: Use Octave coding conventions for ode* functions.
Rik <rik@octave.org>
parents:
20548
diff
changeset
|
364 %!endfunction |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
365 %! |
20549
e368ce72a844
maint: Use Octave coding conventions for ode* functions.
Rik <rik@octave.org>
parents:
20548
diff
changeset
|
366 %!test # two output arguments |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
367 %! [t, y] = ode45 (@fpol, [0 2], [2 0]); |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
368 %! assert ([t(end), y(end,:)], [2, fref], 1e-2); |
20549
e368ce72a844
maint: Use Octave coding conventions for ode* functions.
Rik <rik@octave.org>
parents:
20548
diff
changeset
|
369 %!test # not too many steps |
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 %! [t, y] = ode45 (@fpol, [0 2], [2 0], odeset("Refine",1)); |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
371 %! assert (size (t) < 20); |
31263
449ed6f427cb
ode45/23/23s: Implement Events, OutputFcn, & Refine options (bug #49408 and #63063)
Ken Marek <marek_ka@mercer.edu>
parents:
30893
diff
changeset
|
372 %!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
|
373 %! [t1, y1] = ode45 (@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
|
374 %! [t2, y2] = ode45 (@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 %! [t3, y3] = ode45 (@fpol, [0 2], [2 0]); #default 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
|
376 %! s = ode45 (@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
|
377 %! assert (length (t2) == 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
|
378 %! 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
|
379 %! assert (length (s.x) == length (t1)); |
20549
e368ce72a844
maint: Use Octave coding conventions for ode* functions.
Rik <rik@octave.org>
parents:
20548
diff
changeset
|
380 %!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
|
381 %! 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
|
382 %! [t, y] = ode45 (fvdp, [0 2], [2 0]); |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
383 %! assert ([t(end), y(end,:)], [2, fref], 1e-2); |
20613
27c091f4b66d
allow first argument in ode45 to be a string
Carlo de Falco <carlo.defalco@polimi.it>
parents:
20612
diff
changeset
|
384 %!test # string instead of function |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
385 %! [t, y] = ode45 ("fpol", [0 2], [2 0]); |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
386 %! assert ([t(end), y(end,:)], [2, fref], 1e-2); |
20549
e368ce72a844
maint: Use Octave coding conventions for ode* functions.
Rik <rik@octave.org>
parents:
20548
diff
changeset
|
387 %!test # extra input arguments passed through |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
388 %! [t, y] = ode45 (@fpol, [0 2], [2 0], 12, 13, "KL"); |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
389 %! assert ([t(end), y(end,:)], [2, fref], 1e-2); |
20631
00caf63edcdf
maint: Remove obsolete ODE options from odeset/odeget/ode45.
Rik <rik@octave.org>
parents:
20620
diff
changeset
|
390 %!test # empty ODEOPT structure *but* extra input arguments |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
391 %! opt = odeset; |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
392 %! [t, y] = ode45 (@fpol, [0 2], [2 0], opt, 12, 13, "KL"); |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
393 %! assert ([t(end), y(end,:)], [2, fref], 1e-2); |
20549
e368ce72a844
maint: Use Octave coding conventions for ode* functions.
Rik <rik@octave.org>
parents:
20548
diff
changeset
|
394 %!test # Solve another anonymous function below zero |
e368ce72a844
maint: Use Octave coding conventions for ode* functions.
Rik <rik@octave.org>
parents:
20548
diff
changeset
|
395 %! vref = [0, 14.77810590694212]; |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
396 %! [t, y] = ode45 (@(t,y) y, [-2 0], 2); |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
397 %! assert ([t(end), y(end,:)], vref, 1e-1); |
20549
e368ce72a844
maint: Use Octave coding conventions for ode* functions.
Rik <rik@octave.org>
parents:
20548
diff
changeset
|
398 %!test # InitialStep option |
31263
449ed6f427cb
ode45/23/23s: Implement Events, OutputFcn, & Refine options (bug #49408 and #63063)
Ken Marek <marek_ka@mercer.edu>
parents:
30893
diff
changeset
|
399 %! opt = odeset ("InitialStep", 1e-8, "Refine", 1); |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
400 %! [t, y] = ode45 (@fpol, [0 0.2], [2 0], opt); |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
401 %! assert ([t(2)-t(1)], [1e-8], 1e-9); |
20549
e368ce72a844
maint: Use Octave coding conventions for ode* functions.
Rik <rik@octave.org>
parents:
20548
diff
changeset
|
402 %!test # MaxStep option |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
403 %! opt = odeset ("MaxStep", 1e-3); |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
404 %! sol = ode45 (@fpol, [0 0.2], [2 0], opt); |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
405 %! assert ([sol.x(5)-sol.x(4)], [1e-3], 1e-3); |
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
|
406 %!test # Solve with intermediate step |
04fc7e9c5f96
Disable Refine option of ode solvers for certain input/output combinations (partial fix bug #49408).
Rik <rik@octave.org>
parents:
22658
diff
changeset
|
407 %! [t, y] = ode45 (@fpol, [0 1 2], [2 0]); |
28912
0de38a6ef693
maint: Use Octave convention of space after function name in scripts dir.
Rik <rik@octave.org>
parents:
28896
diff
changeset
|
408 %! assert (any ((t-1) == 0)); |
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
|
409 %! assert ([t(end), y(end,:)], [2, fref], 1e-3); |
20549
e368ce72a844
maint: Use Octave coding conventions for ode* functions.
Rik <rik@octave.org>
parents:
20548
diff
changeset
|
410 %!test # Solve in backward direction starting at t=0 |
e368ce72a844
maint: Use Octave coding conventions for ode* functions.
Rik <rik@octave.org>
parents:
20548
diff
changeset
|
411 %! vref = [-1.205364552835178, 0.951542399860817]; |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
412 %! sol = ode45 (@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
|
413 %! assert ([sol.x(end); sol.y(:,end)], [-2; vref'], 1e-2); |
20549
e368ce72a844
maint: Use Octave coding conventions for ode* functions.
Rik <rik@octave.org>
parents:
20548
diff
changeset
|
414 %!test # Solve in backward direction starting at t=2 |
e368ce72a844
maint: Use Octave coding conventions for ode* functions.
Rik <rik@octave.org>
parents:
20548
diff
changeset
|
415 %! vref = [-1.205364552835178, 0.951542399860817]; |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
416 %! sol = ode45 (@fpol, [2 -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
|
417 %! assert ([sol.x(end); sol.y(:,end)], [-2; vref'], 1e-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
|
418 %!test # Solve in backward direction starting at t=2, with intermediate step |
20549
e368ce72a844
maint: Use Octave coding conventions for ode* functions.
Rik <rik@octave.org>
parents:
20548
diff
changeset
|
419 %! vref = [-1.205364552835178, 0.951542399860817]; |
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
|
420 %! [t, y] = ode45 (@fpol, [2 0 -2], fref); |
28912
0de38a6ef693
maint: Use Octave convention of space after function name in scripts dir.
Rik <rik@octave.org>
parents:
28896
diff
changeset
|
421 %! idx = find (y < 0, 1, "first") - 1; |
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
|
422 %! assert ([t(idx), y(idx,:)], [0,2,0], 1e-2); |
04fc7e9c5f96
Disable Refine option of ode solvers for certain input/output combinations (partial fix bug #49408).
Rik <rik@octave.org>
parents:
22658
diff
changeset
|
423 %! assert ([t(end), y(end,:)], [-2, vref], 1e-2); |
20549
e368ce72a844
maint: Use Octave coding conventions for ode* functions.
Rik <rik@octave.org>
parents:
20548
diff
changeset
|
424 %!test # Solve another anonymous function in backward direction |
e368ce72a844
maint: Use Octave coding conventions for ode* functions.
Rik <rik@octave.org>
parents:
20548
diff
changeset
|
425 %! vref = [-1, 0.367879437558975]; |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
426 %! sol = ode45 (@(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
|
427 %! assert ([sol.x(end); sol.y(:,end)], vref', 1e-3); |
20549
e368ce72a844
maint: Use Octave coding conventions for ode* functions.
Rik <rik@octave.org>
parents:
20548
diff
changeset
|
428 %!test # Solve another anonymous function below zero |
e368ce72a844
maint: Use Octave coding conventions for ode* functions.
Rik <rik@octave.org>
parents:
20548
diff
changeset
|
429 %! vref = [0, 14.77810590694212]; |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
430 %! sol = ode45 (@(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
|
431 %! assert ([sol.x(end); sol.y(:,end)], vref', 1e-3); |
20549
e368ce72a844
maint: Use Octave coding conventions for ode* functions.
Rik <rik@octave.org>
parents:
20548
diff
changeset
|
432 %!test # Solve in backward direction starting at t=0 with MaxStep option |
e368ce72a844
maint: Use Octave coding conventions for ode* functions.
Rik <rik@octave.org>
parents:
20548
diff
changeset
|
433 %! vref = [-1.205364552835178, 0.951542399860817]; |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
434 %! opt = odeset ("MaxStep", 1e-3); |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
435 %! sol = ode45 (@fpol, [0 -2], [2 0], opt); |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
436 %! 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
|
437 %! assert ([sol.x(end); sol.y(:,end)], [-2; vref'], 1e-3); |
20549
e368ce72a844
maint: Use Octave coding conventions for ode* functions.
Rik <rik@octave.org>
parents:
20548
diff
changeset
|
438 %!test # AbsTol option |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
439 %! opt = odeset ("AbsTol", 1e-5); |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
440 %! sol = ode45 (@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
|
441 %! assert ([sol.x(end); sol.y(:,end)], [2; fref'], 1e-3); |
20549
e368ce72a844
maint: Use Octave coding conventions for ode* functions.
Rik <rik@octave.org>
parents:
20548
diff
changeset
|
442 %!test # AbsTol and RelTol option |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
443 %! opt = odeset ("AbsTol", 1e-8, "RelTol", 1e-8); |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
444 %! sol = ode45 (@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
|
445 %! assert ([sol.x(end); sol.y(:,end)], [2; fref'], 1e-3); |
20549
e368ce72a844
maint: Use Octave coding conventions for ode* functions.
Rik <rik@octave.org>
parents:
20548
diff
changeset
|
446 %!test # RelTol and NormControl option -- higher accuracy |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
447 %! opt = odeset ("RelTol", 1e-8, "NormControl", "on"); |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
448 %! sol = ode45 (@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
|
449 %! assert ([sol.x(end); sol.y(:,end)], [2; fref'], 1e-5); |
20549
e368ce72a844
maint: Use Octave coding conventions for ode* functions.
Rik <rik@octave.org>
parents:
20548
diff
changeset
|
450 %!test # Keeps initial values while integrating |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
451 %! opt = odeset ("NonNegative", 2); |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
452 %! sol = ode45 (@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
|
453 %! assert ([sol.x(end); sol.y(:,end)], [2; 2; 0], 0.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
|
454 %!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
|
455 %! opt = odeset ("OutputFcn", @fout, "OutputSel", 1); |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
456 %! sol = ode45 (@fpol, [0 2], [2 0], opt); |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
457 %!test # Stats must add further elements in sol |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
458 %! 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:
22755
diff
changeset
|
459 %! stat_str = evalc ("sol = ode45 (@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:
22755
diff
changeset
|
460 %! assert (strncmp (stat_str, "Number of successful steps:", 27)); |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
461 %! assert (isfield (sol, "stats")); |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
462 %! assert (isfield (sol.stats, "nsteps")); |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
463 %!test # Events option add further elements in sol |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
464 %! opt = odeset ("Events", @feve); |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
465 %! sol = ode45 (@fpol, [0 10], [2 0], opt); |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
466 %! assert (isfield (sol, "ie")); |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
467 %! assert (sol.ie(1), 2); |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
468 %! assert (isfield (sol, "xe")); |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
469 %! assert (isfield (sol, "ye")); |
20549
e368ce72a844
maint: Use Octave coding conventions for ode* functions.
Rik <rik@octave.org>
parents:
20548
diff
changeset
|
470 %!test # Events option, now stop integration |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
471 %! opt = odeset ("Events", @fevn, "NormControl", "on"); |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
472 %! sol = ode45 (@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
|
473 %! assert ([sol.ie, sol.xe, sol.ye.'], |
20553
45151de7423f
maint: Clean up implementations of ode45.m, odeget.m, odeset.m.
Rik <rik@octave.org>
parents:
20549
diff
changeset
|
474 %! [2.0, 2.496110, -0.830550, -2.677589], 6e-1); |
20549
e368ce72a844
maint: Use Octave coding conventions for ode* functions.
Rik <rik@octave.org>
parents:
20548
diff
changeset
|
475 %!test # Events option, five output arguments |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
476 %! opt = odeset ("Events", @fevn, "NormControl", "on"); |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
477 %! [t, y, vxe, ye, vie] = ode45 (@fpol, [0 10], [2 0], opt); |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
478 %! assert ([vie, vxe, ye], |
20553
45151de7423f
maint: Clean up implementations of ode45.m, odeget.m, odeset.m.
Rik <rik@octave.org>
parents:
20549
diff
changeset
|
479 %! [2.0, 2.496110, -0.830550, -2.677589], 6e-1); |
20549
e368ce72a844
maint: Use Octave coding conventions for ode* functions.
Rik <rik@octave.org>
parents:
20548
diff
changeset
|
480 %!test # Mass option as function |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
481 %! opt = odeset ("Mass", @fmas); |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
482 %! sol = ode45 (@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); |
20549
e368ce72a844
maint: Use Octave coding conventions for ode* functions.
Rik <rik@octave.org>
parents:
20548
diff
changeset
|
484 %!test # Mass option as matrix |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
485 %! opt = odeset ("Mass", eye (2,2)); |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
486 %! sol = ode45 (@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); |
20549
e368ce72a844
maint: Use Octave coding conventions for ode* functions.
Rik <rik@octave.org>
parents:
20548
diff
changeset
|
488 %!test # Mass option as sparse matrix |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
489 %! opt = odeset ("Mass", sparse (eye (2,2))); |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
490 %! sol = ode45 (@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
|
491 %! assert ([sol.x(end); sol.y(:,end)], [2; fref'], 1e-3); |
20549
e368ce72a844
maint: Use Octave coding conventions for ode* functions.
Rik <rik@octave.org>
parents:
20548
diff
changeset
|
492 %!test # Mass option as function and sparse matrix |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
493 %! opt = odeset ("Mass", @fmsa); |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
494 %! sol = ode45 (@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
|
495 %! assert ([sol.x(end); sol.y(:,end)], [2; fref'], 1e-3); |
20549
e368ce72a844
maint: Use Octave coding conventions for ode* functions.
Rik <rik@octave.org>
parents:
20548
diff
changeset
|
496 %!test # Mass option as function and MStateDependence |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
497 %! opt = odeset ("Mass", @fmas, "MStateDependence", "strong"); |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
498 %! sol = ode45 (@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
|
499 %! 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:
20908
diff
changeset
|
500 |
22660
7eb3f8ec1aed
Remove FIXME comment about missing tests for ignored ODE options.
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22659
diff
changeset
|
501 ## 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
|
502 ## 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
|
503 ## |
7eb3f8ec1aed
Remove FIXME comment about missing tests for ignored ODE options.
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22659
diff
changeset
|
504 ## "BDF" |
7eb3f8ec1aed
Remove FIXME comment about missing tests for ignored ODE options.
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22659
diff
changeset
|
505 ## "InitialSlope" |
7eb3f8ec1aed
Remove FIXME comment about missing tests for ignored ODE options.
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22659
diff
changeset
|
506 ## "JPattern" |
7eb3f8ec1aed
Remove FIXME comment about missing tests for ignored ODE options.
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22659
diff
changeset
|
507 ## "Jacobian" |
7eb3f8ec1aed
Remove FIXME comment about missing tests for ignored ODE options.
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22659
diff
changeset
|
508 ## "MassSingular" |
7eb3f8ec1aed
Remove FIXME comment about missing tests for ignored ODE options.
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22659
diff
changeset
|
509 ## "MaxOrder" |
7eb3f8ec1aed
Remove FIXME comment about missing tests for ignored ODE options.
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22659
diff
changeset
|
510 ## "MvPattern" |
7eb3f8ec1aed
Remove FIXME comment about missing tests for ignored ODE options.
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22659
diff
changeset
|
511 ## "Vectorized" |
22626 | 512 |
22655
6b134d294d61
ode solvers: use ordinary transpose instead of Hermitian conjugate (bug #49410).
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22654
diff
changeset
|
513 %!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
|
514 %! sol = ode45 (@(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
|
515 %! assert (imag (sol.y), ones (size (sol.y))); |
31263
449ed6f427cb
ode45/23/23s: Implement Events, OutputFcn, & Refine options (bug #49408 and #63063)
Ken Marek <marek_ka@mercer.edu>
parents:
30893
diff
changeset
|
516 %! [x, y] = ode45 (@(x,y) 1, [0 1], 1i, odeset ("Refine", 1)); |
28929
9e43deb9bfc3
maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents:
28912
diff
changeset
|
517 %! 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
|
518 |
31263
449ed6f427cb
ode45/23/23s: Implement Events, OutputFcn, & Refine options (bug #49408 and #63063)
Ken Marek <marek_ka@mercer.edu>
parents:
30893
diff
changeset
|
519 ## FIXME: convert to demo or a visible=off test with failable assert/error |
449ed6f427cb
ode45/23/23s: Implement Events, OutputFcn, & Refine options (bug #49408 and #63063)
Ken Marek <marek_ka@mercer.edu>
parents:
30893
diff
changeset
|
520 ## statemments |
449ed6f427cb
ode45/23/23s: Implement Events, OutputFcn, & Refine options (bug #49408 and #63063)
Ken Marek <marek_ka@mercer.edu>
parents:
30893
diff
changeset
|
521 ##%!test # Make sure odeplot works (default OutputFcn when no return value) |
449ed6f427cb
ode45/23/23s: Implement Events, OutputFcn, & Refine options (bug #49408 and #63063)
Ken Marek <marek_ka@mercer.edu>
parents:
30893
diff
changeset
|
522 ##%! ode45 (@fpol, [0 2], [2 0]); |
449ed6f427cb
ode45/23/23s: Implement Events, OutputFcn, & Refine options (bug #49408 and #63063)
Ken Marek <marek_ka@mercer.edu>
parents:
30893
diff
changeset
|
523 ##%! close all |
449ed6f427cb
ode45/23/23s: Implement Events, OutputFcn, & Refine options (bug #49408 and #63063)
Ken Marek <marek_ka@mercer.edu>
parents:
30893
diff
changeset
|
524 |
28896
90fea9cc9caa
test: Add expected error message <Invalid call> to BIST tests for nargin.
Rik <rik@octave.org>
parents:
28892
diff
changeset
|
525 %!error <Invalid call> ode45 () |
90fea9cc9caa
test: Add expected error message <Invalid call> to BIST tests for nargin.
Rik <rik@octave.org>
parents:
28892
diff
changeset
|
526 %!error <Invalid call> ode45 (1) |
90fea9cc9caa
test: Add expected error message <Invalid call> to BIST tests for nargin.
Rik <rik@octave.org>
parents:
28892
diff
changeset
|
527 %!error <Invalid call> ode45 (1,2) |
22626 | 528 %!error <TRANGE must be a numeric> ode45 (@fpol, {[0 25]}, [3 15 1]) |
529 %!error <TRANGE must be a .* vector> ode45 (@fpol, [0 25; 25 0], [3 15 1]) | |
530 %!error <TRANGE must contain at least 2 elements> ode45 (@fpol, [1], [3 15 1]) | |
531 %!error <invalid time span> ode45 (@fpol, [1 1], [3 15 1]) | |
532 %!error <INIT must be a numeric> ode45 (@fpol, [0 25], {[3 15 1]}) | |
533 %!error <INIT must be a .* vector> ode45 (@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
|
534 %!error <FCN must be a valid function handle> ode45 (1, [0 25], [3 15 1]) |