help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: SVD, EIG and CHOL of a matrix


From: Alberto Frigerio
Subject: Re: SVD, EIG and CHOL of a matrix
Date: Fri, 22 Jan 2010 05:38:38 -0800 (PST)

Yeah Jaroslav, you were completely right. I've seen the description of the
command SIGN but I misunderstood it ... and obviously the one I made was
completely non-sense. Hence I succeed in making simple programs about
eigenvalues and SVD, but I got a mathematical problem about Cholesky
factorization.

If I get a positive definite matrix I've found how to calculate its Cholesky
factorization and luckily it is the same of the Octave's one. But I have
some problems when the input matrix A is not positive definite, beacuse I
succeded only in finding a representation like A=L*D*L', where L is
triangular and D is diagonal, and I'd like to have a representation like the
Octave one (I cannot take sqrt(D) because it has also negative values).

By the way, I noted something strange in the Octave CHOL function. In the
help command I read : "With two or more output arguments P flags whether the
matrix was positive definite and `chol' does not fail. A zero value
indicated that the matrix was positive definite and the R gives the
factorization, and P will have a positive value otherwise."

But if I try to run [R,P]=chol(A) with the matrix A=magic(4) I got P=-1.
Obviously it is not a big problem, BUT if I try to valuate R'*R I got a
completely different result from A. Hence, what algorithm is Octave using in
the not positive-definite case?

Thanks,
   Alberto




Jaroslav Hajek-2 wrote:
> 
> On Wed, Jan 20, 2010 at 1:56 PM, Alberto Frigerio
> <address@hidden> wrote:
>>
>> I looked for a code to find, for example, the SVD decomposition of a
>> matrix .
>> I found it on the web and I tried to use it, but I got different results
>> from the Octave function SVD ... as you would see if you try ro run the
>> attached file, I got NaN results, which are not so good I believe .
>>
>> http://old.nabble.com/file/p27241250/svdmio.m svdmio.m
>> http://old.nabble.com/file/p27241250/pythag.m pythag.m
>>
>>
> 
> Oh, I see. I didn't look at the code thoroughly, but one thing that
> poked me into my eyes was
> abs(sqrt(s)*sign(f)) --> you probably wanted abs(sqrt(s))*sign(f).
> 
> Octave uses the LAPACK library for doing the SVD, so you can start here:
> http://www.netlib.org/lapack/double/dgesvd.f
> 
> If you are an Octave newbie, I suggest you first learn how to
> vectorize your code and make use of high-level functions.
> Good programs in Octave are typically quite different from loopy code
> in Fortran or C.
> It's not a bad idea to try reimplementing some of the basic
> factorization, although you'd need to try very hard to outmatch the
> built-in functions in accuracy and it's quite impossible to outperform
> them in speed (as long as you code in m-files). I would, however,
> start with something simpler than the SVD.
> 
> For instance, you can write this:
> 
>                 scale = 0;
>               for k=i:m
>                       scale=scale+abs(A(k,i));
>               endfor
> 
> better as
> 
>                  scale = sum (abs (A(i:m,i)));
> 
> or even better
> 
>                  scale = norm (A(i:m, i), 1);
> 
> Both ways will be much faster.
> 
> Similarly, this:
> 
>                         for k=i:m
>                               A(k,i)=A(k,i)/scale;
>                               s=s+A(k,i)*A(k,i);
>                       endfor
> 
> could be written as
> 
>                       A(i:m) /= scale;
>                       s = sumsq (A(i:m));
> 
> etc. It's a bit of an art, and also requires some knowledge about
> available functions. But the results are normally faster, sometimes
> more accurate, typically more readable and easier to debug, so it's
> worth the effort.
> 
> happy Octaving & best regards
> 
> -- 
> RNDr. Jaroslav Hajek, PhD
> computing expert & GNU Octave developer
> Aeronautical Research and Test Institute (VZLU)
> Prague, Czech Republic
> url: www.highegg.matfyz.cz
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
> 
> 

-- 
View this message in context: 
http://old.nabble.com/SVD%2C-EIG-and-CHOL-of-a-matrix-tp27227342p27273223.html
Sent from the Octave - General mailing list archive at Nabble.com.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]