Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

possible issue dggsvd3 function #109

Closed
tiagofrepereira2012 opened this issue Jan 12, 2017 · 6 comments
Closed

possible issue dggsvd3 function #109

tiagofrepereira2012 opened this issue Jan 12, 2017 · 6 comments

Comments

@tiagofrepereira2012
Copy link

In a very simplified way, I created the following function in C that uses the Generalized SVD function dggsvd3.
[U,V,Q,C,S] = my_gsvd_in_C(A,B), where the inputs are:

A =    [[ 1.,  1.,  2.],
       [ 0.,  1.,  3.],
       [ 0.,  4.,  3.]]
B =   [[ 0.2,  1.4,  2. ],
       [ 0.4,  1. ,  3.2],
       [ 0.3,  4.5,  3.3]]

The outputs that I get are the following:

U =    [[-0.45904757,  0.22321234, -0.8599137 ],
       [-0.88154988, -0.23451243,  0.40972397],
       [-0.11020501,  0.94613961,  0.30442518]]

V =   [[-0.38233328,  0.1538968 ,  0.91111856],
       [-0.92047714, -0.149751  , -0.36096602],
       [-0.0808894 ,  0.97667313, -0.19891328]]

C = [ 0.69954115,  0.64582169,  0.99967773]

S = [ 0.71459232,  0.76348828,  0.02538585]

Q =  [[-0.09327252, -0.55839886,  0.82431241],
       [ 0.70757717,  0.54528323,  0.44944494],
       [ 0.70045328, -0.6251855 , -0.34425035]]

My problem is with the output of Q.
This output is completely different from the one from MATLAB.
Calling the function gsvd from MATLAB, with the same inputs, I have the following value for Q

Q =
    0.3456   -0.6562    0.8602
    5.8426   -2.5466   -0.7678
    3.9969   -5.5656   -0.4228

I don't know what is going on. I can send my C code if needed.
Sorry for any duplicate message, I posted the same issue in the LAPACK forum.

Thanks in advance for any answer

@se4u
Copy link

se4u commented Jan 12, 2017 via email

@tiagofrepereira2012
Copy link
Author

So, I've tested that.
In my C code, U, V and Q are orthonormal, but

A <> U * C * Q^T and B <> V * S * Q^T

In Matab, only U and V are orthonormal (they are same as in C), but not Q and

A = U * C * Q^T and B = V * S * Q^T

which I think it is correct

@langou
Copy link
Contributor

langou commented Jan 12, 2017

You say "Calling the function gsvd from MATLAB, with the same inputs, I have the following value for Q". What you give is Matlab X, not Matlab Q. (There is no Matlab Q.) LAPACK returns a Q and an R. Matlab returns an X. Please read DGGSVD3 interface.

DGGSVD3 computes the generalized singular value decomposition (GSVD)
of an M-by-N real matrix A and P-by-N real matrix B:
U**T*A*Q = D1*( 0 R ),    V**T*B*Q = D2*( 0 R )

Julien.

@tiagofrepereira2012
Copy link
Author

Wow, that's right.
Thank you all and sorry for the noise.

I will close the issue

Cheers

@tiagofrepereira2012
Copy link
Author

Another question
Why Matlab sorts ALPHA like this

ALPHA(1) < ALPHA(2) < ... < ALPHA(N)

and BETA like this

BETA(1) >= BETA(2) >= ... >= BETA(N)

Thanks in advance.

@langou
Copy link
Contributor

langou commented Jan 13, 2017

Tiago.

(1) Next time you have a question about LAPACK, can you post it on the LAPACK forum? http://icl.cs.utk.edu/lapack-forum/ As opposed to on GitHub. We use GitHub Issue to track bugs, etc. I am not sure we want to use it for user support. User support is on the forum. Thanks.

(2) What do you mean by ALPHA and BETA? Do you mean C and S? Since C^2+S^2=1, if C is increasing order, then S is decreasing order. I am not sure I understood the question correctly. If more questions, please ask on the forum.

Julien.

@julielangou julielangou modified the milestone: 2017 Release Feb 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants