comparison scripts/ode/ode45.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 449ed6f427cb
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{t}, @var{y}] =} ode45 (@var{fun}, @var{trange}, @var{init}) 27 ## @deftypefn {} {[@var{t}, @var{y}] =} ode45 (@var{fcn}, @var{trange}, @var{init})
28 ## @deftypefnx {} {[@var{t}, @var{y}] =} ode45 (@var{fun}, @var{trange}, @var{init}, @var{ode_opt}) 28 ## @deftypefnx {} {[@var{t}, @var{y}] =} ode45 (@var{fcn}, @var{trange}, @var{init}, @var{ode_opt})
29 ## @deftypefnx {} {[@var{t}, @var{y}, @var{te}, @var{ye}, @var{ie}] =} ode45 (@dots{}) 29 ## @deftypefnx {} {[@var{t}, @var{y}, @var{te}, @var{ye}, @var{ie}] =} ode45 (@dots{})
30 ## @deftypefnx {} {@var{solution} =} ode45 (@dots{}) 30 ## @deftypefnx {} {@var{solution} =} ode45 (@dots{})
31 ## @deftypefnx {} {} ode45 (@dots{}) 31 ## @deftypefnx {} {} ode45 (@dots{})
32 ## 32 ##
33 ## Solve a set of non-stiff Ordinary Differential Equations (non-stiff ODEs) 33 ## Solve a set of non-stiff Ordinary Differential Equations (non-stiff ODEs)
34 ## with the well known explicit @nospell{Dormand-Prince} method of order 4. 34 ## with the well known explicit @nospell{Dormand-Prince} method of order 4.
35 ## 35 ##
36 ## @var{fun} is a function handle, inline function, or string containing the 36 ## @var{fcn} is a function handle, inline function, or string containing the
37 ## name of the function that defines the ODE: @code{y' = f(t,y)}. The function 37 ## name of the function that defines the ODE: @code{y' = f(t,y)}. The function
38 ## must accept two inputs where the first is time @var{t} and the second is a 38 ## must accept two inputs where the first is time @var{t} and the second is a
39 ## column vector of unknowns @var{y}. 39 ## column vector of unknowns @var{y}.
40 ## 40 ##
41 ## @var{trange} specifies the time interval over which the ODE will be 41 ## @var{trange} specifies the time interval over which the ODE will be
87 ## @end group 87 ## @end group
88 ## @end example 88 ## @end example
89 ## @seealso{odeset, odeget, ode23, ode15s} 89 ## @seealso{odeset, odeget, ode23, ode15s}
90 ## @end deftypefn 90 ## @end deftypefn
91 91
92 function varargout = ode45 (fun, trange, init, varargin) 92 function varargout = ode45 (fcn, trange, init, varargin)
93 93
94 if (nargin < 3) 94 if (nargin < 3)
95 print_usage (); 95 print_usage ();
96 endif 96 endif
97 97
98 solver = "ode45"; 98 solver = "ode45";
99 order = 5; # runge_kutta_45_dorpri uses local extrapolation 99 order = 5; # runge_kutta_45_dorpri uses local extrapolation
100 100
101 if (nargin >= 4) 101 if (nargin >= 4)
102 if (! isstruct (varargin{1})) 102 if (! isstruct (varargin{1}))
103 ## varargin{1:len} are parameters for fun 103 ## varargin{1:len} are parameters for fcn
104 odeopts = odeset (); 104 odeopts = odeset ();
105 funarguments = varargin; 105 funarguments = varargin;
106 elseif (numel (varargin) > 1) 106 elseif (numel (varargin) > 1)
107 ## varargin{1} is an ODE options structure opt 107 ## varargin{1} is an ODE options structure opt
108 odeopts = varargin{1}; 108 odeopts = varargin{1};
137 error ("Octave:invalid-input-arg", 137 error ("Octave:invalid-input-arg",
138 "ode45: INIT must be a numeric vector"); 138 "ode45: INIT must be a numeric vector");
139 endif 139 endif
140 init = init(:); 140 init = init(:);
141 141
142 if (ischar (fun)) 142 if (ischar (fcn))
143 if (! exist (fun)) 143 if (! exist (fcn))
144 error ("Octave:invalid-input-arg", 144 error ("Octave:invalid-input-arg",
145 ['ode45: function "' fun '" not found']); 145 ['ode45: function "' fcn '" not found']);
146 endif 146 endif
147 fun = str2func (fun); 147 fcn = str2func (fcn);
148 endif 148 endif
149 if (! is_function_handle (fun)) 149 if (! is_function_handle (fcn))
150 error ("Octave:invalid-input-arg", 150 error ("Octave:invalid-input-arg",
151 "ode45: FUN must be a valid function handle"); 151 "ode45: FCN must be a valid function handle");
152 endif 152 endif
153 153
154 ## Start preprocessing, have a look which options are set in odeopts, 154 ## Start preprocessing, have a look which options are set in odeopts,
155 ## check if an invalid or unused option is set 155 ## check if an invalid or unused option is set
156 [defaults, classes, attributes] = odedefaults (numel (init), 156 [defaults, classes, attributes] = odedefaults (numel (init),
192 odeopts.haveoutputfunction = ! isempty (odeopts.OutputFcn); 192 odeopts.haveoutputfunction = ! isempty (odeopts.OutputFcn);
193 endif 193 endif
194 194
195 if (isempty (odeopts.InitialStep)) 195 if (isempty (odeopts.InitialStep))
196 odeopts.InitialStep = odeopts.direction * ... 196 odeopts.InitialStep = odeopts.direction * ...
197 starting_stepsize (order, fun, trange(1), init, 197 starting_stepsize (order, fcn, trange(1), init,
198 odeopts.AbsTol, odeopts.RelTol, 198 odeopts.AbsTol, odeopts.RelTol,
199 strcmpi (odeopts.NormControl, "on"), 199 strcmpi (odeopts.NormControl, "on"),
200 odeopts.funarguments); 200 odeopts.funarguments);
201 endif 201 endif
202 202
218 218
219 if (havemasshandle) # Handle only the dynamic mass matrix, 219 if (havemasshandle) # Handle only the dynamic mass matrix,
220 if (! strcmp (odeopts.MStateDependence, "none")) 220 if (! strcmp (odeopts.MStateDependence, "none"))
221 ### constant mass matrices have already 221 ### constant mass matrices have already
222 mass = @(t,x) odeopts.Mass (t, x, odeopts.funarguments{:}); 222 mass = @(t,x) odeopts.Mass (t, x, odeopts.funarguments{:});
223 fun = @(t,x) mass (t, x, odeopts.funarguments{:}) ... 223 fcn = @(t,x) mass (t, x, odeopts.funarguments{:}) ...
224 \ fun (t, x, odeopts.funarguments{:}); 224 \ fcn (t, x, odeopts.funarguments{:});
225 else 225 else
226 mass = @(t) odeopts.Mass (t, odeopts.funarguments{:}); 226 mass = @(t) odeopts.Mass (t, odeopts.funarguments{:});
227 fun = @(t,x) mass (t, odeopts.funarguments{:}) ... 227 fcn = @(t,x) mass (t, odeopts.funarguments{:}) ...
228 \ fun (t, x, odeopts.funarguments{:}); 228 \ fcn (t, x, odeopts.funarguments{:});
229 endif 229 endif
230 endif 230 endif
231 231
232 if (nargout == 1) 232 if (nargout == 1)
233 ## Single output requires auto-selected intermediate times, 233 ## Single output requires auto-selected intermediate times,
237 elseif (numel (trange) > 2) 237 elseif (numel (trange) > 2)
238 odeopts.Refine = []; # disable Refine when specific times requested 238 odeopts.Refine = []; # disable Refine when specific times requested
239 endif 239 endif
240 240
241 solution = integrate_adaptive (@runge_kutta_45_dorpri, 241 solution = integrate_adaptive (@runge_kutta_45_dorpri,
242 order, fun, trange, init, odeopts); 242 order, fcn, trange, init, odeopts);
243 243
244 ## Postprocessing, do whatever when terminating integration algorithm 244 ## Postprocessing, do whatever when terminating integration algorithm
245 if (odeopts.haveoutputfunction) # Cleanup plotter 245 if (odeopts.haveoutputfunction) # Cleanup plotter
246 feval (odeopts.OutputFcn, [], [], "done", odeopts.funarguments{:}); 246 feval (odeopts.OutputFcn, [], [], "done", odeopts.funarguments{:});
247 endif 247 endif
521 %!error <TRANGE must be a .* vector> ode45 (@fpol, [0 25; 25 0], [3 15 1]) 521 %!error <TRANGE must be a .* vector> ode45 (@fpol, [0 25; 25 0], [3 15 1])
522 %!error <TRANGE must contain at least 2 elements> ode45 (@fpol, [1], [3 15 1]) 522 %!error <TRANGE must contain at least 2 elements> ode45 (@fpol, [1], [3 15 1])
523 %!error <invalid time span> ode45 (@fpol, [1 1], [3 15 1]) 523 %!error <invalid time span> ode45 (@fpol, [1 1], [3 15 1])
524 %!error <INIT must be a numeric> ode45 (@fpol, [0 25], {[3 15 1]}) 524 %!error <INIT must be a numeric> ode45 (@fpol, [0 25], {[3 15 1]})
525 %!error <INIT must be a .* vector> ode45 (@fpol, [0 25], [3 15 1; 3 15 1]) 525 %!error <INIT must be a .* vector> ode45 (@fpol, [0 25], [3 15 1; 3 15 1])
526 %!error <FUN must be a valid function handle> ode45 (1, [0 25], [3 15 1]) 526 %!error <FCN must be a valid function handle> ode45 (1, [0 25], [3 15 1])