Mercurial > octave
annotate scripts/ode/private/ode_event_handler.m @ 30893:e1788b1a315f
maint: Use "fcn" as preferred abbreviation for "function" in m-files.
* accumarray.m, accumdim.m, quadl.m, quadv.m, randi.m, structfun.m,
__is_function__.m, uigetfile.m, uimenu.m, uiputfile.m, doc_cache_create.m,
colorspace_conversion_input_check.m, imageIO.m, argnames.m, vectorize.m,
vectorize.m, normest1.m, inputname.m, nthargout.m, display_info_file.m,
decic.m, ode15i.m, ode15s.m, ode23.m, ode23s.m, ode45.m, odeset.m,
check_default_input.m, integrate_adaptive.m, ode_event_handler.m,
runge_kutta_23.m, runge_kutta_23s.m, runge_kutta_45_dorpri.m,
runge_kutta_interpolate.m, starting_stepsize.m, __all_opts__.m, fminbnd.m,
fminsearch.m, fminunc.m, fsolve.m, fzero.m, sqp.m, fplot.m, plotyy.m,
__bar__.m, __ezplot__.m, flat_entry.html, profexport.m, movfun.m, bicg.m,
bicgstab.m, cgs.m, eigs.m, gmres.m, pcg.m, __alltohandles__.m, __sprand__.m,
qmr.m, tfqmr.m, dump_demos.m:
Replace "func", "fun", "fn" in documentation and variable names with "fcn".
author | Rik <rik@octave.org> |
---|---|
date | Mon, 04 Apr 2022 18:14:56 -0700 |
parents | 796f54d4ddbf |
children | 449ed6f427cb |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 ######################################################################## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 ## |
30564
796f54d4ddbf
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
3 ## Copyright (C) 2006-2022 The Octave Project Developers |
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
4 ## |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 ## See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 ## distribution or <https://octave.org/copyright/>. |
20536
6256f6e366ac
Fix copyright text in private ode functions
Carlo de Falco <carlo.defalco@polimi.it>
parents:
20533
diff
changeset
|
7 ## |
6256f6e366ac
Fix copyright text in private ode functions
Carlo de Falco <carlo.defalco@polimi.it>
parents:
20533
diff
changeset
|
8 ## This file is part of Octave. |
6256f6e366ac
Fix copyright text in private ode functions
Carlo de Falco <carlo.defalco@polimi.it>
parents:
20533
diff
changeset
|
9 ## |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23565
diff
changeset
|
10 ## Octave is free software: you can redistribute it and/or modify it |
20536
6256f6e366ac
Fix copyright text in private ode functions
Carlo de Falco <carlo.defalco@polimi.it>
parents:
20533
diff
changeset
|
11 ## under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23565
diff
changeset
|
12 ## the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22655
diff
changeset
|
13 ## (at your option) any later version. |
20536
6256f6e366ac
Fix copyright text in private ode functions
Carlo de Falco <carlo.defalco@polimi.it>
parents:
20533
diff
changeset
|
14 ## |
6256f6e366ac
Fix copyright text in private ode functions
Carlo de Falco <carlo.defalco@polimi.it>
parents:
20533
diff
changeset
|
15 ## Octave is distributed in the hope that it will be useful, but |
6256f6e366ac
Fix copyright text in private ode functions
Carlo de Falco <carlo.defalco@polimi.it>
parents:
20533
diff
changeset
|
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22655
diff
changeset
|
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22655
diff
changeset
|
18 ## GNU General Public License for more details. |
20536
6256f6e366ac
Fix copyright text in private ode functions
Carlo de Falco <carlo.defalco@polimi.it>
parents:
20533
diff
changeset
|
19 ## |
6256f6e366ac
Fix copyright text in private ode functions
Carlo de Falco <carlo.defalco@polimi.it>
parents:
20533
diff
changeset
|
20 ## You should have received a copy of the GNU General Public License |
6256f6e366ac
Fix copyright text in private ode functions
Carlo de Falco <carlo.defalco@polimi.it>
parents:
20533
diff
changeset
|
21 ## along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23565
diff
changeset
|
22 ## <https://www.gnu.org/licenses/>. |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 ## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 ######################################################################## |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
25 |
20536
6256f6e366ac
Fix copyright text in private ode functions
Carlo de Falco <carlo.defalco@polimi.it>
parents:
20533
diff
changeset
|
26 ## -*- texinfo -*- |
30893
e1788b1a315f
maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
27 ## @deftypefn {} {@var{retval} =} ode_event_handler (@var{@@evtfcn}, @var{t}, @var{y}, @var{flag}, @var{par1}, @var{par2}, @dots{}) |
20548
25623ef2ff4f
doc: Rewrite docstrings for ode* family of functions.
Rik <rik@octave.org>
parents:
20536
diff
changeset
|
28 ## |
30893
e1788b1a315f
maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
29 ## Return the solution of the event function (@var{@@evtfcn}) which is |
22648
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
30 ## specified in the form of a function handle. |
23565
3a730821e4a2
doc: Peridoc grammarcheck of documentation.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
31 ## |
22648
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
32 ## The second input argument @var{t} is a scalar double and specifies the time |
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
33 ## of the event evaluation. |
20536
6256f6e366ac
Fix copyright text in private ode functions
Carlo de Falco <carlo.defalco@polimi.it>
parents:
20533
diff
changeset
|
34 ## |
22648
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
35 ## The third input argument @var{y} may be a column vector of type double |
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
36 ## (for ODEs and DAEs) which specifies the solutions. Alternatives, @var{y} |
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
37 ## may be a cell array (for IDEs and DDEs) which specifies the solutions and |
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
38 ## derivatives. |
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
39 ## |
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
40 ## The fourth input argument @var{flag} is of type string. Valid values are: |
20548
25623ef2ff4f
doc: Rewrite docstrings for ode* family of functions.
Rik <rik@octave.org>
parents:
20536
diff
changeset
|
41 ## |
20536
6256f6e366ac
Fix copyright text in private ode functions
Carlo de Falco <carlo.defalco@polimi.it>
parents:
20533
diff
changeset
|
42 ## @table @option |
20548
25623ef2ff4f
doc: Rewrite docstrings for ode* family of functions.
Rik <rik@octave.org>
parents:
20536
diff
changeset
|
43 ## @item @qcode{"init"} |
22648
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
44 ## Initialize internal persistent variables of the function |
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
45 ## @code{ode_event_handler} and return an empty cell array of size 4. |
20548
25623ef2ff4f
doc: Rewrite docstrings for ode* family of functions.
Rik <rik@octave.org>
parents:
20536
diff
changeset
|
46 ## |
25623ef2ff4f
doc: Rewrite docstrings for ode* family of functions.
Rik <rik@octave.org>
parents:
20536
diff
changeset
|
47 ## @item @qcode{"calc"} |
22648
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
48 ## Evaluate the event function and return the solution @var{retval} as a cell |
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
49 ## array of size 4. |
20548
25623ef2ff4f
doc: Rewrite docstrings for ode* family of functions.
Rik <rik@octave.org>
parents:
20536
diff
changeset
|
50 ## |
25623ef2ff4f
doc: Rewrite docstrings for ode* family of functions.
Rik <rik@octave.org>
parents:
20536
diff
changeset
|
51 ## @item @qcode{"done"} |
22648
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
52 ## Clean up internal variables of the function @code{ode_event_handler} and |
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
53 ## return an empty cell array of size 4. |
20536
6256f6e366ac
Fix copyright text in private ode functions
Carlo de Falco <carlo.defalco@polimi.it>
parents:
20533
diff
changeset
|
54 ## @end table |
20548
25623ef2ff4f
doc: Rewrite docstrings for ode* family of functions.
Rik <rik@octave.org>
parents:
20536
diff
changeset
|
55 ## |
22648
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
56 ## If additional input arguments @var{par1}, @var{par2}, @dots{} are given |
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
57 ## these parameters are passed directly to the event function. |
20536
6256f6e366ac
Fix copyright text in private ode functions
Carlo de Falco <carlo.defalco@polimi.it>
parents:
20533
diff
changeset
|
58 ## |
22648
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
59 ## This function is an ODE internal helper function and it should never be |
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
60 ## necessary to call it directly. |
20536
6256f6e366ac
Fix copyright text in private ode functions
Carlo de Falco <carlo.defalco@polimi.it>
parents:
20533
diff
changeset
|
61 ## @end deftypefn |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
62 |
30893
e1788b1a315f
maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
63 function retval = ode_event_handler (evtfcn, t, y, flag = "", varargin) |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
64 |
20536
6256f6e366ac
Fix copyright text in private ode functions
Carlo de Falco <carlo.defalco@polimi.it>
parents:
20533
diff
changeset
|
65 ## No error handling has been implemented in this function to achieve |
22648
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
66 ## the highest performance possible. |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
67 |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
68 ## retval{1} is true (to terminate) or false (to continue) |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
69 ## retval{2} is the index information for which an event occurred |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
70 ## retval{3} is the time information column vector |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
71 ## retval{4} is the line by line result information matrix |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
72 |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
73 ## These persistent variables store the results and time value from the |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
74 ## processing in the previous time stamp. |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
75 ## evtold the results from the event function |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
76 ## told the time stamp |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
77 ## yold the ODE result |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
78 ## retcell the return values cell array |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
79 ## evtcnt the counter for how often this function has been called |
22648
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
80 persistent evtold told yold retcell; |
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
81 persistent evtcnt = 1; # Don't remove. Required for Octave parser. |
23079
17dc6c7ef427
Ignore ODE event function at t==0 for Matlab compatibility (bug #49919).
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
82 persistent firstrun = true; |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
83 |
22648
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
84 if (isempty (flag)) |
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
85 ## Process the event, i.e., |
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
86 ## find the zero crossings for either a rising or falling edge |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
87 if (! iscell (y)) |
30893
e1788b1a315f
maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
88 inpargs = {evtfcn, t, y}; |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
89 else |
30893
e1788b1a315f
maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
90 inpargs = {evtfcn, t, y{1}, y{2}}; |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
91 y = y{1}; # Delete cell element 2 |
20552
eb9e2d187ed2
maint: Use Octave coding conventions in scripts/ode/private dir.
Rik <rik@octave.org>
parents:
20548
diff
changeset
|
92 endif |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
93 if (nargin > 4) |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
94 inpargs = {inpargs{:}, varargin{:}}; |
20552
eb9e2d187ed2
maint: Use Octave coding conventions in scripts/ode/private dir.
Rik <rik@octave.org>
parents:
20548
diff
changeset
|
95 endif |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
96 [evt, term, dir] = feval (inpargs{:}); |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
97 |
22648
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
98 ## We require that all return values be row vectors |
22655
6b134d294d61
ode solvers: use ordinary transpose instead of Hermitian conjugate (bug #49410).
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22648
diff
changeset
|
99 evt = evt(:).'; term = term(:).'; dir = dir(:).'; |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
100 |
20536
6256f6e366ac
Fix copyright text in private ode functions
Carlo de Falco <carlo.defalco@polimi.it>
parents:
20533
diff
changeset
|
101 ## Check if one or more signs of the event has changed |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
102 signum = (sign (evtold) != sign (evt)); |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
103 if (any (signum)) # One or more values have changed |
29193
b2d5ee958d7f
ode_event_handler.m: Fix mishandling of event edge types and multiple events (bug #59709).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
104 ## Find events where either rising and falling edges are counted (dir==0) |
b2d5ee958d7f
ode_event_handler.m: Fix mishandling of event edge types and multiple events (bug #59709).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
105 ## or where the specified edge type matches the event edge type. |
b2d5ee958d7f
ode_event_handler.m: Fix mishandling of event edge types and multiple events (bug #59709).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
106 idx = signum & (dir == 0 | dir == sign (evt)); |
b2d5ee958d7f
ode_event_handler.m: Fix mishandling of event edge types and multiple events (bug #59709).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
107 idx = find (idx); # convert logical to numeric index or [] |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
108 |
20536
6256f6e366ac
Fix copyright text in private ode functions
Carlo de Falco <carlo.defalco@polimi.it>
parents:
20533
diff
changeset
|
109 ## Create new output values if a valid index has been found |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
110 if (! isempty (idx)) |
20536
6256f6e366ac
Fix copyright text in private ode functions
Carlo de Falco <carlo.defalco@polimi.it>
parents:
20533
diff
changeset
|
111 ## Change the persistent result cell array |
23079
17dc6c7ef427
Ignore ODE event function at t==0 for Matlab compatibility (bug #49919).
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
112 if (firstrun) |
17dc6c7ef427
Ignore ODE event function at t==0 for Matlab compatibility (bug #49919).
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
113 ## Matlab compatibility requires ignoring condition on first run. |
17dc6c7ef427
Ignore ODE event function at t==0 for Matlab compatibility (bug #49919).
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
114 retcell{1} = false; |
17dc6c7ef427
Ignore ODE event function at t==0 for Matlab compatibility (bug #49919).
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
115 else |
17dc6c7ef427
Ignore ODE event function at t==0 for Matlab compatibility (bug #49919).
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
116 retcell{1} = any (term(idx)); # Stop integration or not |
17dc6c7ef427
Ignore ODE event function at t==0 for Matlab compatibility (bug #49919).
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
117 endif |
29193
b2d5ee958d7f
ode_event_handler.m: Fix mishandling of event edge types and multiple events (bug #59709).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
118 idx = idx(1); # Use first event found if there are multiple. |
b2d5ee958d7f
ode_event_handler.m: Fix mishandling of event edge types and multiple events (bug #59709).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
119 retcell{2}(evtcnt,1) = idx; |
20536
6256f6e366ac
Fix copyright text in private ode functions
Carlo de Falco <carlo.defalco@polimi.it>
parents:
20533
diff
changeset
|
120 ## Calculate the time stamp when the event function returned 0 and |
6256f6e366ac
Fix copyright text in private ode functions
Carlo de Falco <carlo.defalco@polimi.it>
parents:
20533
diff
changeset
|
121 ## calculate new values for the integration results, we do both by |
29193
b2d5ee958d7f
ode_event_handler.m: Fix mishandling of event edge types and multiple events (bug #59709).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
122 ## a linear interpolation. |
b2d5ee958d7f
ode_event_handler.m: Fix mishandling of event edge types and multiple events (bug #59709).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
123 tnew = t - evt(idx) * (t - told) / (evt(idx) - evtold(idx)); |
22655
6b134d294d61
ode solvers: use ordinary transpose instead of Hermitian conjugate (bug #49410).
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22648
diff
changeset
|
124 ynew = (y - (t - tnew) * (y - yold) / (t - told)).'; |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
125 retcell{3}(evtcnt,1) = tnew; |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
126 retcell{4}(evtcnt,:) = ynew; |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
127 evtcnt += 1; |
20552
eb9e2d187ed2
maint: Use Octave coding conventions in scripts/ode/private dir.
Rik <rik@octave.org>
parents:
20548
diff
changeset
|
128 endif |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
129 |
22648
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
130 endif |
23079
17dc6c7ef427
Ignore ODE event function at t==0 for Matlab compatibility (bug #49919).
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
131 |
17dc6c7ef427
Ignore ODE event function at t==0 for Matlab compatibility (bug #49919).
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
132 firstrun = false; |
22648
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
133 evtold = evt; told = t; yold = y; |
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
134 retval = retcell; |
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
135 |
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
136 elseif (strcmp (flag, "init")) |
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
137 ## Call the event function if an event function has been defined to |
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
138 ## initialize the internal variables of the event function and to get |
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
139 ## a value for evtold. |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
140 |
23079
17dc6c7ef427
Ignore ODE event function at t==0 for Matlab compatibility (bug #49919).
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
141 firstrun = true; |
17dc6c7ef427
Ignore ODE event function at t==0 for Matlab compatibility (bug #49919).
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
142 |
22648
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
143 if (! iscell (y)) |
30893
e1788b1a315f
maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
144 inpargs = {evtfcn, t, y}; |
22648
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
145 else |
30893
e1788b1a315f
maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
146 inpargs = {evtfcn, t, y{1}, y{2}}; |
22648
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
147 y = y{1}; # Delete cell element 2 |
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
148 endif |
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
149 if (nargin > 4) |
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
150 inpargs = {inpargs{:}, varargin{:}}; |
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
151 endif |
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
152 [evtold, ~, ~] = feval (inpargs{:}); |
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
153 |
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
154 ## We require that all return values be row vectors |
22655
6b134d294d61
ode solvers: use ordinary transpose instead of Hermitian conjugate (bug #49410).
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22648
diff
changeset
|
155 evtold = evtold(:).'; told = t; yold = y; |
22648
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
156 evtcnt = 1; |
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
157 retval = retcell = cell (1,4); |
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
158 |
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
159 elseif (strcmp (flag, "done")) |
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
160 ## Clear this event handling function |
23079
17dc6c7ef427
Ignore ODE event function at t==0 for Matlab compatibility (bug #49919).
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
161 firstrun = true; |
22648
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
162 evtold = told = yold = evtcnt = []; |
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
163 retval = retcell = cell (1,4); |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
164 |
20552
eb9e2d187ed2
maint: Use Octave coding conventions in scripts/ode/private dir.
Rik <rik@octave.org>
parents:
20548
diff
changeset
|
165 endif |
20621
b92f8e148936
maint: Continued clean-up of functions in ode/private dir.
Rik <rik@octave.org>
parents:
20554
diff
changeset
|
166 |
20552
eb9e2d187ed2
maint: Use Octave coding conventions in scripts/ode/private dir.
Rik <rik@octave.org>
parents:
20548
diff
changeset
|
167 endfunction |