From: werner_huysegoms@my-dejanews.com
Subject: Re: Cholesky Decomposition Program?
Date: 23 Mar 1999 00:00:00 GMT
Message-ID: <7d88j0$t6f$1@nnrp1.dejanews.com>
References: <taCJ2.62555$YV6.39612@news2.giganews.com> <01be74fe$4b543e80$9916f181@r286>
X-Http-Proxy: 1.0 x2.dejanews.com:80 (Squid/1.1.22) for client 158.169.131.32
Organization: Deja News - The Leader in Internet Discussion
X-Article-Creation-Date: Tue Mar 23 14:30:56 1999 GMT
Newsgroups: comp.sys.hp48
X-Http-User-Agent: Mozilla/4.5 [en] (WinNT; I)

Here's the latest version of the same program:
- it handles real and complex matrices alike
- it doesn't do a/sqrt(a) for the diagonals any more, but the correct sqrt(a)
- it's still G/GX only.. I can't do it as fast as this without SUB working
  on arrays, the way it does in the G/GX..

@----------------------------------------------------------------------
@ LL
@
@ Cholesky Factorization
@
@ In : A
@ Out: L
@
@ Where:
@
@  A : n-by-n positive definite matrix.  Only the diagonal
@      and lower triangle are referenced
@  L : n-by-n matrix, lower triangular, such that:
@      L*trans(L) = A in the real case
@      L*herm(L) = A in the complex case
@  The HP48 command TRN performs a conjugate transpose (herm)
@  for the complex case.
@
@ - Upon successful return, LASTARG (if enabled) will return the
@   original matrix.
@ - When an error occurs, the stack will be as it was before the
@   program was called.
@ - Checks performed:
@   1. Argument type check (array?)
@   2. Array dimension check (matrix?)
@   3. Matrix square check
@   4. Matrix positive definite check
@
@ bytes: 471.5
@ check: #6933h
@ timing: 10-by-10 Hilbert matrix : 6.16 secs @ 3.76Mhz
@ Werner Huysegoms 19981214
@----------------------------------------------------------------------
\<<
@
@ Error routines
@
  { #202h DOERR }			@ Bad Argument Type
  { DROP #501h DOERR }			@ Invalid Dimension
  { DROP2 DROP2 "LL Error:
Not Positive Definite" DOERR }		@ Not Positive Definite
  1 DUP2
@
@ yDIVa:
@  in  : L y i
@  out : L        y/sqrt(y[1]) REPL'd in L, tested for pos def
@ guarantees y[1] is positive real
@
  {
    OVER 1 GET
    DUP ABS DUP ROT \=/ \<-NPD IFT
    \v/ ROT OVER /
    1 ROT PUT REPL			@ A L
  }
@
@ local vars
@
  \-> BAT ID \<-NPD i m k y		@ sets i := 1, k := 1
  \<<
@
@ argument check
@
    { 3 4 } OVER TYPE POS NOT BAT IFT	@ - array
    DUP SIZE OBJ\-> 2 - ID IFT		@ - matrix
    OVER - ID IFT			@ - square
@
@ initialize
@
    DUP 1 + 'm' STO			@ m  := n + 1
    DUP 1 - * 'k' STO+			@ k := n*(n-1) + 1
    DUP 0 CON				@ A L
@
@ first col
@
    OVER 1 k SUB 1			@ A L y 1
    y EVAL
@
@ 2nd..nth col
@
    1 m 2 -				@ 1 n 1 -
    IF DUP THEN				@ IF n 1 > THEN ..
      FOR j
        'i' m STO+
        OVER i k j + SUB		@ A L y
        OVER i 1 - k SUB		@ A L y B
        DUP 1 j SUB			@ A L y B x
        TRN RSD				@ A L y-Bx'
	i y EVAL
      NEXT
    ELSE
      DROP2
    END
@
@ wrapup
@
    SWAP DROP				@ handles possible LASTARG
  \>>
\>>

- I have a version somewhere that does the composition for a *packed* UPPER 
triangular matrix - as there I found a way to still use matrix
multiplications  (fast and accurate in the 48) in the inner loop, with
roughly half the memory  requirement.  It's a bit slower though, can't be
helped.  Let me know if  you're interested. - remember though, that even if I
have tried to make maximum use of the  highest-order function (RSD), the
builtin G/GX matrix divide is still  more accurate, and quite a lot faster -
even if it doesn't make use of	the symmetry.

Best Regards,
Werner Huysegoms
Reply-To: werner.huysegoms@dg11.cec.be
