Mercurial > octave
diff scripts/ode/private/odepkg_event_handle.m @ 20552:eb9e2d187ed2
maint: Use Octave coding conventions in scripts/ode/private dir.
* AbsRel_Norm.m, fuzzy_compare.m, hermite_quartic_interpolation.m,
integrate_adaptive.m, integrate_const.m, integrate_n_steps.m, kahan.m,
ode_struct_value_check.m, odepkg_event_handle.m, odepkg_structure_check.m,
runge_kutta_45_dorpri.m, starting_stepsize.m:
Wrap long lines to < 80 chars.
Use double quotes rather than single quotes where possible.
Use ';' at end of keywords "return;" and "break;"
Use '##" for stand-alone comments and '#' for end-of-line comments.
Use two spaces after period before starting new sentence.
Use '!' instead of '~' for logical negation.
Use specific form of end (endif, endfor, etc.).
Don't use line continuation marker '...' unless necessary.
author | Rik <rik@octave.org> |
---|---|
date | Sun, 04 Oct 2015 22:18:54 -0700 |
parents | 25623ef2ff4f |
children | b7ac1e94266e |
line wrap: on
line diff
--- a/scripts/ode/private/odepkg_event_handle.m Sun Oct 04 16:24:32 2015 +0100 +++ b/scripts/ode/private/odepkg_event_handle.m Sun Oct 04 22:18:54 2015 -0700 @@ -17,10 +17,10 @@ ## <http://www.gnu.org/licenses/>. ## -*- texinfo -*- -## @deftypefn {Function File} {[@var{sol}] =} odepkg_event_handle (@var{@@fun}, @var{time}, @var{y}, @var{flag}, @var{par1}, @var{par2}, @dots{}) +## @deftypefn {Function File} {@var{sol} =} odepkg_event_handle (@var{@@fun}, @var{time}, @var{y}, @var{flag}, @var{par1}, @var{par2}, @dots{}) ## ## Return the solution of the event function that is specified as the first -## input argument @var{@@fun} in form of a function handle. +## input argument @var{@@fun} in the form of a function handle. ## ## The second input argument @var{time} is of type double scalar and ## specifies the time of the event evaluation, the third input argument @@ -55,7 +55,7 @@ ## ## @seealso{odepkg} -function [vretval] = odepkg_event_handle (vevefun, vt, vy, vflag, varargin) +function vretval = odepkg_event_handle (vevefun, vt, vy, vflag, varargin) ## No error handling has been implemented in this function to achieve ## the highest performance available. @@ -78,17 +78,17 @@ ## Call the event function if an event function has been defined to ## initialize the internal variables of the event function an to get ## a value for veveold - if (strcmp (vflag, 'init')) + if (strcmp (vflag, "init")) - if (~iscell (vy)) + if (! iscell (vy)) vinpargs = {vevefun, vt, vy}; else vinpargs = {vevefun, vt, vy{1}, vy{2}}; - vy = vy{1}; ## Delete cell element 2 - end + vy = vy{1}; # Delete cell element 2 + endif if (nargin > 4) vinpargs = {vinpargs{:}, varargin{:}}; - end + endif [veveold, vterm, vdir] = feval (vinpargs{:}); ## We assume that all return values must be column vectors @@ -99,24 +99,24 @@ ## or for a falling edge elseif (isempty (vflag)) - if (~iscell (vy)) + if (! iscell (vy)) vinpargs = {vevefun, vt, vy}; else vinpargs = {vevefun, vt, vy{1}, vy{2}}; - vy = vy{1}; ## Delete cell element 2 - end + vy = vy{1}; # Delete cell element 2 + endif if (nargin > 4) vinpargs = {vinpargs{:}, varargin{:}}; - end + endif [veve, vterm, vdir] = feval (vinpargs{:}); ## We assume that all return values must be column vectors veve = veve(:)'; vterm = vterm(:)'; vdir = vdir(:)'; ## Check if one or more signs of the event has changed - vsignum = (sign (veveold) ~= sign (veve)); - if (any (vsignum)) ## One or more values have changed - vindex = find (vsignum); ## Get the index of the changed values + vsignum = (sign (veveold) != sign (veve)); + if (any (vsignum)) # One or more values have changed + vindex = find (vsignum); # Get the index of the changed values if (any (vdir(vindex) == 0)) ## Rising or falling (both are possible) @@ -127,28 +127,31 @@ else ## Found a zero crossing but must not be notified vindex = []; - end + endif ## Create new output values if a valid index has been found - if (~isempty (vindex)) + if (! isempty (vindex)) ## Change the persistent result cell array - vretcell{1} = any (vterm(vindex)); ## Stop integration or not - vretcell{2}(vevecnt,1) = vindex(1,1); ## Take first event found + vretcell{1} = any (vterm(vindex)); # Stop integration or not + vretcell{2}(vevecnt,1) = vindex(1,1); # Take first event found ## Calculate the time stamp when the event function returned 0 and ## calculate new values for the integration results, we do both by ## a linear interpolation - vtnew = vt - veve(1,vindex) * (vt - vtold) / (veve(1,vindex) - veveold(1,vindex)); + vtnew = vt - veve(1,vindex) * (vt - vtold) / ... + (veve(1,vindex) - veveold(1,vindex)); vynew = (vy - (vt - vtnew) * (vy - vyold) / (vt - vtold))'; vretcell{3}(vevecnt,1) = vtnew; vretcell{4}(vevecnt,:) = vynew; vevecnt = vevecnt + 1; - end ## if (~isempty (vindex)) + endif - end ## Check for one or more signs ... + endif # Check for one or more signs ... veveold = veve; vtold = vt; vretval = vretcell; vyold = vy; - elseif (strcmp (vflag, 'done')) ## Clear this event handling function - clear ('veveold', 'vtold', 'vretcell', 'vyold', 'vevecnt'); + elseif (strcmp (vflag, "done")) # Clear this event handling function + clear ("veveold", "vtold", "vretcell", "vyold", "vevecnt"); vretcell = cell (1,4); - end + endif +endfunction +