<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Exchange Server">
<!-- converted from text --><style><!-- .EmailQuote { margin-left: 1pt; padding-left: 4pt; border-left: #800000 2px solid; } --></style>
</head>
<body>
<meta content="text/html; charset=UTF-8">
<style type="text/css" style="">
<!--
p
        {margin-top:0;
        margin-bottom:0}
-->
</style>
<div dir="ltr">
<div id="x_divtagdefaultwrapper" dir="ltr" style="font-size:12pt; color:#000000; font-family:Calibri,Helvetica,sans-serif">
<p>Thank you for your advice, Jose.</p>
<p><br>
</p>
<p>I tried <span style="font-family:Calibri,Helvetica,sans-serif,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols; font-size:16px">
using a single column of the data matrix as a </span>basis for left singular vector space, and a row for the right one - and lo and behold, all singular vectors become real.</p>
<p><br>
</p>
<p>Somehow it did not occur to me that I was I was looking at was simply a complex phase on U and V which would cancel upon computing UΣV*. In other words, rather than an incorrect result it was a slightly inconvenient representation of a correct result.</p>
<p><br>
</p>
<p>Best regards</p>
<p>Peder</p>
</div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="x_divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>Fra:</b> Jose E. Roman <jroman@dsic.upv.es><br>
<b>Sendt:</b> 29. april 2021 13:00:03<br>
<b>Til:</b> Peder Jørgensgaard Olesen<br>
<b>Cc:</b> petsc-users@mcs.anl.gov<br>
<b>Emne:</b> Re: [petsc-users] SLEPc: non-real singular vectors from SVD of real matrix</font>
<div> </div>
</div>
</div>
<font size="2"><span style="font-size:10pt;">
<div class="PlainText">In complex scalars there is no way of knowing if the user-provided matrix is real or not. If there was an option of MatSetOption() we could use it.<br>
<br>
If you set a real initial vector with SVDSetInitialSpaces(), then most probably the computed singular vectors will be real. But still rounding errors could introduce a nonzero imaginary part.<br>
<br>
In any case, you could normalize the computed singular vectors, as is done for instance in FixSign() in this example
<a href="https://slepc.upv.es/documentation/current/src/nep/tutorials/ex20.c.html">
https://slepc.upv.es/documentation/current/src/nep/tutorials/ex20.c.html</a><br>
<br>
Jose<br>
<br>
<br>
> El 29 abr 2021, a las 12:42, Peder Jørgensgaard Olesen via petsc-users <petsc-users@mcs.anl.gov> escribió:<br>
> <br>
> Hello<br>
> <br>
> I've noticed that doing a singular value decomposition of a real matrix appears to result in non-real singular vectors. This should not be the case - singular vectors of a real matrix must be real-valued.<br>
> <br>
> In the example attached I read a matrix from a binary file (also attached), perform the SVD, and write singular vectors to an HDF5 file which I subsequently inspect using h5dump, revealing  non-zero imaginary parts of vector elements as highlighted below:<br>
> [pjool@svol mwes]$ h5dump -d U0_sample_svd -c "5,2" sample_svecs.h5 <br>
> HDF5 "sample_svecs.h5" {<br>
> DATASET "U0_sample_svd" {<br>
>    DATATYPE  H5T_IEEE_F64LE<br>
>    DATASPACE  SIMPLE { ( 882, 2 ) / ( 882, 2 ) }<br>
>    SUBSET {<br>
>       START ( 0, 0 );<br>
>       STRIDE ( 1, 1 );<br>
>       COUNT ( 5, 2 );<br>
>       BLOCK ( 1, 1 );<br>
>       DATA {<br>
>       (0,0): 0.0226108, 0.0299595,<br>
>       (1,0): 0.035414, 0.0469237,<br>
>       (2,0): 0.0276317, 0.0366122,<br>
>       (3,0): 0.0145344, 0.0192581,<br>
>       (4,0): 0.0110376, 0.0146249<br>
>       }<br>
>    }<br>
>    ATTRIBUTE "complex" {<br>
>       DATATYPE  H5T_STD_I32LE<br>
>       DATASPACE  SCALAR<br>
>       DATA {<br>
>       (0): 1<br>
>       }<br>
>    }<br>
> }<br>
> }<br>
> I also extract the imaginary part of the input matrix and print its norm to ensure that the matrix is indeed real.<br>
> <br>
> I'm running v3.14, but I don't believe that alone should cause the issue, since it what I'm trying to do appears like a rather common and basic task.<br>
> <br>
> What might be the reason behind this behavior, and what can be done to resolve it?<br>
> <br>
> <br>
> Med venlig hilsen / Best Regards<br>
> <br>
> Peder Jørgensgaard Olesen<br>
> PhD Student, Turbulence Research Lab<br>
> Dept. of Mechanical Engineering<br>
> Technical University of Denmark<br>
> Niels Koppels Allé<br>
> Bygning 403, Rum 105<br>
> DK-2800 Kgs. Lyngby<br>
> <read_bin.c><sample_data><br>
<br>
</div>
</span></font>
</body>
</html>