From octave-sources-request at bevo dot che dot wisc dot edu Thu Jan 11 01:56:28 2001 Subject: dot.m ( typo corrected) From: Rolf Fabian To: "'octave-sources UWISC'" Date: Thu, 11 Jan 2001 08:53:01 +0100 Hi, I've removed some typos in the header section of my previous upload yesterday. The function body remained unchanged! Sorry for any inconvenience. Rolf --------------------- snip ----------------------- ## -*- texinfo -*- ## at deftypefn {Function File} {} dot (@var{x}, @var{y}) ## DOT PRODUCT of two vectors ## ##The dot (inner) product may be legally defined in two flavours: ##(A) at var{x}(1)*conj(@var{y}(1)) + .. + @var{x}(N)*conj(@var{y}(N)) ## This definition applies complex conjugation to the second ## argument and is preferred in most linear algebra textbooks. ## It is choosen to be the default method in current function. ## ##(B) at conj(var{x}(1))*@var{y}(1) + .. + @conj(var{x}(N))*@var{y}(N) ## This alternate definition prefers complex conjugation ## of the first argument and is used as matlab's default. ## ##Both definitions are identical for vectors at var{x}, @var{y} in ##euclidian (real) space, but differ in unitary (complex) space. ##Switching between both definitions may be controlled by setting ##variable 'global dot_arg_conj_prefer' =2 (A) or =1 (B). ## ##Simple properties ##dot( at var(x),C*@var(y)) == conj( C ) * dot(@var(x),@var(y)) (A) ## == C * dot( at var(x),@var(y)) (B) ##dot(C* at var(x),@var(y)) == C * dot(@var(x),@var(y)) (A) ## == conj( C ) * dot( at var(x),@var(y)) (B) ##dot( ) == norm( at var(x) )^2 (A ) == norm( @var(x) )^2 (A|B) ##dot( ) == conj( dot( at var(y),@var(x) ) ) (A ) == conj( dot( @var(y),@var(x) ) ) (A|B) ## ##The input vectors may pocess any combination of row/column ##orientation, but their length N must be the same. ## at end deftypefn ##AUTHOR Rolf Fabian Jan. 11, 2001 ## published under current GNU GENERAL PUBLIC LICENSE function z = dot(x,y) if (nargin != 2) usage ("dot( x,y )"); endif if exist("dot_arg_conj_prefer")==1 global dot_arg_conj_prefer; DACP=dot_arg_conj_prefer; if all([1,2]!=DACP), error(\ "dot: invalid global \'dot_arg_conj_prefer\' .. set to 1|2"); endif else DACP=2; 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) ) if DACP==2 z = x(:).' * conj( y(:) ); #conj 2nd arg elseif DACP==1 z = x(:)' * y(:); #conj 1st arg endif 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 ------------------------------------------------------------- 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 -------------------------------------------------------------