Mercurial > hg > octave-terminal
changeset 4852:404c7122853e
[project @ 2004-04-06 17:23:37 by jwe]
author | jwe |
---|---|
date | Tue, 06 Apr 2004 17:25:59 +0000 |
parents | 047ff938b0d9 |
children | 66b3cce2bf37 |
files | liboctave/ChangeLog scripts/ChangeLog scripts/statistics/base/median.m src/ChangeLog src/DLD-FUNCTIONS/daspk.cc src/DLD-FUNCTIONS/dasrt.cc src/DLD-FUNCTIONS/dassl.cc |
diffstat | 7 files changed, 51 insertions(+), 34 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -12,7 +12,7 @@ * lo-specfun.cc (besselj, bessely, besseli, besselk, besselh1, besselh2, airy, biry, betainc, gammainc, do_bessel): - New NDArray versions. + New N-d array versions. (SN_BESSEL, NS_BESSEL, NN_BESSEL): New macros. * lo-specfun.h (besselj, bessely, besseli, besselk, besselh1, besselh2, airy, biry, betainc, gammainc): Provide decls.
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,23 +1,24 @@ 2004-04-06 David Bateman <dbateman@free.fr> - * statistics/base/var.m: Update for NDArrays. Allow dimension arg. + * statistics/base/var.m: Update for N-d arrays. Allow dimension arg. + * statistics/base/median.m: Likewise. 2004-04-02 David Bateman <dbateman@free.fr> * statistics/base/std.m: Allow optional args for type and dim. * statistics/base/center.m, statistics/base/meansq.m, statistics/base/moment.m, statistics/base/range.m: - Update for NDArrays. + Update for N-d arrays. * signal/fftshift.m: Fix dimensioning error. * statistics/base/std.m: Use repmat not ones(nr,1)*mean to allow - NDArrays. + N-d arrays. - * general/mod.m, general/mod.m: Allow NDArrays with one scalar arg. - - * signal/fftshift.m: Update for NDArrays, allow optional dim arg. + * general/mod.m, general/mod.m: Allow N-d arrays with one scalar arg. + + * signal/fftshift.m: Update for N-d arrays, allow optional dim arg. - * specfun/erfinv.m, general/repmat.m: Update for NDArrays. + * specfun/erfinv.m, general/repmat.m: Update for N-d arrays. * control/base/bode.m, control/base/lqg.m, control/system/ss2sys.m, control/system/cellidx.m, control/system/dmr2d.m control/system/ss.m,
--- a/scripts/statistics/base/median.m +++ b/scripts/statistics/base/median.m @@ -47,29 +47,45 @@ ## Author: jwe -function retval = median (a) +function retval = median (a, dim) - if (nargin != 1) - usage ("median (a)"); + if (nargin != 1 && nargin != 2) + usage ("median (a, dim)"); + endif + if (nargin < 2) + dim = min (find (size (a) > 1)); + if (isempty (dim)) + dim = 1; + endif endif - [nr, nc] = size (a); - s = sort (a); - if (nr == 1 && nc > 0) - if (rem (nc, 2) == 0) - i = nc/2; - retval = (s (i) + s (i+1)) / 2; + sz = size (a); + s = sort (a, dim); + if (numel (a) > 1) + if (numel (a) == sz(dim)) + if (rem (sz(dim), 2) == 0) + i = sz(dim) / 2; + retval = (s(i) + s(i+1)) / 2; + else + i = ceil (sz(dim) /2); + retval = s(i); + endif else - i = ceil (nc/2); - retval = s (i); - endif - elseif (nr > 0 && nc > 0) - if (rem (nr, 2) == 0) - i = nr/2; - retval = (s (i,:) + s (i+1,:)) / 2; - else - i = ceil (nr/2); - retval = s (i,:); + idx = cell (); + nd = length (sz); + for i = 1:nd + idx{i} = 1:sz(i); + endfor + if (rem (sz(dim), 2) == 0) + i = sz(dim) / 2; + idx{dim} = i; + retval = s(idx{:}); + idx{dim} = i+1; + retval = (retval + s(idx{:})) / 2; + else + idx{dim} = ceil (sz(dim) / 2); + retval = s(idx{:}); + endif endif else error ("median: invalid matrix argument");
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,7 +1,7 @@ 2004-04-06 David Bateman <dbateman@free.fr> * DLD_FUNCTIONS/sort.cc: Use the new template sort class, adapt for - NDArrays, and allow optional dim argument. + N-d arrays, and allow optional dim argument. * DLD_FUNCTIONS/fftn.cc: Save result of transpose operation. Check for failure of transpose. @@ -36,7 +36,7 @@ * DLD-FUNCTIONS/besselj.cc, DLD-FUNCTIONS/betainc.cc, DLD-FUNCTIONS/gammainc.cc, DLD-FUNCTIONS/minmax.cc, DLD-FUNCTIONS/filter.cc: - Convert for NDArray, better Matlab compatibility. + Convert for N-d array, better Matlab compatibility. * load-save.cc (Fload): Better handling of non existent files.
--- a/src/DLD-FUNCTIONS/daspk.cc +++ b/src/DLD-FUNCTIONS/daspk.cc @@ -179,7 +179,7 @@ @deftypefn {Loadable Function} {[@var{x}, @var{xdot}, @var{istate}, @var{msg}] =} daspk (@var{fcn}, @var{x_0}, @var{xdot_0}, @var{t}, @var{t_crit})\n\ Solve the set of differential-algebraic equations\n\ @tex\n\ -$$ 0 = f (\\dot{x}, x, t) $$\n\ +$$ 0 = f (x, \\dot{x}, t) $$\n\ with\n\ $$ x(t_0) = x_0, \\dot{x}(t_0) = \\dot{x}_0 $$\n\ @end tex\n\
--- a/src/DLD-FUNCTIONS/dasrt.cc +++ b/src/DLD-FUNCTIONS/dasrt.cc @@ -215,14 +215,14 @@ @deftypefn {Loadable Function} {[@var{x}, @var{xdot}, @var{t_out}, @var{istat}, @var{msg}] =} dasrt (@var{fcn} [, @var{g}], @var{x_0}, @var{xdot_0}, @var{t} [, @var{t_crit}])\n\ Solve the set of differential-algebraic equations\n\ @tex\n\ -$$ 0 = f (\\dot{x}, x, t) $$\n\ +$$ 0 = f (x, \\dot{x}, t) $$\n\ with\n\ $$ x(t_0) = x_0, \\dot{x}(t_0) = \\dot{x}_0 $$\n\ @end tex\n\ @ifinfo\n\ \n\ @example\n\ -0 = f (xdot, x, t)\n\ +0 = f (x, xdot, t)\n\ @end example\n\ \n\ with\n\ @@ -301,7 +301,7 @@ will attempt to stop the integration at the point of the sign change.\n\ \n\ If the name of the constraint function is omitted, @code{dasrt} solves\n\ -the saem problem as @code{daspk} or @code{dassl}.\n\ +the same problem as @code{daspk} or @code{dassl}.\n\ \n\ Note that because of numerical errors in the constraint functions\n\ due to roundoff and integration error, @sc{Dasrt} may return false\n\
--- a/src/DLD-FUNCTIONS/dassl.cc +++ b/src/DLD-FUNCTIONS/dassl.cc @@ -179,7 +179,7 @@ @deftypefn {Loadable Function} {[@var{x}, @var{xdot}, @var{istate}, @var{msg}] =} dassl (@var{fcn}, @var{x_0}, @var{xdot_0}, @var{t}, @var{t_crit})\n\ Solve the set of differential-algebraic equations\n\ @tex\n\ -$$ 0 = f (\\dot{x}, x, t) $$\n\ +$$ 0 = f (x, \\dot{x}, t) $$\n\ with\n\ $$ x(t_0) = x_0, \\dot{x}(t_0) = \\dot{x}_0 $$\n\ @end tex\n\