view scripts/ode/private/AbsRel_Norm.m @ 20634:80e630b37ba1

maint: Remove unnecessary 'v' prefix before variables in ODE m-files. * ode_rk_interpolate.m: Deleted file. * odepkg_event_handle.m: Deleted file. * runge_kutta_interpolate.m: Renamed from ode_rk_interpolate.m. Remove 'v' prefix on variables. Delete blank space at end of lines. * ode_event_handler.m: Renamed from odepkg_event_handle.m. Remove 'v' prefix on variables. Delete blank space at end of lines. Use 'evt' for event rather than 'eve' in variable names. Use 'idx' rather than 'index' in variable names. * scripts/ode/module.mk: Add ode_event_handler.m and runge_kutta_interpolate.m to build system. * AbsRel_Norm.m, starting_stepsize.m, ode_struct_value_check.m, odeget.m, odeset.m: Delete blank space at end of lines. * integrate_adaptive, integrate_const.m, integrate_n_steps.m, runge_kutta_45_dorpri.m: Remove 'v' prefix on variable. Delete blank space at end of lines. * ode45.m: Expand docstring to cover more of the inputs/outputs. Remove 'v' prefix on variable. Use name of variable in input validation warnings. Use name of function as prefix in warnings and error messages. Delete long, unnecessary comments. Use faster 'isempty' rather than slow 'isequal' to check whether option has been set. Remove SubOpts variable. Shorten lines < 80 chars.
author Rik <rik@octave.org>
date Sun, 18 Oct 2015 09:55:41 -0700
parents 00caf63edcdf
children 74257c267c8b
line wrap: on
line source

## Copyright (C) 2014-15 Jacopo Corno <jacopo.corno@gmail.com>
## Copyright (C) 2013 Roberto Porcu' <roberto.porcu@polimi.it>
##
## This file is part of Octave.
##
## Octave is free software; you can redistribute it and/or modify it
## under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 3 of the License, or (at
## your option) any later version.
##
## Octave is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Octave; see the file COPYING.  If not, see
## <http://www.gnu.org/licenses/>.

function retval = AbsRel_Norm (x, x_old, AbsTol, RelTol, normcontrol, y)

  n = length (x);

  if (nargin == 5)
    y = zeros (size (x));
  endif

  if (length (x_old) != n || length (y) != n)
    error ("Octave:invalid-input-arg", "invalid dimensions of input arguments");
  endif

  if ((length (AbsTol) != 1 && length (AbsTol) != n)
      || (length (RelTol) != 1 && length (RelTol) != n))
    error ("Octave:invalid-input-arg", "invalid dimensions of input arguments");
  endif

  sc = AbsTol + max (abs (x), abs (x_old)) .* RelTol;
  if (normcontrol)
    retval = max (abs (x - y) ./ sc);
  else
    retval = sqrt ((1 / n) * sumsq ((x - y) ./ sc));
  endif

endfunction