Mercurial > octave
annotate scripts/ode/private/ode_event_handler.m @ 27919:1891570abac8
update Octave Project Developers copyright for the new year
In files that have the "Octave Project Developers" copyright notice,
update for 2020.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 06 Jan 2020 22:29:51 -0500 |
parents | b442ec6dda5c |
children | bd51beb6205e |
rev | line source |
---|---|
27919
1891570abac8
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
27918
diff
changeset
|
1 ## Copyright (C) 2006-2020 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
|
2 ## |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
3 ## See the file COPYRIGHT.md in the top-level directory of this distribution |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
4 ## or <https://octave.org/COPYRIGHT.html/>. |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
5 ## |
20536
6256f6e366ac
Fix copyright text in private ode functions
Carlo de Falco <carlo.defalco@polimi.it>
parents:
20533
diff
changeset
|
6 ## |
6256f6e366ac
Fix copyright text in private ode functions
Carlo de Falco <carlo.defalco@polimi.it>
parents:
20533
diff
changeset
|
7 ## 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
|
8 ## |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23565
diff
changeset
|
9 ## 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
|
10 ## 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
|
11 ## 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
|
12 ## (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
|
13 ## |
6256f6e366ac
Fix copyright text in private ode functions
Carlo de Falco <carlo.defalco@polimi.it>
parents:
20533
diff
changeset
|
14 ## 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
|
15 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22655
diff
changeset
|
16 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22655
diff
changeset
|
17 ## 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
|
18 ## |
6256f6e366ac
Fix copyright text in private ode functions
Carlo de Falco <carlo.defalco@polimi.it>
parents:
20533
diff
changeset
|
19 ## 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
|
20 ## 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
|
21 ## <https://www.gnu.org/licenses/>. |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
22 |
20536
6256f6e366ac
Fix copyright text in private ode functions
Carlo de Falco <carlo.defalco@polimi.it>
parents:
20533
diff
changeset
|
23 ## -*- texinfo -*- |
22626 | 24 ## @deftypefn {} {@var{retval} =} ode_event_handler (@var{@@evtfun}, @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
|
25 ## |
22648
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
26 ## Return the solution of the event function (@var{@@evtfun}) which is |
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
27 ## specified in the form of a function handle. |
23565
3a730821e4a2
doc: Peridoc grammarcheck of documentation.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
28 ## |
22648
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
29 ## 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
|
30 ## of the event evaluation. |
20536
6256f6e366ac
Fix copyright text in private ode functions
Carlo de Falco <carlo.defalco@polimi.it>
parents:
20533
diff
changeset
|
31 ## |
22648
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
32 ## 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
|
33 ## (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
|
34 ## 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
|
35 ## derivatives. |
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
36 ## |
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
37 ## 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
|
38 ## |
20536
6256f6e366ac
Fix copyright text in private ode functions
Carlo de Falco <carlo.defalco@polimi.it>
parents:
20533
diff
changeset
|
39 ## @table @option |
20548
25623ef2ff4f
doc: Rewrite docstrings for ode* family of functions.
Rik <rik@octave.org>
parents:
20536
diff
changeset
|
40 ## @item @qcode{"init"} |
22648
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
41 ## Initialize internal persistent variables of the function |
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
42 ## @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
|
43 ## |
25623ef2ff4f
doc: Rewrite docstrings for ode* family of functions.
Rik <rik@octave.org>
parents:
20536
diff
changeset
|
44 ## @item @qcode{"calc"} |
22648
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
45 ## 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
|
46 ## array of size 4. |
20548
25623ef2ff4f
doc: Rewrite docstrings for ode* family of functions.
Rik <rik@octave.org>
parents:
20536
diff
changeset
|
47 ## |
25623ef2ff4f
doc: Rewrite docstrings for ode* family of functions.
Rik <rik@octave.org>
parents:
20536
diff
changeset
|
48 ## @item @qcode{"done"} |
22648
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
49 ## 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
|
50 ## 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
|
51 ## @end table |
20548
25623ef2ff4f
doc: Rewrite docstrings for ode* family of functions.
Rik <rik@octave.org>
parents:
20536
diff
changeset
|
52 ## |
22648
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
53 ## 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
|
54 ## 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
|
55 ## |
22648
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
56 ## 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
|
57 ## 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
|
58 ## @end deftypefn |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
59 |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
60 function retval = ode_event_handler (evtfun, t, y, flag = "", varargin) |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
61 |
20536
6256f6e366ac
Fix copyright text in private ode functions
Carlo de Falco <carlo.defalco@polimi.it>
parents:
20533
diff
changeset
|
62 ## 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
|
63 ## the highest performance possible. |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
64 |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
65 ## 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
|
66 ## 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
|
67 ## 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
|
68 ## 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
|
69 |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
70 ## 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
|
71 ## 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
|
72 ## 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
|
73 ## told the time stamp |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
74 ## yold the ODE result |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
75 ## 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
|
76 ## 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
|
77 persistent evtold told yold retcell; |
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
78 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
|
79 persistent firstrun = true; |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
80 |
22648
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
81 if (isempty (flag)) |
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
82 ## Process the event, i.e., |
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
83 ## 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
|
84 if (! iscell (y)) |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
85 inpargs = {evtfun, t, y}; |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
86 else |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
87 inpargs = {evtfun, t, y{1}, y{2}}; |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
88 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
|
89 endif |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
90 if (nargin > 4) |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
91 inpargs = {inpargs{:}, varargin{:}}; |
20552
eb9e2d187ed2
maint: Use Octave coding conventions in scripts/ode/private dir.
Rik <rik@octave.org>
parents:
20548
diff
changeset
|
92 endif |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
93 [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
|
94 |
22648
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
95 ## 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
|
96 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
|
97 |
20536
6256f6e366ac
Fix copyright text in private ode functions
Carlo de Falco <carlo.defalco@polimi.it>
parents:
20533
diff
changeset
|
98 ## 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
|
99 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
|
100 if (any (signum)) # One or more values have changed |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
101 idx = find (signum); # Get the index of the changed values |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
102 |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
103 if (any (dir(idx) == 0)) |
20536
6256f6e366ac
Fix copyright text in private ode functions
Carlo de Falco <carlo.defalco@polimi.it>
parents:
20533
diff
changeset
|
104 ## Rising or falling (both are possible) |
6256f6e366ac
Fix copyright text in private ode functions
Carlo de Falco <carlo.defalco@polimi.it>
parents:
20533
diff
changeset
|
105 ## Don't change anything, keep the index |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
106 elseif (any (dir(idx) == sign (evt(idx)))) |
20536
6256f6e366ac
Fix copyright text in private ode functions
Carlo de Falco <carlo.defalco@polimi.it>
parents:
20533
diff
changeset
|
107 ## Detected rising or falling, need a new index |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
108 idx = find (dir == sign (evt)); |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
109 else |
20536
6256f6e366ac
Fix copyright text in private ode functions
Carlo de Falco <carlo.defalco@polimi.it>
parents:
20533
diff
changeset
|
110 ## Found a zero crossing but must not be notified |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
111 idx = []; |
20552
eb9e2d187ed2
maint: Use Octave coding conventions in scripts/ode/private dir.
Rik <rik@octave.org>
parents:
20548
diff
changeset
|
112 endif |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
113 |
20536
6256f6e366ac
Fix copyright text in private ode functions
Carlo de Falco <carlo.defalco@polimi.it>
parents:
20533
diff
changeset
|
114 ## 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
|
115 if (! isempty (idx)) |
20536
6256f6e366ac
Fix copyright text in private ode functions
Carlo de Falco <carlo.defalco@polimi.it>
parents:
20533
diff
changeset
|
116 ## 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
|
117 if (firstrun) |
17dc6c7ef427
Ignore ODE event function at t==0 for Matlab compatibility (bug #49919).
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
118 ## 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
|
119 retcell{1} = false; |
17dc6c7ef427
Ignore ODE event function at t==0 for Matlab compatibility (bug #49919).
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
120 else |
17dc6c7ef427
Ignore ODE event function at t==0 for Matlab compatibility (bug #49919).
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
121 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
|
122 endif |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
123 retcell{2}(evtcnt,1) = idx(1,1); # Take first event found |
20536
6256f6e366ac
Fix copyright text in private ode functions
Carlo de Falco <carlo.defalco@polimi.it>
parents:
20533
diff
changeset
|
124 ## 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
|
125 ## calculate new values for the integration results, we do both by |
6256f6e366ac
Fix copyright text in private ode functions
Carlo de Falco <carlo.defalco@polimi.it>
parents:
20533
diff
changeset
|
126 ## a linear interpolation |
20634
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
127 tnew = t - evt(1,idx) * (t - told) / (evt(1,idx) - evtold(1,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
|
128 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
|
129 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
|
130 retcell{4}(evtcnt,:) = ynew; |
80e630b37ba1
maint: Remove unnecessary 'v' prefix before variables in ODE m-files.
Rik <rik@octave.org>
parents:
20631
diff
changeset
|
131 evtcnt += 1; |
20552
eb9e2d187ed2
maint: Use Octave coding conventions in scripts/ode/private dir.
Rik <rik@octave.org>
parents:
20548
diff
changeset
|
132 endif |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
133 |
22648
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
134 endif |
23079
17dc6c7ef427
Ignore ODE event function at t==0 for Matlab compatibility (bug #49919).
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
135 |
17dc6c7ef427
Ignore ODE event function at t==0 for Matlab compatibility (bug #49919).
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
136 firstrun = false; |
22648
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
137 evtold = evt; told = t; yold = y; |
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
138 retval = retcell; |
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
139 |
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
140 elseif (strcmp (flag, "init")) |
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
141 ## 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
|
142 ## 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
|
143 ## a value for evtold. |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
144 |
23079
17dc6c7ef427
Ignore ODE event function at t==0 for Matlab compatibility (bug #49919).
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
145 firstrun = true; |
17dc6c7ef427
Ignore ODE event function at t==0 for Matlab compatibility (bug #49919).
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
146 |
22648
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
147 if (! iscell (y)) |
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
148 inpargs = {evtfun, t, y}; |
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
149 else |
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
150 inpargs = {evtfun, t, y{1}, y{2}}; |
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
151 y = y{1}; # Delete cell element 2 |
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
152 endif |
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
153 if (nargin > 4) |
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
154 inpargs = {inpargs{:}, varargin{:}}; |
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
155 endif |
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
156 [evtold, ~, ~] = feval (inpargs{:}); |
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
157 |
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
158 ## 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
|
159 evtold = evtold(:).'; told = t; yold = y; |
22648
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
160 evtcnt = 1; |
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
161 retval = retcell = cell (1,4); |
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
162 |
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
163 elseif (strcmp (flag, "done")) |
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
164 ## 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
|
165 firstrun = true; |
22648
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
166 evtold = told = yold = evtcnt = []; |
9bc03a3f7a34
ode_event_handler.m: Overhaul function.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
167 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
|
168 |
20552
eb9e2d187ed2
maint: Use Octave coding conventions in scripts/ode/private dir.
Rik <rik@octave.org>
parents:
20548
diff
changeset
|
169 endif |
20621
b92f8e148936
maint: Continued clean-up of functions in ode/private dir.
Rik <rik@octave.org>
parents:
20554
diff
changeset
|
170 |
20552
eb9e2d187ed2
maint: Use Octave coding conventions in scripts/ode/private dir.
Rik <rik@octave.org>
parents:
20548
diff
changeset
|
171 endfunction |