Mercurial > hg > octave-lojdl
changeset 13146:1ce5cd703af0
Fix bug for complex input for gradient (#34292)
general/gradient.m: Replace conjugate with transpose operator. Tests added.
author | Kai Habel <kai.habel@gmx.de> |
---|---|
date | Fri, 16 Sep 2011 21:04:30 +0200 |
parents | 28227e743342 |
children | 6c952376482d |
files | scripts/general/gradient.m |
diffstat | 1 files changed, 29 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/general/gradient.m +++ b/scripts/general/gradient.m @@ -88,7 +88,7 @@ if (isvector (m)) ## make a row vector. transposed = (size (m, 2) == 1); - m = m(:)'; + m = m(:).'; endif nd = ndims (m); @@ -259,6 +259,34 @@ %! assert (all(dU(:)==2)); %!test +%! [Y,X,Z,U] = ndgrid (2:2:8,1:5,4:4:12,3:5:30); +%! [dX,dY,dZ,dU] = gradient (X+j*X); +%! assert (all(dX(:)==1+1j)); +%! assert (all(dY(:)==0)); +%! assert (all(dZ(:)==0)); +%! assert (all(dU(:)==0)); +%! [dX,dY,dZ,dU] = gradient (Y-j*Y); +%! assert (all(dX(:)==0)); +%! assert (all(dY(:)==2-j*2)); +%! assert (all(dZ(:)==0)); +%! assert (all(dU(:)==0)); +%! [dX,dY,dZ,dU] = gradient (Z+j*1); +%! assert (all(dX(:)==0)); +%! assert (all(dY(:)==0)); +%! assert (all(dZ(:)==4)); +%! assert (all(dU(:)==0)); +%! [dX,dY,dZ,dU] = gradient (U-j*1); +%! assert (all(dX(:)==0)); +%! assert (all(dY(:)==0)); +%! assert (all(dZ(:)==0)); +%! assert (all(dU(:)==5)); +%! assert (size_equal(dX, dY, dZ, dU, X, Y, Z, U)); +%! [dX,dY,dZ,dU] = gradient (U, 5.0); +%! assert (all(dU(:)==1)); +%! [dX,dY,dZ,dU] = gradient (U, 1.0, 2.0, 3.0, 2.5); +%! assert (all(dU(:)==2)); + +%!test %! x = 0:10; %! f = @cos; %! df_dx = @(x) -sin (x);