comparison scripts/ode/private/starting_stepsize.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 597f3ee61a48
comparison
equal deleted inserted replaced
30892:1a3cc2811090 30893:e1788b1a315f
22 ## <https://www.gnu.org/licenses/>. 22 ## <https://www.gnu.org/licenses/>.
23 ## 23 ##
24 ######################################################################## 24 ########################################################################
25 25
26 ## -*- texinfo -*- 26 ## -*- texinfo -*-
27 ## @deftypefn {} {@var{h} =} starting_stepsize (@var{order}, @var{func}, @var{t0}, @var{x0}, @var{AbsTol}, @var{RelTol}, @var{normcontrol}, @var{args}) 27 ## @deftypefn {} {@var{h} =} starting_stepsize (@var{order}, @var{fcn}, @var{t0}, @var{x0}, @var{AbsTol}, @var{RelTol}, @var{normcontrol}, @var{args})
28 ## 28 ##
29 ## Determine a good initial timestep for an ODE solver of order @var{order} 29 ## Determine a good initial timestep for an ODE solver of order @var{order}
30 ## using the algorithm described in reference [1]. 30 ## using the algorithm described in reference [1].
31 ## 31 ##
32 ## The input argument @var{func}, is the function describing the differential 32 ## The input argument @var{fcn}, is the function describing the differential
33 ## equations, @var{t0} is the initial time, and @var{x0} is the initial 33 ## equations, @var{t0} is the initial time, and @var{x0} is the initial
34 ## condition. @var{AbsTol} and @var{RelTol} are the absolute and relative 34 ## condition. @var{AbsTol} and @var{RelTol} are the absolute and relative
35 ## tolerance on the ODE integration taken from an ode options structure. 35 ## tolerance on the ODE integration taken from an ode options structure.
36 ## 36 ##
37 ## Reference: 37 ## Reference:
40 ## Springer. 40 ## Springer.
41 ## @end deftypefn 41 ## @end deftypefn
42 ## 42 ##
43 ## @seealso{odepkg} 43 ## @seealso{odepkg}
44 44
45 function h = starting_stepsize (order, func, t0, x0, 45 function h = starting_stepsize (order, fcn, t0, x0,
46 AbsTol, RelTol, normcontrol, 46 AbsTol, RelTol, normcontrol,
47 args = {}) 47 args = {})
48 48
49 ## compute norm of initial conditions 49 ## compute norm of initial conditions
50 d0 = AbsRel_norm (x0, x0, AbsTol, RelTol, normcontrol); 50 d0 = AbsRel_norm (x0, x0, AbsTol, RelTol, normcontrol);
51 51
52 ## compute norm of the function evaluated at initial conditions 52 ## compute norm of the function evaluated at initial conditions
53 y = func (t0, x0, args{:}); 53 y = fcn (t0, x0, args{:});
54 if (iscell (y)) 54 if (iscell (y))
55 y = y{1}; 55 y = y{1};
56 endif 56 endif
57 d1 = AbsRel_norm (y, y, AbsTol, RelTol, normcontrol); 57 d1 = AbsRel_norm (y, y, AbsTol, RelTol, normcontrol);
58 58
64 64
65 ## compute one step of Explicit-Euler 65 ## compute one step of Explicit-Euler
66 x1 = x0 + h0 * y; 66 x1 = x0 + h0 * y;
67 67
68 ## approximate the derivative norm 68 ## approximate the derivative norm
69 yh = func (t0+h0, x1, args{:}); 69 yh = fcn (t0+h0, x1, args{:});
70 if (iscell (yh)) 70 if (iscell (yh))
71 yh = yh{1}; 71 yh = yh{1};
72 endif 72 endif
73 d2 = (1 / h0) * ... 73 d2 = (1 / h0) * ...
74 AbsRel_norm (yh - y, yh - y, AbsTol, RelTol, normcontrol); 74 AbsRel_norm (yh - y, yh - y, AbsTol, RelTol, normcontrol);