On Nov 20, 2007 7:30 AM, Viktor Cerovski <[EMAIL PROTECTED]> wrote:
> 2) Gramm-Schmidt orthonormalization:
> (in this example I couldn't find an elegant J code without reduce/fold)

I am going to rephrase your code, since email seems to have mangled it:

mp=:   +/ .*
norm=: % %:@mp~
orth=: ] - +/@(mp * [)

GS=: monad :0
   v=.,:[EMAIL PROTECTED]
   i=.1
   while.i<#y do.
     v=.v,norm(v orth i{y)
     i=.>:i
   end.
   v
)

You did not specify the domain of any of this, but since GS is usually
for numeric matricies, I believe you use your others with numeric vectors
(and norm is a monad while mp and orth are dyads).

Anyways, here's another approach to GS:
   GS1=: [: [EMAIL PROTECTED]/\. [EMAIL PROTECTED]:@]`_1:`]}~

   (-: norm"1) GS2 mat=: ?20 20 $ 100
1

This gives you a different result from GS.  To get
the result from GS, use GS1&.|.  (This issue illustrates
that sets of orthogonal normal vectors spanning a vector
space are not unique.)

Or, using an adverb for this pattern;
   foldf=: 2 :'[: [EMAIL PROTECTED]/\. [EMAIL PROTECTED]:@]`_1:`]}~'
   GS2=: norm foldf orth

GS1 and GS2 are identical.

-- 
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to