From bug-octave-request at bevo dot che dot wisc dot edu Fri Dec 22 10:49:25 2000 Subject: inner product in complex n-space From: Rolf Fabian To: "'bug-octave UWISC'" Date: Fri, 22 Dec 2000 10:49:23 -0600 (CST) Hi last spring, I've sent a bug report to this list ( see http://www.octave.org/mailing-lists/bug-octave/1999/44 ) and the proposed changes were adopted to ,dot.m'. Now, I'd to realize, that the mixing of complex conjugation and transposition operations is still incorrect and that the function dot( x,y ) V2.1.32 -script may still fail if complex input vectors x,y are involved. ( Real vectors are handled correctly ) So I've completely rewritten the function script with respect to the following points 1) give a clear definition of the used ,dot'-product in complex n-space. I gave preference to the following definition, given by most textbooks e.g. by Seymour Lipschutz ,Linear Analysis'' (Schaum) length dot ( x, y ) = SUM x(k) * conj( y(k) ) <== k=1 The inner product in complex Euklidian n-space must be defined asymmetrically concerning x and y vectors (see e.g. also given ref). NOTE that an alternate possible definition might be length dot ( x, y ) = SUM conj(x(k)) * x (k) k=1 which is quite different from the one given above. So, in order to avoid any confusion, the preferenced definition (<== ) appears in the help-header of the script 2) all script calls removed e.g. ,is_vector' , only builtin -funcs used 3) all if clauses removed, instead x( : ) y( : ) feature used inside an unwind_protect block, because setting global ,do_fortran_indexing=1' is required. Then the central function module simplifies considerably to Z = x( : ).' * conj ( y( : ) ) This always computes the correct answer complying to the choosen definition of the dot operation. It does no more depend on any of the 4 possible combinations of x,y - vector orentations as was the case in previous versions of ,dot.m'. Check-by :>x=(t=randn(6,1) + randn(6,1)*i ) / norm(t) # this constructs a complex random norm(x)==1 column vector # next four lines use the revised script from below :> dot( x , x ) |- ans = 1 :> dot( x , x.' ) |- ans = 1 :> dot( x.',x ) |- ans = 1 :> dot( x.',x.' ) |- ans = 1 so, all 4 combinations of orientations OK ! Note, that this check fails with current V2.1.32 dot-script (also all previous versions). Bye Rolf --------------------------------------- snip ------------------------------------------------ ## Copyright (C) 1998 John W. Eaton ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 2, or (at your option) ## any later version. ## ## This program is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this file. If not, write to the Free Software Foundation, ## 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ## -*- texinfo -*- ## at deftypefn {Function File} {} dot (@var{x}, @var{y}) ## Computes the dot product of two vectors defined as ## at var{x}(1)*conj(@var{y}(1)) + .. + @var{x}(N)*conj(@var{y}(N)) ## Both vectors may have any orientation, but their length N must be the same. ## at end deftypefn ## Author: jwe ## completely rewritten by Rolf Fabian 001220 function z = dot(x,y) if (nargin != 2) usage ("dot( x,y )"); endif save_do_fortran_indexing = do_fortran_indexing; unwind_protect do_fortran_indexing = 1; if ( any(size(x)==1) && any(size(y)==1) && length(x)==length(y) ) z = x(:).' * conj( y(:) ); else error ("dot: both arguments must be vectors of the same length"); endif unwind_protect_cleanup do_fortran_indexing = save_do_fortran_indexing; end_unwind_protect endfunction --------------------------------------- snip ------------------------------------------------ ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------