Mercurial > hg > octave-nkf
changeset 20824:27c091f4b66d
allow first argument in ode45 to be a string
* scripts/ode/ode45.m: allow first argument to be a string
author | Carlo de Falco <carlo.defalco@polimi.it> |
---|---|
date | Mon, 12 Oct 2015 23:28:29 +0200 |
parents | 05c77bc1d204 |
children | d35201e5ce5d |
files | scripts/ode/ode45.m |
diffstat | 1 files changed, 11 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ode/ode45.m +++ b/scripts/ode/ode45.m @@ -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"); -