# HG changeset patch # User Carlo de Falco # Date 1444685309 -7200 # Node ID 27c091f4b66dc3d462eb18c947d4d752254a40f4 # Parent 05c77bc1d20473ad7d5edc0089b4b84dfcda9fb0 allow first argument in ode45 to be a string * scripts/ode/ode45.m: allow first argument to be a string diff -r 05c77bc1d204 -r 27c091f4b66d scripts/ode/ode45.m --- a/scripts/ode/ode45.m Mon Oct 12 22:57:17 2015 +0200 +++ b/scripts/ode/ode45.m Mon Oct 12 23:28:29 2015 +0200 @@ -131,7 +131,10 @@ endif vinit = vinit(:); - if (! (isa (vfun, "function_handle"))) + if (ischar (vfun)) + try; vfun = str2func (vfun); catch; warning (lasterr); end_try_catch + endif + if (! (isa (vfun, "function_handle"))) error ("OdePkg:InvalidArgument", "first input argument must be a valid function handle"); endif @@ -509,6 +512,8 @@ %! B = ode45 (1, [0 25], [3 15 1]); %!error # input argument number one %! [vt, vy] = ode45 (1, [0 25], [3 15 1]); +%!error # input argument number one as name of non existing function +%! [vt, vy] = ode45 ("non-existing-function"", [0 25], [3 15 1]); %!error # input argument number two %! [vt, vy] = ode45 (@fpol, 1, [3 15 1]); %!test # two output arguments @@ -521,6 +526,10 @@ %! fvdb = @(vt,vy) [vy(2); (1 - vy(1)^2) * vy(2) - vy(1)]; %! [vt, vy] = ode45 (fvdb, [0 2], [2 0]); %! assert ([vt(end), vy(end,:)], [2, fref], 1e-2); +%!test # string instead of function +%! fvdb = @(vt,vy) [vy(2); (1 - vy(1)^2) * vy(2) - vy(1)]; +%! [vt, vy] = ode45 ("atan2", [0 2], [2 0]); +%! assert ([vt(end), vy(end,:)], [2, fref], 1e-2); %!test # extra input arguments passed through %! [vt, vy] = ode45 (@fpol, [0 2], [2 0], 12, 13, "KL"); %! assert ([vt(end), vy(end,:)], [2, fref], 1e-2); @@ -658,10 +667,9 @@ %! vopt = odeset ("BDF", "on"); %! [vt, vy] = ode45 (@fpol, [0 2], [2 0], vopt); %! assert ([vt(end), vy(end,:)], [2, fref], 1e-3); -%! +%!test # %!## test for MvPattern option is missing %!## test for InitialSlope option is missing %!## test for MaxOrder option is missing %! %! warning ("on", "OdePkg:InvalidArgument"); -