Mercurial > octave-nkf
comparison scripts/ode/ode45.m @ 20648: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 |
comparison
equal
deleted
inserted
replaced
20647:05c77bc1d204 | 20648:27c091f4b66d |
---|---|
129 error ("OdePkg:InvalidArgument", | 129 error ("OdePkg:InvalidArgument", |
130 "third input argument must be a valid numerical value"); | 130 "third input argument must be a valid numerical value"); |
131 endif | 131 endif |
132 vinit = vinit(:); | 132 vinit = vinit(:); |
133 | 133 |
134 if (! (isa (vfun, "function_handle"))) | 134 if (ischar (vfun)) |
135 try; vfun = str2func (vfun); catch; warning (lasterr); end_try_catch | |
136 endif | |
137 if (! (isa (vfun, "function_handle"))) | |
135 error ("OdePkg:InvalidArgument", | 138 error ("OdePkg:InvalidArgument", |
136 "first input argument must be a valid function handle"); | 139 "first input argument must be a valid function handle"); |
137 endif | 140 endif |
138 | 141 |
139 ## Start preprocessing, have a look which options are set in vodeoptions, | 142 ## Start preprocessing, have a look which options are set in vodeoptions, |
507 %!error # ouput argument | 510 %!error # ouput argument |
508 %! warning ("off", "OdePkg:InvalidArgument"); | 511 %! warning ("off", "OdePkg:InvalidArgument"); |
509 %! B = ode45 (1, [0 25], [3 15 1]); | 512 %! B = ode45 (1, [0 25], [3 15 1]); |
510 %!error # input argument number one | 513 %!error # input argument number one |
511 %! [vt, vy] = ode45 (1, [0 25], [3 15 1]); | 514 %! [vt, vy] = ode45 (1, [0 25], [3 15 1]); |
515 %!error # input argument number one as name of non existing function | |
516 %! [vt, vy] = ode45 ("non-existing-function"", [0 25], [3 15 1]); | |
512 %!error # input argument number two | 517 %!error # input argument number two |
513 %! [vt, vy] = ode45 (@fpol, 1, [3 15 1]); | 518 %! [vt, vy] = ode45 (@fpol, 1, [3 15 1]); |
514 %!test # two output arguments | 519 %!test # two output arguments |
515 %! [vt, vy] = ode45 (@fpol, [0 2], [2 0]); | 520 %! [vt, vy] = ode45 (@fpol, [0 2], [2 0]); |
516 %! assert ([vt(end), vy(end,:)], [2, fref], 1e-2); | 521 %! assert ([vt(end), vy(end,:)], [2, fref], 1e-2); |
518 %! [vt, vy] = ode45 (@fpol, [0 2], [2 0]); | 523 %! [vt, vy] = ode45 (@fpol, [0 2], [2 0]); |
519 %! assert (size (vt) < 20); | 524 %! assert (size (vt) < 20); |
520 %!test # anonymous function instead of real function | 525 %!test # anonymous function instead of real function |
521 %! fvdb = @(vt,vy) [vy(2); (1 - vy(1)^2) * vy(2) - vy(1)]; | 526 %! fvdb = @(vt,vy) [vy(2); (1 - vy(1)^2) * vy(2) - vy(1)]; |
522 %! [vt, vy] = ode45 (fvdb, [0 2], [2 0]); | 527 %! [vt, vy] = ode45 (fvdb, [0 2], [2 0]); |
528 %! assert ([vt(end), vy(end,:)], [2, fref], 1e-2); | |
529 %!test # string instead of function | |
530 %! fvdb = @(vt,vy) [vy(2); (1 - vy(1)^2) * vy(2) - vy(1)]; | |
531 %! [vt, vy] = ode45 ("atan2", [0 2], [2 0]); | |
523 %! assert ([vt(end), vy(end,:)], [2, fref], 1e-2); | 532 %! assert ([vt(end), vy(end,:)], [2, fref], 1e-2); |
524 %!test # extra input arguments passed through | 533 %!test # extra input arguments passed through |
525 %! [vt, vy] = ode45 (@fpol, [0 2], [2 0], 12, 13, "KL"); | 534 %! [vt, vy] = ode45 (@fpol, [0 2], [2 0], 12, 13, "KL"); |
526 %! assert ([vt(end), vy(end,:)], [2, fref], 1e-2); | 535 %! assert ([vt(end), vy(end,:)], [2, fref], 1e-2); |
527 %!test # empty OdePkg structure *but* extra input arguments | 536 %!test # empty OdePkg structure *but* extra input arguments |
656 %! assert ([vsol.x(end), vsol.y(end,:)], [2, fref], 1e-3); | 665 %! assert ([vsol.x(end), vsol.y(end,:)], [2, fref], 1e-3); |
657 %!test # Set BDF option to something else than default | 666 %!test # Set BDF option to something else than default |
658 %! vopt = odeset ("BDF", "on"); | 667 %! vopt = odeset ("BDF", "on"); |
659 %! [vt, vy] = ode45 (@fpol, [0 2], [2 0], vopt); | 668 %! [vt, vy] = ode45 (@fpol, [0 2], [2 0], vopt); |
660 %! assert ([vt(end), vy(end,:)], [2, fref], 1e-3); | 669 %! assert ([vt(end), vy(end,:)], [2, fref], 1e-3); |
661 %! | 670 %!test # |
662 %!## test for MvPattern option is missing | 671 %!## test for MvPattern option is missing |
663 %!## test for InitialSlope option is missing | 672 %!## test for InitialSlope option is missing |
664 %!## test for MaxOrder option is missing | 673 %!## test for MaxOrder option is missing |
665 %! | 674 %! |
666 %! warning ("on", "OdePkg:InvalidArgument"); | 675 %! warning ("on", "OdePkg:InvalidArgument"); |
667 |