# HG changeset patch # User jwe # Date 1081272359 0 # Node ID 404c7122853e5603209f773d3d95afeac999f0b1 # Parent 047ff938b0d9c7bcc9395e94844946400b1929e4 [project @ 2004-04-06 17:23:37 by jwe] diff --git a/liboctave/ChangeLog b/liboctave/ChangeLog --- 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. diff --git a/scripts/ChangeLog b/scripts/ChangeLog --- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,23 +1,24 @@ 2004-04-06 David Bateman - * 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 * 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, diff --git a/scripts/statistics/base/median.m b/scripts/statistics/base/median.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"); diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,7 +1,7 @@ 2004-04-06 David Bateman * 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. diff --git a/src/DLD-FUNCTIONS/daspk.cc b/src/DLD-FUNCTIONS/daspk.cc --- 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\ diff --git a/src/DLD-FUNCTIONS/dasrt.cc b/src/DLD-FUNCTIONS/dasrt.cc --- 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\ diff --git a/src/DLD-FUNCTIONS/dassl.cc b/src/DLD-FUNCTIONS/dassl.cc --- 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\