annotate scripts/ode/ode15s.m @ 25803:23483673ba43

Use is_function_handle instead of isa (x, "function_handle"). * ov-fcn-handle.cc (Fis_function_handle): Add BIST test for an inline function. * gradient.m, isequal.m, isequaln.m, __makeinfo__.m, nthargout.m, decic.m, ode15i.m, ode15s.m, ode23.m, ode45.m, check_default_input.m, fplot.m, __ezplot__.m, __alltohandles__.m, qmr.m, spfun.m, args.tst: Use is_function_handle instead of isa (x, "function_handle").
author Rik <rik@octave.org>
date Wed, 15 Aug 2018 15:29:11 -0700
parents 476fc012d09a
children 52ff6e691e49
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
25054
6652d3823428 maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents: 25026
diff changeset
1 ## Copyright (C) 2016-2018 Francesco Faccio <francesco.faccio@mail.polimi.it>
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
2 ##
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
3 ## This file is part of Octave.
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
4 ##
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24012
diff changeset
5 ## Octave is free software: you can redistribute it and/or modify it
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
6 ## 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: 24012
diff changeset
7 ## the Free Software Foundation, either version 3 of the License, or
24007
e8a74d95b4f3 maint: Use same format for Copyright statement throught code base.
Rik <rik@octave.org>
parents: 23023
diff changeset
8 ## (at your option) any later version.
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
9 ##
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
24007
e8a74d95b4f3 maint: Use same format for Copyright statement throught code base.
Rik <rik@octave.org>
parents: 23023
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e8a74d95b4f3 maint: Use same format for Copyright statement throught code base.
Rik <rik@octave.org>
parents: 23023
diff changeset
13 ## GNU General Public License for more details.
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
14 ##
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
16 ## 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: 24012
diff changeset
17 ## <https://www.gnu.org/licenses/>.
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
18
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
19 ## -*- texinfo -*-
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
20 ## @deftypefn {} {[@var{t}, @var{y}] =} ode15s (@var{fun}, @var{trange}, @var{y0})
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
21 ## @deftypefnx {} {[@var{t}, @var{y}] =} ode15s (@var{fun}, @var{trange}, @var{y0}, @var{ode_opt})
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
22 ## @deftypefnx {} {[@var{t}, @var{y}, @var{te}, @var{ye}, @var{ie}] =} ode15s (@dots{})
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
23 ## @deftypefnx {} {@var{solution} =} ode15s (@dots{})
22941
d92ec2901770 Make ode15i,ode15s doc consistent with other ode functions.
Rik <rik@octave.org>
parents: 22938
diff changeset
24 ## @deftypefnx {} {} ode15s (@dots{})
25113
476fc012d09a doc: Shorten very long first sentences of docstrings (bug #53388).
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
25 ## Solve a set of stiff Ordinary Differential Equations (ODEs) or stiff
476fc012d09a doc: Shorten very long first sentences of docstrings (bug #53388).
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
26 ## semi-explicit index 1 Differential Algebraic Equations (DAEs).
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
27 ##
25113
476fc012d09a doc: Shorten very long first sentences of docstrings (bug #53388).
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
28 ## @code{ode15s} uses a variable step, variable order BDF (Backward
476fc012d09a doc: Shorten very long first sentences of docstrings (bug #53388).
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
29 ## Differentiation Formula) method that ranges from order 1 to 5.
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
30 ##
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
31 ## @var{fun} is a function handle, inline function, or string containing the
22941
d92ec2901770 Make ode15i,ode15s doc consistent with other ode functions.
Rik <rik@octave.org>
parents: 22938
diff changeset
32 ## name of the function that defines the ODE: @code{y' = f(t,y)}. The function
d92ec2901770 Make ode15i,ode15s doc consistent with other ode functions.
Rik <rik@octave.org>
parents: 22938
diff changeset
33 ## must accept two inputs where the first is time @var{t} and the second is a
d92ec2901770 Make ode15i,ode15s doc consistent with other ode functions.
Rik <rik@octave.org>
parents: 22938
diff changeset
34 ## column vector of unknowns @var{y}.
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
35 ##
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
36 ## @var{trange} specifies the time interval over which the ODE will be
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
37 ## evaluated. Typically, it is a two-element vector specifying the initial and
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
38 ## final times (@code{[tinit, tfinal]}). If there are more than two elements
22941
d92ec2901770 Make ode15i,ode15s doc consistent with other ode functions.
Rik <rik@octave.org>
parents: 22938
diff changeset
39 ## then the solution will also be evaluated at these intermediate time
d92ec2901770 Make ode15i,ode15s doc consistent with other ode functions.
Rik <rik@octave.org>
parents: 22938
diff changeset
40 ## instances.
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
41 ##
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
42 ## @var{init} contains the initial value for the unknowns. If it is a row
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
43 ## vector then the solution @var{y} will be a matrix in which each column is
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
44 ## the solution for the corresponding initial value in @var{init}.
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
45 ##
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
46 ## The optional fourth argument @var{ode_opt} specifies non-default options to
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
47 ## the ODE solver. It is a structure generated by @code{odeset}.
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
48 ##
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
49 ## The function typically returns two outputs. Variable @var{t} is a
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
50 ## column vector and contains the times where the solution was found. The
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
51 ## output @var{y} is a matrix in which each column refers to a different
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
52 ## unknown of the problem and each row corresponds to a time in @var{t}.
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
53 ##
25026
f886561f9696 doc: improve differential eqtn docs and mention ode15i/ode15s (bug #51965).
Colin Macdonald <cbm@m.fsf.org>
parents: 24534
diff changeset
54 ## 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
55 ## 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
56 ## 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
57 ## 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
58 ## @w{@code{fieldnames (@var{solution})}} to see the other fields and
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
59 ## additional information returned.
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
60 ##
25026
f886561f9696 doc: improve differential eqtn docs and mention ode15i/ode15s (bug #51965).
Colin Macdonald <cbm@m.fsf.org>
parents: 24534
diff changeset
61 ## If no output arguments are requested, and no @code{OutputFcn} is specified
f886561f9696 doc: improve differential eqtn docs and mention ode15i/ode15s (bug #51965).
Colin Macdonald <cbm@m.fsf.org>
parents: 24534
diff changeset
62 ## in @var{ode_opt}, then the @code{OutputFcn} is set to @code{odeplot} and the
f886561f9696 doc: improve differential eqtn docs and mention ode15i/ode15s (bug #51965).
Colin Macdonald <cbm@m.fsf.org>
parents: 24534
diff changeset
63 ## results of the solver are plotted immediately.
22941
d92ec2901770 Make ode15i,ode15s doc consistent with other ode functions.
Rik <rik@octave.org>
parents: 22938
diff changeset
64 ##
25026
f886561f9696 doc: improve differential eqtn docs and mention ode15i/ode15s (bug #51965).
Colin Macdonald <cbm@m.fsf.org>
parents: 24534
diff changeset
65 ## 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
66 ## 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
67 ## @var{ye} holds the value of the solution at time @var{te}. @var{ie}
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
68 ## contains an index indicating which Event function was triggered in the case
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
69 ## of multiple Event functions.
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
70 ##
25026
f886561f9696 doc: improve differential eqtn docs and mention ode15i/ode15s (bug #51965).
Colin Macdonald <cbm@m.fsf.org>
parents: 24534
diff changeset
71 ## Example: Solve @nospell{Robertson's} equations:
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
72 ##
25026
f886561f9696 doc: improve differential eqtn docs and mention ode15i/ode15s (bug #51965).
Colin Macdonald <cbm@m.fsf.org>
parents: 24534
diff changeset
73 ## @smallexample
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
74 ## @group
25026
f886561f9696 doc: improve differential eqtn docs and mention ode15i/ode15s (bug #51965).
Colin Macdonald <cbm@m.fsf.org>
parents: 24534
diff changeset
75 ## function r = robertson_dae (@var{t}, @var{y})
f886561f9696 doc: improve differential eqtn docs and mention ode15i/ode15s (bug #51965).
Colin Macdonald <cbm@m.fsf.org>
parents: 24534
diff changeset
76 ## r = [ -0.04*@var{y}(1) + 1e4*@var{y}(2)*@var{y}(3)
f886561f9696 doc: improve differential eqtn docs and mention ode15i/ode15s (bug #51965).
Colin Macdonald <cbm@m.fsf.org>
parents: 24534
diff changeset
77 ## 0.04*@var{y}(1) - 1e4*@var{y}(2)*@var{y}(3) - 3e7*@var{y}(2)^2
f886561f9696 doc: improve differential eqtn docs and mention ode15i/ode15s (bug #51965).
Colin Macdonald <cbm@m.fsf.org>
parents: 24534
diff changeset
78 ## @var{y}(1) + @var{y}(2) + @var{y}(3) - 1 ];
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
79 ## endfunction
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
80 ## opt = odeset ("Mass", [1 0 0; 0 1 0; 0 0 0], "MStateDependence", "none");
25026
f886561f9696 doc: improve differential eqtn docs and mention ode15i/ode15s (bug #51965).
Colin Macdonald <cbm@m.fsf.org>
parents: 24534
diff changeset
81 ## [@var{t},@var{y}] = ode15s (@@robertson_dae, [0, 1e3], [1; 0; 0], opt);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
82 ## @end group
25026
f886561f9696 doc: improve differential eqtn docs and mention ode15i/ode15s (bug #51965).
Colin Macdonald <cbm@m.fsf.org>
parents: 24534
diff changeset
83 ## @end smallexample
f886561f9696 doc: improve differential eqtn docs and mention ode15i/ode15s (bug #51965).
Colin Macdonald <cbm@m.fsf.org>
parents: 24534
diff changeset
84 ## @seealso{decic, odeset, odeget, ode23, ode45}
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
85 ## @end deftypefn
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
86
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
87 function varargout = ode15s (fun, trange, y0, varargin)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
88
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
89 if (nargin < 3)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
90 print_usage ();
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
91 endif
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22902
diff changeset
92
25026
f886561f9696 doc: improve differential eqtn docs and mention ode15i/ode15s (bug #51965).
Colin Macdonald <cbm@m.fsf.org>
parents: 24534
diff changeset
93 solver = "ode15s";
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
94 ## Check fun, trange, y0, yp0
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
95 fun = check_default_input (fun, trange, solver, y0);
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22902
diff changeset
96
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
97 n = numel (y0);
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22902
diff changeset
98
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
99 if (nargin > 3)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
100 options = varargin{1};
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
101 else
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
102 options = odeset ();
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
103 endif
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
104
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
105 if (! isempty (options.Mass))
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
106 if (ischar (options.Mass))
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
107 try
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
108 options.Mass = str2func (options.Mass);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
109 catch
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
110 warning (lasterr);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
111 end_try_catch
25803
23483673ba43 Use is_function_handle instead of isa (x, "function_handle").
Rik <rik@octave.org>
parents: 25113
diff changeset
112 if (! is_function_handle (options.Mass))
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
113 error ("Octave:invalid-input-arg",
22933
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
114 [solver ": invalid value assigned to field 'Mass'"]);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
115 endif
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
116 endif
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22902
diff changeset
117 endif
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
118
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
119 if (! isempty (options.Jacobian))
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
120 if (ischar (options.Jacobian))
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
121 try
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
122 options.Jacobian = str2func (options.Jacobian);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
123 catch
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
124 warning (lasterr);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
125 end_try_catch
25803
23483673ba43 Use is_function_handle instead of isa (x, "function_handle").
Rik <rik@octave.org>
parents: 25113
diff changeset
126 if (! is_function_handle (options.Jacobian))
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
127 error ("Octave:invalid-input-arg",
22933
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
128 [solver ": invalid value assigned to field 'Jacobian'"]);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
129 endif
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
130 endif
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
131 endif
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
132
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
133 if (! isempty (options.OutputFcn))
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
134 if (ischar (options.OutputFcn))
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
135 try
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
136 options.OutputFcn = str2func (options.OutputFcn);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
137 catch
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
138 warning (lasterr);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
139 end_try_catch
25803
23483673ba43 Use is_function_handle instead of isa (x, "function_handle").
Rik <rik@octave.org>
parents: 25113
diff changeset
140 if (! is_function_handle (options.OutputFcn))
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
141 error ("Octave:invalid-input-arg",
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
142 [solver ": invalid value assigned to field '%s'"], "OutputFcn");
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
143 endif
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
144 endif
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
145 endif
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
146
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
147 if (! isempty (options.Events))
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
148 if (ischar (options.Events))
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
149 try
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
150 options.Events = str2func (options.Events);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
151 catch
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
152 warning (lasterr);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
153 end_try_catch
25803
23483673ba43 Use is_function_handle instead of isa (x, "function_handle").
Rik <rik@octave.org>
parents: 25113
diff changeset
154 if (! is_function_handle (options.Events))
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
155 error ("Octave:invalid-input-arg",
22933
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
156 [solver ": invalid value assigned to field 'Events'"]);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
157 endif
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
158 endif
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
159 endif
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
160
22933
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
161 [defaults, classes, attributes] = odedefaults (n, trange(1), trange(end));
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
162
22933
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
163 classes = odeset (classes, "Vectorized", {});
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
164 attributes = odeset (attributes, "Jacobian", {}, "Vectorized", {});
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
165
22933
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
166 options = odemergeopts ("ode15s", options, defaults,
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
167 classes, attributes, solver);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
168
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
169 ## Mass
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
170 options.havemassfun = false;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
171 options.havestatedep = false;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
172 options.havetimedep = false;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
173 options.havemasssparse = false;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
174
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
175 if (! isempty (options.Mass))
25803
23483673ba43 Use is_function_handle instead of isa (x, "function_handle").
Rik <rik@octave.org>
parents: 25113
diff changeset
176 if (is_function_handle (options.Mass))
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
177 options.havemassfun = true;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
178 if (nargin (options.Mass) == 2)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
179 options.havestatedep = true;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
180 M = options.Mass (trange(1), y0);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
181 options.havemasssparse = issparse (M);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
182 if (any (size (M) != [n n]) || ! isnumeric (M) || ! isreal (M))
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
183 error ("Octave:invalid-input-arg",
22941
d92ec2901770 Make ode15i,ode15s doc consistent with other ode functions.
Rik <rik@octave.org>
parents: 22938
diff changeset
184 [solver ": invalid value assigned to field 'Mass'"]);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
185 endif
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
186 elseif (nargin (options.Mass) == 1)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
187 options.havetimedep = true;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
188 M = options.Mass (trange(1));
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
189 options.havemasssparse = issparse (M);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
190 if (any (size (M) != [n n]) || ! isnumeric (M) || ! isreal (M))
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
191 error ("Octave:invalid-input-arg",
22941
d92ec2901770 Make ode15i,ode15s doc consistent with other ode functions.
Rik <rik@octave.org>
parents: 22938
diff changeset
192 [solver ": invalid value assigned to field 'Mass'"]);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
193 endif
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
194 else
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
195 error ("Octave:invalid-input-arg",
22941
d92ec2901770 Make ode15i,ode15s doc consistent with other ode functions.
Rik <rik@octave.org>
parents: 22938
diff changeset
196 [solver ": invalid value assigned to field 'Mass'"]);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
197 endif
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
198 elseif (ismatrix (options.Mass))
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
199 options.havemasssparse = issparse (options.Mass);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
200 if (any (size (options.Mass) != [n n]) ||
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
201 ! isnumeric (options.Mass) || ! isreal (options.Mass))
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
202 error ("Octave:invalid-input-arg",
22941
d92ec2901770 Make ode15i,ode15s doc consistent with other ode functions.
Rik <rik@octave.org>
parents: 22938
diff changeset
203 [solver ": invalid value assigned to field 'Mass'"]);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
204 endif
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22902
diff changeset
205 else
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
206 error ("Octave:invalid-input-arg",
22941
d92ec2901770 Make ode15i,ode15s doc consistent with other ode functions.
Rik <rik@octave.org>
parents: 22938
diff changeset
207 [solver ": invalid value assigned to field 'Mass'"]);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
208 endif
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
209 endif
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
210
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
211 ## Jacobian
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
212 options.havejac = false;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
213 options.havejacsparse = false;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
214 options.havejacfun = false;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
215
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
216 if (! isempty (options.Jacobian))
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
217 options.havejac = true;
25803
23483673ba43 Use is_function_handle instead of isa (x, "function_handle").
Rik <rik@octave.org>
parents: 25113
diff changeset
218 if (is_function_handle (options.Jacobian))
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
219 options.havejacfun = true;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
220 if (nargin (options.Jacobian) == 2)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
221 [A] = options.Jacobian (trange(1), y0);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
222 if (issparse (A))
22933
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
223 options.havejacsparse = true; # Jac is sparse fun
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
224 endif
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
225 if (any (size (A) != [n n]) || ! isnumeric (A) || ! isreal (A))
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
226 error ("Octave:invalid-input-arg",
22941
d92ec2901770 Make ode15i,ode15s doc consistent with other ode functions.
Rik <rik@octave.org>
parents: 22938
diff changeset
227 [solver ": invalid value assigned to field 'Jacobian'"]);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
228 endif
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
229 else
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
230 error ("Octave:invalid-input-arg",
22941
d92ec2901770 Make ode15i,ode15s doc consistent with other ode functions.
Rik <rik@octave.org>
parents: 22938
diff changeset
231 [solver ": invalid value assigned to field 'Jacobian'"]);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
232 endif
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
233 elseif (ismatrix (options.Jacobian))
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
234 if (issparse (options.Jacobian))
22933
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
235 options.havejacsparse = true; # Jac is sparse matrix
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
236 endif
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
237 if (! issquare (options.Jacobian))
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
238 error ("Octave:invalid-input-arg",
22941
d92ec2901770 Make ode15i,ode15s doc consistent with other ode functions.
Rik <rik@octave.org>
parents: 22938
diff changeset
239 [solver ": invalid value assigned to field 'Jacobian'"]);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
240 endif
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
241 else
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
242 error ("Octave:invalid-input-arg",
22941
d92ec2901770 Make ode15i,ode15s doc consistent with other ode functions.
Rik <rik@octave.org>
parents: 22938
diff changeset
243 [solver ": invalid value assigned to field 'Jacobian'"]);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
244 endif
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
245 endif
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
246
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
247 ## Derivative of M(t,y) for implicit problem not implemented yet
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
248 if (! isempty (options.Mass) && ! isempty (options.Jacobian))
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
249 if (options.MStateDependence != "none" || options.havestatedep == true)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
250 options.havejac = false;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
251 options.Jacobian = [];
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
252 warning ("ode15s:mass_state_dependent_provided",
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
253 ["with MStateDependence != 'none' an internal", ...
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
254 " approximation of Jacobian Matrix will be used.", ...
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
255 " Set MStateDependence equal to 'none' if you want ", ...
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
256 " to provide a constant or time-dependent Jacobian"]);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
257 endif
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
258 endif
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22902
diff changeset
259
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
260 ## Use sparse methods only if all matrices are sparse
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
261 if (! options.havemasssparse)
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22902
diff changeset
262 options.havejacsparse = false;
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22902
diff changeset
263 endif
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22902
diff changeset
264
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22902
diff changeset
265 ## If Mass or Jacobian is fun, then new Jacobian is fun
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
266 if (options.havejac)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
267 if (options.havejacfun || options.havetimedep)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
268 options.Jacobian = @ (t, y, yp) wrapjacfun (t, y, yp,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
269 options.Jacobian,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
270 options.Mass,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
271 options.havetimedep,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
272 options.havejacfun);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
273 options.havejacfun = true;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
274 else ## All matrices are constant
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
275 options.Jacobian = {[- options.Jacobian], [options.Mass]};
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22902
diff changeset
276
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
277 endif
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
278 endif
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
279
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
280 ## Abstol and Reltol
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
281 options.haveabstolvec = false;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
282
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
283 if (numel (options.AbsTol) != 1 && numel (options.AbsTol) != n)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
284 error ("Octave:invalid-input-arg",
22941
d92ec2901770 Make ode15i,ode15s doc consistent with other ode functions.
Rik <rik@octave.org>
parents: 22938
diff changeset
285 [solver ": invalid value assigned to field 'AbsTol'"]);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
286 elseif (numel (options.AbsTol) == n)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
287 options.haveabstolvec = true;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
288 endif
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
289
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
290 ## Stats
22935
c9344df03da5 Allow case-insensitive option argument 'on' to ode solvers (bug #49918).
Rik <rik@octave.org>
parents: 22933
diff changeset
291 options.havestats = strcmpi (options.Stats, "on");
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
292
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
293 ## Don't use Refine when the output is a structure
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
294 if (nargout == 1)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
295 options.Refine = 1;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
296 endif
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
297
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
298 ## OutputFcn and OutputSel
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
299 if (isempty (options.OutputFcn) && nargout == 0)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
300 options.OutputFcn = @odeplot;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
301 options.haveoutputfunction = true;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
302 else
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
303 options.haveoutputfunction = ! isempty (options.OutputFcn);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
304 endif
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22902
diff changeset
305
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
306 options.haveoutputselection = ! isempty (options.OutputSel);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
307 if (options.haveoutputselection)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
308 options.OutputSel = options.OutputSel - 1;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
309 endif
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
310
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
311 ## Events
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
312 options.haveeventfunction = ! isempty (options.Events);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
313
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
314 yp0 = options.InitialSlope;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
315
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
316 [t, y, te, ye, ie] = __ode15__ (@ (t, y, yp) wrap (t, y, yp, options.Mass,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
317 options.havetimedep,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
318 options.havestatedep,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
319 fun),
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
320 trange, y0, yp0, options);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
321
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
322 if (nargout == 2)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
323 varargout{1} = t;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
324 varargout{2} = y;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
325 elseif (nargout == 1)
22933
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
326 varargout{1}.x = t; # Time stamps are saved in field x
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
327 varargout{1}.y = y; # Results are saved in field y
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22902
diff changeset
328 varargout{1}.solver = solver;
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
329 if (options.haveeventfunction)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
330 varargout{1}.xe = te; # Time info when an event occurred
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
331 varargout{1}.ye = ye; # Results when an event occurred
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
332 varargout{1}.ie = ie; # Index info which event occurred
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
333 endif
22938
a88ceac2aa53 Fix undefined return argument for more than 2 outputs from ode15i,ode15s.
Rik <rik@octave.org>
parents: 22936
diff changeset
334 elseif (nargout > 2)
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
335 varargout = cell (1,5);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
336 varargout{1} = t;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
337 varargout{2} = y;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
338 if (options.haveeventfunction)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
339 varargout{3} = te; # Time info when an event occurred
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
340 varargout{4} = ye; # Results when an event occurred
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
341 varargout{5} = ie; # Index info which event occurred
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
342 endif
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
343 endif
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
344
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
345 endfunction
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
346
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
347 function res = wrap (t, y, yp, Mass, havetimedep, havestatedep, fun)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
348
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22902
diff changeset
349 if (! isempty (Mass) && havestatedep)
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
350 res = Mass (t, y) * yp - fun (t, y);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
351 elseif (! isempty (Mass) && havetimedep)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
352 res = Mass (t) * yp - fun (t, y);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
353 elseif (! isempty (Mass))
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
354 res = Mass * yp - fun (t, y);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
355 else
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
356 res = yp - fun (t, y);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
357 endif
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
358
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
359 endfunction
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
360
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
361 function [jac, jact] = wrapjacfun (t, y, yp, Jac, Mass,
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22902
diff changeset
362 havetimedep, havejacfun)
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
363 if (havejacfun)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
364 jac = - Jac (t, y);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
365 else
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
366 jac = - Jac;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
367 endif
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
368
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22902
diff changeset
369 if (! isempty (Mass) && havetimedep)
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
370 jact = Mass (t);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
371 elseif (! isempty (Mass))
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
372 jact = Mass;
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
373 else
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
374 jact = speye (numel (y));
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
375 endif
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22902
diff changeset
376
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
377 endfunction
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
378
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
379
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
380 %!demo
22933
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
381 %! ## Solve Robertson's equations with ode15s
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
382 %! fun = @ (t, y) [-0.04*y(1) + 1e4*y(2).*y(3);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
383 %! 0.04*y(1) - 1e4*y(2).*y(3) - 3e7*y(2).^2;
22936
f2a1fc90a903 * ode15s.m: More minor style fixes in tests.
John W. Eaton <jwe@octave.org>
parents: 22935
diff changeset
384 %! y(1) + y(2) + y(3) - 1];
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
385 %!
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
386 %! y0 = [1; 0; 0];
22936
f2a1fc90a903 * ode15s.m: More minor style fixes in tests.
John W. Eaton <jwe@octave.org>
parents: 22935
diff changeset
387 %! tspan = [0, 4*logspace(-6, 6)];
f2a1fc90a903 * ode15s.m: More minor style fixes in tests.
John W. Eaton <jwe@octave.org>
parents: 22935
diff changeset
388 %! M = [1, 0, 0; 0, 1, 0; 0, 0, 0];
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22902
diff changeset
389 %!
22936
f2a1fc90a903 * ode15s.m: More minor style fixes in tests.
John W. Eaton <jwe@octave.org>
parents: 22935
diff changeset
390 %! options = odeset ("RelTol", 1e-4, "AbsTol", [1e-6, 1e-10, 1e-6],
22933
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
391 %! "MStateDependence", "none", "Mass", M);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
392 %!
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
393 %! [t, y] = ode15s (fun, tspan, y0, options);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
394 %!
22933
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
395 %! y(:,2) = 1e4 * y(:,2);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
396 %! figure (2);
22933
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
397 %! semilogx (t, y, "o");
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
398 %! xlabel ("time");
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
399 %! ylabel ("species concentration");
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
400 %! title ("Robertson DAE problem with a Conservation Law");
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
401 %! legend ("y1", "y2", "y3");
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
402
22933
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
403 %!function ydot = fpol (t, y) # Van der Pol equation
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
404 %! ydot = [y(2); (1 - y(1)^2) * y(2) - y(1)];
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
405 %!endfunction
22928
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
406 %!
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
407 %!function ref = fref () # The computed reference sol
22933
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
408 %! ref = [0.32331666704577, -1.83297456798624];
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
409 %!endfunction
22928
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
410 %!
22933
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
411 %!function jac = fjac (t, y) # its Jacobian
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
412 %! jac = [0, 1; -1 - 2 * y(1) * y(2), 1 - y(1)^2];
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
413 %!endfunction
22928
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
414 %!
22933
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
415 %!function jac = fjcc (t, y) # sparse type
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
416 %! jac = sparse ([0, 1; -1 - 2 * y(1) * y(2), 1 - y(1)^2]);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
417 %!endfunction
22928
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
418 %!
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
419 %!function mas = fmas (t, y)
22933
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
420 %! mas = [1, 0; 0, 1]; # Dummy mass matrix for tests
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
421 %!endfunction
22928
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
422 %!
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
423 %!function mas = fmsa (t, y)
22933
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
424 %! mas = sparse ([1, 0; 0, 1]); # A sparse dummy matrix
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
425 %!endfunction
22928
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
426 %!
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
427 %!function res = rob (t, y)
22933
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
428 %! res = [-0.04*y(1) + 1e4*y(2).*y(3);
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
429 %! 0.04*y(1) - 1e4*y(2).*y(3) - 3e7*y(2).^2;
22936
f2a1fc90a903 * ode15s.m: More minor style fixes in tests.
John W. Eaton <jwe@octave.org>
parents: 22935
diff changeset
430 %! y(1) + y(2) + y(3) - 1];
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
431 %!endfunction
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
432 %!
22933
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
433 %!function refrob = frefrob ()
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
434 %! refrob = [100, 0.617234887614937, 0.000006153591397, 0.382758958793666];
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
435 %!endfunction
22928
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
436 %!
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
437 %!function [val, isterminal, direction] = feve (t, y)
22933
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
438 %! isterminal = [0, 1];
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
439 %! if (t < 1e1)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
440 %! val = [-1, -2];
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
441 %! else
22933
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
442 %! val = [1, 3];
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
443 %! endif
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22902
diff changeset
444 %!
22933
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
445 %! direction = [1, 0];
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
446 %!endfunction
22928
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
447 %!
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
448 %!function masrob = massdensefunstate (t, y)
22936
f2a1fc90a903 * ode15s.m: More minor style fixes in tests.
John W. Eaton <jwe@octave.org>
parents: 22935
diff changeset
449 %! masrob = [1, 0, 0; 0, 1, 0; 0, 0, 0];
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
450 %!endfunction
22928
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
451 %!
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
452 %!function masrob = masssparsefunstate (t, y)
22936
f2a1fc90a903 * ode15s.m: More minor style fixes in tests.
John W. Eaton <jwe@octave.org>
parents: 22935
diff changeset
453 %! masrob = sparse ([1, 0, 0; 0, 1, 0; 0, 0, 0]);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
454 %!endfunction
22928
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
455 %!
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
456 %!function masrob = massdensefuntime (t)
22936
f2a1fc90a903 * ode15s.m: More minor style fixes in tests.
John W. Eaton <jwe@octave.org>
parents: 22935
diff changeset
457 %! masrob = [1, 0, 0; 0, 1, 0; 0, 0, 0];
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
458 %!endfunction
22928
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
459 %!
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
460 %!function masrob = masssparsefuntime (t)
22936
f2a1fc90a903 * ode15s.m: More minor style fixes in tests.
John W. Eaton <jwe@octave.org>
parents: 22935
diff changeset
461 %! masrob = sparse ([1, 0, 0; 0, 1, 0; 0, 0, 0]);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
462 %!endfunction
22928
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
463 %!
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
464 %!function jac = jacfundense (t, y)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
465 %! jac = [-0.04, 1e4*y(3), 1e4*y(2);
22933
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
466 %! 0.04, -1e4*y(3)-6e7*y(2), -1e4*y(2);
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
467 %! 1, 1, 1];
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
468 %!endfunction
22928
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
469 %!
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
470 %!function jac = jacfunsparse (t, y)
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
471 %! jac = sparse([-0.04, 1e4*y(3), 1e4*y(2);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
472 %! 0.04, -1e4*y(3)-6e7*y(2), -1e4*y(2);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
473 %! 1, 1, 1]);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
474 %!endfunction
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
475
22928
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
476 %!testif HAVE_SUNDIALS
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22902
diff changeset
477 %! opt = odeset ("MStateDependence", "none",
22936
f2a1fc90a903 * ode15s.m: More minor style fixes in tests.
John W. Eaton <jwe@octave.org>
parents: 22935
diff changeset
478 %! "Mass", [1, 0, 0; 0, 1, 0; 0, 0, 0]);
f2a1fc90a903 * ode15s.m: More minor style fixes in tests.
John W. Eaton <jwe@octave.org>
parents: 22935
diff changeset
479 %! [t, y] = ode15s (@rob, [0, 100], [1; 0; 0], opt);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
480 %! assert ([t(end), y(end,:)], frefrob, 1e-3);
22928
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
481
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
482 %!testif HAVE_SUNDIALS
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22902
diff changeset
483 %! opt = odeset ("MStateDependence", "none",
22936
f2a1fc90a903 * ode15s.m: More minor style fixes in tests.
John W. Eaton <jwe@octave.org>
parents: 22935
diff changeset
484 %! "Mass", sparse ([1, 0, 0; 0, 1, 0; 0, 0, 0]));
f2a1fc90a903 * ode15s.m: More minor style fixes in tests.
John W. Eaton <jwe@octave.org>
parents: 22935
diff changeset
485 %! [t, y] = ode15s (@rob, [0, 100], [1; 0; 0], opt);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
486 %! assert ([t(end), y(end,:)], frefrob, 1e-3);
22928
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
487
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
488 %!testif HAVE_SUNDIALS
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22902
diff changeset
489 %! opt = odeset ("MStateDependence", "none",
22933
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
490 %! "Mass", @massdensefunstate);
22936
f2a1fc90a903 * ode15s.m: More minor style fixes in tests.
John W. Eaton <jwe@octave.org>
parents: 22935
diff changeset
491 %! [t, y] = ode15s (@rob, [0, 100], [1; 0; 0], opt);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
492 %! assert ([t(end), y(end,:)], frefrob, 1e-3);
22928
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
493
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
494 %!testif HAVE_SUNDIALS
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22902
diff changeset
495 %! opt = odeset ("MStateDependence", "none",
22933
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
496 %! "Mass", @masssparsefunstate);
22936
f2a1fc90a903 * ode15s.m: More minor style fixes in tests.
John W. Eaton <jwe@octave.org>
parents: 22935
diff changeset
497 %! [t, y] = ode15s (@rob, [0, 100], [1; 0; 0], opt);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
498 %! assert ([t(end), y(end,:)], frefrob, 1e-3);
22928
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
499
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
500 %!testif HAVE_SUNDIALS
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22902
diff changeset
501 %! opt = odeset ("MStateDependence", "none",
22933
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
502 %! "Mass", "massdensefuntime");
22936
f2a1fc90a903 * ode15s.m: More minor style fixes in tests.
John W. Eaton <jwe@octave.org>
parents: 22935
diff changeset
503 %! [t, y] = ode15s (@rob, [0, 100], [1; 0; 0], opt);
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22902
diff changeset
504 %! assert ([t(end), y(end,:)], frefrob, 1e-3);
22928
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
505
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
506 %!testif HAVE_SUNDIALS
22933
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
507 %! opt = odeset ("MStateDependence", "none",
22936
f2a1fc90a903 * ode15s.m: More minor style fixes in tests.
John W. Eaton <jwe@octave.org>
parents: 22935
diff changeset
508 %! "Mass", [1, 0, 0; 0, 1, 0; 0, 0, 0],
22933
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
509 %! "Jacobian", "jacfundense");
22936
f2a1fc90a903 * ode15s.m: More minor style fixes in tests.
John W. Eaton <jwe@octave.org>
parents: 22935
diff changeset
510 %! [t, y] = ode15s (@rob, [0, 100], [1; 0; 0], opt);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
511 %! assert ([t(end), y(end,:)], frefrob, 1e-3);
22928
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
512
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
513 %!testif HAVE_SUNDIALS
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22902
diff changeset
514 %! opt = odeset ("MStateDependence", "none",
22936
f2a1fc90a903 * ode15s.m: More minor style fixes in tests.
John W. Eaton <jwe@octave.org>
parents: 22935
diff changeset
515 %! "Mass", sparse ([1, 0, 0; 0, 1, 0; 0, 0, 0]),
22933
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
516 %! "Jacobian", @jacfundense);
22936
f2a1fc90a903 * ode15s.m: More minor style fixes in tests.
John W. Eaton <jwe@octave.org>
parents: 22935
diff changeset
517 %! [t, y] = ode15s (@rob, [0, 100], [1; 0; 0], opt);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
518 %! assert ([t(end), y(end,:)], frefrob, 1e-3);
22928
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
519
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
520 %!testif HAVE_SUNDIALS
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
521 %! warning ("off", "ode15s:mass_state_dependent_provided", "local");
22933
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
522 %! opt = odeset ("MStateDependence", "none",
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
523 %! "Mass", @massdensefunstate,
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
524 %! "Jacobian", @jacfundense);
22936
f2a1fc90a903 * ode15s.m: More minor style fixes in tests.
John W. Eaton <jwe@octave.org>
parents: 22935
diff changeset
525 %! [t, y] = ode15s (@rob, [0, 100], [1; 0; 0], opt);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
526 %! assert ([t(end), y(end,:)], frefrob, 1e-3);
22928
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
527
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
528 %!testif HAVE_SUNDIALS
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
529 %! warning ("off", "ode15s:mass_state_dependent_provided", "local");
22933
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
530 %! opt = odeset ("MStateDependence", "none",
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
531 %! "Mass", @masssparsefunstate,
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
532 %! "Jacobian", @jacfundense);
22936
f2a1fc90a903 * ode15s.m: More minor style fixes in tests.
John W. Eaton <jwe@octave.org>
parents: 22935
diff changeset
533 %! [t, y] = ode15s (@rob, [0, 100], [1; 0; 0], opt);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
534 %! assert ([t(end), y(end,:)], frefrob, 1e-3);
22928
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
535
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
536 %!testif HAVE_SUNDIALS
22933
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
537 %! opt = odeset ("MStateDependence", "none",
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
538 %! "Mass", @massdensefuntime,
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
539 %! "Jacobian", @jacfundense);
22936
f2a1fc90a903 * ode15s.m: More minor style fixes in tests.
John W. Eaton <jwe@octave.org>
parents: 22935
diff changeset
540 %! [t, y] = ode15s (@rob, [0, 100], [1; 0; 0], opt);
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22902
diff changeset
541 %! assert ([t(end), y(end,:)], frefrob, 1e-3);
22933
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
542 %! opt = odeset ("MStateDependence", "none",
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
543 %! "Mass", "masssparsefuntime",
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
544 %! "Jacobian", "jacfundense");
22936
f2a1fc90a903 * ode15s.m: More minor style fixes in tests.
John W. Eaton <jwe@octave.org>
parents: 22935
diff changeset
545 %! [t, y] = ode15s (@rob, [0, 100], [1; 0; 0], opt);
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22902
diff changeset
546 %! assert ([t(end), y(end,:)], frefrob, 1e-3);
22928
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
547
23023
63a12df71848 avoid sparse jacobian tests for ode15i and ode15s if IDAKLU is missing
John W. Eaton <jwe@octave.org>
parents: 22941
diff changeset
548 %!testif HAVE_SUNDIALS_IDAKLU
22933
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
549 %! opt = odeset ("MStateDependence", "none",
22936
f2a1fc90a903 * ode15s.m: More minor style fixes in tests.
John W. Eaton <jwe@octave.org>
parents: 22935
diff changeset
550 %! "Mass", [1, 0, 0; 0, 1, 0; 0, 0, 0],
22933
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
551 %! "Jacobian", @jacfunsparse);
22936
f2a1fc90a903 * ode15s.m: More minor style fixes in tests.
John W. Eaton <jwe@octave.org>
parents: 22935
diff changeset
552 %! [t, y] = ode15s (@rob, [0, 100], [1; 0; 0], opt);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
553 %! assert ([t(end), y(end,:)], frefrob, 1e-3);
22928
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
554
23023
63a12df71848 avoid sparse jacobian tests for ode15i and ode15s if IDAKLU is missing
John W. Eaton <jwe@octave.org>
parents: 22941
diff changeset
555 %!testif HAVE_SUNDIALS_IDAKLU
22933
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
556 %! opt = odeset ("MStateDependence", "none",
22936
f2a1fc90a903 * ode15s.m: More minor style fixes in tests.
John W. Eaton <jwe@octave.org>
parents: 22935
diff changeset
557 %! "Mass", sparse ([1, 0, 0; 0, 1, 0; 0, 0, 0]),
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22902
diff changeset
558 %! "Jacobian", @jacfunsparse);
22936
f2a1fc90a903 * ode15s.m: More minor style fixes in tests.
John W. Eaton <jwe@octave.org>
parents: 22935
diff changeset
559 %! [t, y] = ode15s (@rob, [0, 100], [1; 0; 0], opt);
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22902
diff changeset
560 %! assert ([t(end), y(end,:)], frefrob, 1e-3);
22928
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
561
23023
63a12df71848 avoid sparse jacobian tests for ode15i and ode15s if IDAKLU is missing
John W. Eaton <jwe@octave.org>
parents: 22941
diff changeset
562 %!testif HAVE_SUNDIALS_IDAKLU
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
563 %! warning ("off", "ode15s:mass_state_dependent_provided", "local");
22933
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
564 %! opt = odeset ("MStateDependence", "none",
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
565 %! "Mass", @massdensefunstate,
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
566 %! "Jacobian", @jacfunsparse);
22936
f2a1fc90a903 * ode15s.m: More minor style fixes in tests.
John W. Eaton <jwe@octave.org>
parents: 22935
diff changeset
567 %! [t, y] = ode15s (@rob, [0, 100], [1; 0; 0], opt);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
568 %! assert ([t(end), y(end,:)], frefrob, 1e-3);
22928
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
569
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
570 %!testif HAVE_SUNDIALS
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
571 %! warning ("off", "ode15s:mass_state_dependent_provided", "local");
22933
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
572 %! opt = odeset ("MStateDependence", "none",
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
573 %! "Mass", @masssparsefunstate,
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
574 %! "Jacobian", @jacfunsparse);
22936
f2a1fc90a903 * ode15s.m: More minor style fixes in tests.
John W. Eaton <jwe@octave.org>
parents: 22935
diff changeset
575 %! [t, y] = ode15s (@rob, [0, 100], [1; 0; 0], opt);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
576 %! assert ([t(end), y(end,:)], frefrob, 1e-3);
22928
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
577
23023
63a12df71848 avoid sparse jacobian tests for ode15i and ode15s if IDAKLU is missing
John W. Eaton <jwe@octave.org>
parents: 22941
diff changeset
578 %!testif HAVE_SUNDIALS_IDAKLU
22933
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
579 %! opt = odeset ("MStateDependence", "none",
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
580 %! "Mass", @massdensefuntime,
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
581 %! "Jacobian", @jacfunsparse);
22936
f2a1fc90a903 * ode15s.m: More minor style fixes in tests.
John W. Eaton <jwe@octave.org>
parents: 22935
diff changeset
582 %! [t, y] = ode15s (@rob, [0, 100], [1; 0; 0], opt);
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22902
diff changeset
583 %! assert ([t(end), y(end,:)], frefrob, 1e-3);
22928
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
584
23023
63a12df71848 avoid sparse jacobian tests for ode15i and ode15s if IDAKLU is missing
John W. Eaton <jwe@octave.org>
parents: 22941
diff changeset
585 %!testif HAVE_SUNDIALS_IDAKLU
22933
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
586 %! opt = odeset ("MStateDependence", "none",
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
587 %! "Mass", @masssparsefuntime,
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
588 %! "Jacobian", @jacfunsparse);
22936
f2a1fc90a903 * ode15s.m: More minor style fixes in tests.
John W. Eaton <jwe@octave.org>
parents: 22935
diff changeset
589 %! [t, y] = ode15s (@rob, [0, 100], [1; 0; 0], opt);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
590 %! assert ([t(end), y(end,:)], frefrob, 1e-3);
22928
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
591
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
592 ## two output arguments
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
593 %!testif HAVE_SUNDIALS
22936
f2a1fc90a903 * ode15s.m: More minor style fixes in tests.
John W. Eaton <jwe@octave.org>
parents: 22935
diff changeset
594 %! [t, y] = ode15s (@fpol, [0, 2], [2, 0]);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
595 %! assert ([t(end), y(end,:)], [2, fref], 1e-2);
22928
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
596
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
597 ## anonymous function instead of real function
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
598 %!testif HAVE_SUNDIALS
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
599 %! fvdb = @(t,y) [y(2); (1 - y(1)^2) * y(2) - y(1)];
22936
f2a1fc90a903 * ode15s.m: More minor style fixes in tests.
John W. Eaton <jwe@octave.org>
parents: 22935
diff changeset
600 %! [t, y] = ode15s (fvdb, [0, 2], [2, 0]);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
601 %! assert ([t(end), y(end,:)], [2, fref], 1e-2);
22928
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
602
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
603 ## Solve another anonymous function below zero
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
604 %!testif HAVE_SUNDIALS
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
605 %! ref = [0, 14.77810590694212];
22936
f2a1fc90a903 * ode15s.m: More minor style fixes in tests.
John W. Eaton <jwe@octave.org>
parents: 22935
diff changeset
606 %! [t, y] = ode15s (@(t,y) y, [-2, 0], 2);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
607 %! assert ([t(end), y(end,:)], ref, 5e-2);
22928
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
608
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
609 ## InitialStep option
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
610 %!testif HAVE_SUNDIALS
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
611 %! opt = odeset ("InitialStep", 1e-8);
22936
f2a1fc90a903 * ode15s.m: More minor style fixes in tests.
John W. Eaton <jwe@octave.org>
parents: 22935
diff changeset
612 %! [t, y] = ode15s (@fpol, [0, 0.2], [2, 0], opt);
22933
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
613 %! assert (t(2)-t(1), 1e-8, 1e-9);
22928
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
614
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
615 ## MaxStep option
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
616 %!testif HAVE_SUNDIALS
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
617 %! opt = odeset ("MaxStep", 1e-3);
22936
f2a1fc90a903 * ode15s.m: More minor style fixes in tests.
John W. Eaton <jwe@octave.org>
parents: 22935
diff changeset
618 %! sol = ode15s (@fpol, [0, 0.2], [2, 0], opt);
22933
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
619 %! assert (sol.x(5)-sol.x(4), 1e-3, 1e-3);
22928
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
620
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
621 ## Solve in backward direction starting at t=0
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
622 %!testif HAVE_SUNDIALS
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
623 %! ref = [-1.205364552835178, 0.951542399860817];
22936
f2a1fc90a903 * ode15s.m: More minor style fixes in tests.
John W. Eaton <jwe@octave.org>
parents: 22935
diff changeset
624 %! sol = ode15s (@fpol, [0 -2], [2, 0]);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
625 %! assert ([sol.x(end), sol.y(end,:)], [-2, ref], 5e-3);
22928
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
626
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
627 ## Solve in backward direction starting at t=2
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
628 %!testif HAVE_SUNDIALS
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
629 %! ref = [-1.205364552835178, 0.951542399860817];
22936
f2a1fc90a903 * ode15s.m: More minor style fixes in tests.
John W. Eaton <jwe@octave.org>
parents: 22935
diff changeset
630 %! sol = ode15s (@fpol, [2, 0 -2], fref);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
631 %! assert ([sol.x(end), sol.y(end,:)], [-2, ref], 3e-2);
22928
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
632
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
633 ## Solve another anonymous function in backward direction
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
634 %!testif HAVE_SUNDIALS
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
635 %! ref = [-1, 0.367879437558975];
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
636 %! sol = ode15s (@(t,y) y, [0 -1], 1);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
637 %! assert ([sol.x(end), sol.y(end,:)], ref, 1e-2);
22928
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
638
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
639 ## Solve another anonymous function below zero
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
640 %!testif HAVE_SUNDIALS
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
641 %! ref = [0, 14.77810590694212];
22936
f2a1fc90a903 * ode15s.m: More minor style fixes in tests.
John W. Eaton <jwe@octave.org>
parents: 22935
diff changeset
642 %! sol = ode15s (@(t,y) y, [-2, 0], 2);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
643 %! assert ([sol.x(end), sol.y(end,:)], ref, 5e-2);
22928
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
644
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
645 ## Solve in backward direction starting at t=0 with MaxStep option
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
646 %!testif HAVE_SUNDIALS
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
647 %! ref = [-1.205364552835178, 0.951542399860817];
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
648 %! opt = odeset ("MaxStep", 1e-3);
22936
f2a1fc90a903 * ode15s.m: More minor style fixes in tests.
John W. Eaton <jwe@octave.org>
parents: 22935
diff changeset
649 %! sol = ode15s (@fpol, [0 -2], [2, 0], opt);
22933
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
650 %! assert (abs (sol.x(8)-sol.x(7)), 1e-3, 1e-3);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
651 %! assert ([sol.x(end), sol.y(end,:)], [-2, ref], 1e-3);
22928
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
652
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
653 ## AbsTol option
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
654 %!testif HAVE_SUNDIALS
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
655 %! opt = odeset ("AbsTol", 1e-5);
22936
f2a1fc90a903 * ode15s.m: More minor style fixes in tests.
John W. Eaton <jwe@octave.org>
parents: 22935
diff changeset
656 %! sol = ode15s (@fpol, [0, 2], [2, 0], opt);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
657 %! assert ([sol.x(end), sol.y(end,:)], [2, fref], 4e-3);
22928
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
658
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
659 ## AbsTol and RelTol option
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
660 %!testif HAVE_SUNDIALS
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
661 %! opt = odeset ("AbsTol", 1e-8, "RelTol", 1e-8);
22936
f2a1fc90a903 * ode15s.m: More minor style fixes in tests.
John W. Eaton <jwe@octave.org>
parents: 22935
diff changeset
662 %! sol = ode15s (@fpol, [0, 2], [2, 0], opt);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
663 %! assert ([sol.x(end), sol.y(end,:)], [2, fref], 1e-3);
22928
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
664
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
665 ## RelTol option -- higher accuracy
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
666 %!testif HAVE_SUNDIALS
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
667 %! opt = odeset ("RelTol", 1e-8);
22936
f2a1fc90a903 * ode15s.m: More minor style fixes in tests.
John W. Eaton <jwe@octave.org>
parents: 22935
diff changeset
668 %! sol = ode15s (@fpol, [0, 2], [2, 0], opt);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
669 %! assert ([sol.x(end), sol.y(end,:)], [2, fref], 1e-4);
22928
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
670
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
671 ## Mass option as function
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
672 %!testif HAVE_SUNDIALS
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
673 %! opt = odeset ("Mass", @fmas, "MStateDependence", "none");
22936
f2a1fc90a903 * ode15s.m: More minor style fixes in tests.
John W. Eaton <jwe@octave.org>
parents: 22935
diff changeset
674 %! sol = ode15s (@fpol, [0, 2], [2, 0], opt);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
675 %! assert ([sol.x(end), sol.y(end,:)], [2, fref], 3e-3);
22928
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
676
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
677 ## Mass option as matrix
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
678 %!testif HAVE_SUNDIALS
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
679 %! opt = odeset ("Mass", eye (2,2), "MStateDependence", "none");
22936
f2a1fc90a903 * ode15s.m: More minor style fixes in tests.
John W. Eaton <jwe@octave.org>
parents: 22935
diff changeset
680 %! sol = ode15s (@fpol, [0, 2], [2, 0], opt);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
681 %! assert ([sol.x(end), sol.y(end,:)], [2, fref], 3e-3);
22928
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
682
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
683 ## Mass option as sparse matrix
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
684 %!testif HAVE_SUNDIALS
23023
63a12df71848 avoid sparse jacobian tests for ode15i and ode15s if IDAKLU is missing
John W. Eaton <jwe@octave.org>
parents: 22941
diff changeset
685 %! opt = odeset ("Mass", speye (2), "MStateDependence", "none");
22936
f2a1fc90a903 * ode15s.m: More minor style fixes in tests.
John W. Eaton <jwe@octave.org>
parents: 22935
diff changeset
686 %! sol = ode15s (@fpol, [0, 2], [2, 0], opt);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
687 %! assert ([sol.x(end), sol.y(end,:)], [2, fref], 3e-3);
22928
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
688
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
689 ## Mass option as function and sparse matrix
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
690 %!testif HAVE_SUNDIALS
22933
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
691 %! opt = odeset ("Mass", "fmsa", "MStateDependence", "none");
22936
f2a1fc90a903 * ode15s.m: More minor style fixes in tests.
John W. Eaton <jwe@octave.org>
parents: 22935
diff changeset
692 %! sol = ode15s (@fpol, [0, 2], [2, 0], opt);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
693 %! assert ([sol.x(end), sol.y(end,:)], [2, fref], 3e-3);
22928
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
694
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
695 ## Refine
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
696 %!testif HAVE_SUNDIALS
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
697 %! opt2 = odeset ("Refine", 3, "Mass", @massdensefunstate,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
698 %! "MStateDependence", "none");
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
699 %! opt1 = odeset ("Mass", @massdensefunstate, "MStateDependence", "none");
22936
f2a1fc90a903 * ode15s.m: More minor style fixes in tests.
John W. Eaton <jwe@octave.org>
parents: 22935
diff changeset
700 %! [t, y] = ode15s (@rob, [0, 100], [1; 0; 0], opt1);
f2a1fc90a903 * ode15s.m: More minor style fixes in tests.
John W. Eaton <jwe@octave.org>
parents: 22935
diff changeset
701 %! [t2, y2] = ode15s (@rob, [0, 100], [1; 0; 0], opt2);
22933
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
702 %! assert (numel (t2), numel (t) * 3, 3);
22928
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
703
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
704 ## Refine ignored if numel (trange) > 2
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
705 %!testif HAVE_SUNDIALS
22933
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
706 %! opt2 = odeset ("Refine", 3, "Mass", "massdensefunstate",
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
707 %! "MStateDependence", "none");
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
708 %! opt1 = odeset ("Mass", @massdensefunstate, "MStateDependence", "none");
22936
f2a1fc90a903 * ode15s.m: More minor style fixes in tests.
John W. Eaton <jwe@octave.org>
parents: 22935
diff changeset
709 %! [t, y] = ode15s ("rob", [0, 10, 100], [1; 0; 0], opt1);
f2a1fc90a903 * ode15s.m: More minor style fixes in tests.
John W. Eaton <jwe@octave.org>
parents: 22935
diff changeset
710 %! [t2, y2] = ode15s ("rob", [0, 10, 100], [1; 0; 0], opt2);
22933
c3428bb9aca9 ode15i.m, ode15s.m: Follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22928
diff changeset
711 %! assert (numel (t2), numel (t));
22928
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
712
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
713 ## Events option add further elements in sol
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
714 %!testif HAVE_SUNDIALS
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
715 %! opt = odeset ("Events", @feve, "Mass", @massdensefunstate,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
716 %! "MStateDependence", "none");
22936
f2a1fc90a903 * ode15s.m: More minor style fixes in tests.
John W. Eaton <jwe@octave.org>
parents: 22935
diff changeset
717 %! sol = ode15s (@rob, [0, 100], [1; 0; 0], opt);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
718 %! assert (isfield (sol, "ie"));
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
719 %! assert (sol.ie, [0;1]);
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
720 %! assert (isfield (sol, "xe"));
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
721 %! assert (isfield (sol, "ye"));
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
722 %! assert (sol.x(end), 10, 1);
22928
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
723
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
724 ## Events option, five output arguments
dec22bceafa2 use testif HAVE_SUNDIALS for ode15 tests
John W. Eaton <jwe@octave.org>
parents: 22910
diff changeset
725 %!testif HAVE_SUNDIALS
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
726 %! opt = odeset ("Events", @feve, "Mass", @massdensefunstate,
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
727 %! "MStateDependence", "none");
22936
f2a1fc90a903 * ode15s.m: More minor style fixes in tests.
John W. Eaton <jwe@octave.org>
parents: 22935
diff changeset
728 %! [t, y, te, ye, ie] = ode15s (@rob, [0, 100], [1; 0; 0], opt);
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22902
diff changeset
729 %! assert ([t(end), te', ie'], [10, 10, 10, 0, 1], [1, 0.5, 0.5, 0, 0]);
24008
6e7bb85e32b8 Allow ode15s and ode15i to work with row initial vectors (bug #50192).
Marco Caliari <marco.caliari@univr.it>
parents: 24007
diff changeset
730
6e7bb85e32b8 Allow ode15s and ode15i to work with row initial vectors (bug #50192).
Marco Caliari <marco.caliari@univr.it>
parents: 24007
diff changeset
731 ## Initial solution as row vector
6e7bb85e32b8 Allow ode15s and ode15i to work with row initial vectors (bug #50192).
Marco Caliari <marco.caliari@univr.it>
parents: 24007
diff changeset
732 %!testif HAVE_SUNDIALS
6e7bb85e32b8 Allow ode15s and ode15i to work with row initial vectors (bug #50192).
Marco Caliari <marco.caliari@univr.it>
parents: 24007
diff changeset
733 %! A = zeros (2);
6e7bb85e32b8 Allow ode15s and ode15i to work with row initial vectors (bug #50192).
Marco Caliari <marco.caliari@univr.it>
parents: 24007
diff changeset
734 %! [tout, yout] = ode15s (@(t, y) A * y, [0, 1], [1, 1]);
6e7bb85e32b8 Allow ode15s and ode15i to work with row initial vectors (bug #50192).
Marco Caliari <marco.caliari@univr.it>
parents: 24007
diff changeset
735 %! assert (yout, ones (18, 2))
6e7bb85e32b8 Allow ode15s and ode15i to work with row initial vectors (bug #50192).
Marco Caliari <marco.caliari@univr.it>
parents: 24007
diff changeset
736
6e7bb85e32b8 Allow ode15s and ode15i to work with row initial vectors (bug #50192).
Marco Caliari <marco.caliari@univr.it>
parents: 24007
diff changeset
737 %!testif HAVE_SUNDIALS
6e7bb85e32b8 Allow ode15s and ode15i to work with row initial vectors (bug #50192).
Marco Caliari <marco.caliari@univr.it>
parents: 24007
diff changeset
738 %! A = zeros (2);
6e7bb85e32b8 Allow ode15s and ode15i to work with row initial vectors (bug #50192).
Marco Caliari <marco.caliari@univr.it>
parents: 24007
diff changeset
739 %! fail ("ode15s (@(t, y) A * y, [0, 1], eye (2))",
24012
3d65720cd68a ode15s.m: Fix message in BIST test (bug #50192).
Rik <rik@octave.org>
parents: 24008
diff changeset
740 %! "ode15s: Y0 must be a numeric vector");