comparison scripts/ode/private/odepkg_event_handle.m @ 20586:b7ac1e94266e

maint: Further clean up of functions in ode/private dir. * AbsRel_Norm.m, fuzzy_compare.m, integrate_adaptive.m, integrate_const.m, integrate_n_steps.m, ode_struct_value_check.m, odepkg_event_handle.m, odepkg_structure_check.m, runge_kutta_45_dorpri.m: Place latest copyright first in file. Use two spaces before beginning single-line comment. Use parentheses around variable to be tested in switch stmt. Use space between function name and opening parenthesis.
author Rik <rik@octave.org>
date Mon, 05 Oct 2015 12:03:16 -0700
parents eb9e2d187ed2
children
comparison
equal deleted inserted replaced
20585:45151de7423f 20586:b7ac1e94266e
82 82
83 if (! iscell (vy)) 83 if (! iscell (vy))
84 vinpargs = {vevefun, vt, vy}; 84 vinpargs = {vevefun, vt, vy};
85 else 85 else
86 vinpargs = {vevefun, vt, vy{1}, vy{2}}; 86 vinpargs = {vevefun, vt, vy{1}, vy{2}};
87 vy = vy{1}; # Delete cell element 2 87 vy = vy{1}; # Delete cell element 2
88 endif 88 endif
89 if (nargin > 4) 89 if (nargin > 4)
90 vinpargs = {vinpargs{:}, varargin{:}}; 90 vinpargs = {vinpargs{:}, varargin{:}};
91 endif 91 endif
92 [veveold, vterm, vdir] = feval (vinpargs{:}); 92 [veveold, vterm, vdir] = feval (vinpargs{:});
101 101
102 if (! iscell (vy)) 102 if (! iscell (vy))
103 vinpargs = {vevefun, vt, vy}; 103 vinpargs = {vevefun, vt, vy};
104 else 104 else
105 vinpargs = {vevefun, vt, vy{1}, vy{2}}; 105 vinpargs = {vevefun, vt, vy{1}, vy{2}};
106 vy = vy{1}; # Delete cell element 2 106 vy = vy{1}; # Delete cell element 2
107 endif 107 endif
108 if (nargin > 4) 108 if (nargin > 4)
109 vinpargs = {vinpargs{:}, varargin{:}}; 109 vinpargs = {vinpargs{:}, varargin{:}};
110 endif 110 endif
111 [veve, vterm, vdir] = feval (vinpargs{:}); 111 [veve, vterm, vdir] = feval (vinpargs{:});
113 ## We assume that all return values must be column vectors 113 ## We assume that all return values must be column vectors
114 veve = veve(:)'; vterm = vterm(:)'; vdir = vdir(:)'; 114 veve = veve(:)'; vterm = vterm(:)'; vdir = vdir(:)';
115 115
116 ## Check if one or more signs of the event has changed 116 ## Check if one or more signs of the event has changed
117 vsignum = (sign (veveold) != sign (veve)); 117 vsignum = (sign (veveold) != sign (veve));
118 if (any (vsignum)) # One or more values have changed 118 if (any (vsignum)) # One or more values have changed
119 vindex = find (vsignum); # Get the index of the changed values 119 vindex = find (vsignum); # Get the index of the changed values
120 120
121 if (any (vdir(vindex) == 0)) 121 if (any (vdir(vindex) == 0))
122 ## Rising or falling (both are possible) 122 ## Rising or falling (both are possible)
123 ## Don't change anything, keep the index 123 ## Don't change anything, keep the index
124 elseif (any (vdir(vindex) == sign (veve(vindex)))) 124 elseif (any (vdir(vindex) == sign (veve(vindex))))
130 endif 130 endif
131 131
132 ## Create new output values if a valid index has been found 132 ## Create new output values if a valid index has been found
133 if (! isempty (vindex)) 133 if (! isempty (vindex))
134 ## Change the persistent result cell array 134 ## Change the persistent result cell array
135 vretcell{1} = any (vterm(vindex)); # Stop integration or not 135 vretcell{1} = any (vterm(vindex)); # Stop integration or not
136 vretcell{2}(vevecnt,1) = vindex(1,1); # Take first event found 136 vretcell{2}(vevecnt,1) = vindex(1,1); # Take first event found
137 ## Calculate the time stamp when the event function returned 0 and 137 ## Calculate the time stamp when the event function returned 0 and
138 ## calculate new values for the integration results, we do both by 138 ## calculate new values for the integration results, we do both by
139 ## a linear interpolation 139 ## a linear interpolation
140 vtnew = vt - veve(1,vindex) * (vt - vtold) / ... 140 vtnew = vt - veve(1,vindex) * (vt - vtold) / ...
141 (veve(1,vindex) - veveold(1,vindex)); 141 (veve(1,vindex) - veveold(1,vindex));