Re: [julia-users] Simple Quesiton about svd() function

2015-11-23 Thread Tamas Papp
U and V are not unique. Even when A is square and nonsingular, you eg
can multiply them by a diagonal unitary matrix (the same one for both,
of course).

Best,

Tamas

On Mon, Nov 23 2015, Michael Bullman  wrote:

> Hi All, 
>
> I have a pretty easy question about how/why the svd() behaves how it does. 
>
> Why are my U and V matrices always a factor of -1 from the textbook 
> examples? I'm just getting my feet wet with all this, so I wanted to check 
> what the function returns vs what the textbook says the answers would be, 
> and it looks like it's always off by negative one. 
>
> julia> A = [1 2 ; 2 2; 2 1]
> 3x2 Array{Int64,2}:
>  1  2
>  2  2
>  2  1
>
> julia> U, s, V = svd(A, thin=false)
> (
> 3x3 Array{Float64,2}:
>  -0.514496   0.707107   0.485071
>  -0.685994   0.0   -0.727607
>  -0.514496  -0.707107   0.485071,
>
> [4.123105625617661,0.],
> 2x2 Array{Float64,2}:
>  -0.707107  -0.707107
>  -0.707107   0.707107)
>
>
> text book shows the 1,1 entry of U to be 
> julia> 3/sqrt(34)
> 0.5144957554275265
>
> without a negtive sign. really just all the negative signs are reversed. 
> source: http://www.math.iit.edu/~fass/477577_Chapter_2.pdf
>
> 2nd example:
> julia> A = [3 2 -2 ; 2 3 -2]
> 2x3 Array{Int64,2}:
>  3  2  -2
>  2  3  -2
>
> julia> U, s, V = svd(A, thin=false)
> (
> 2x2 Array{Float64,2}:
>  -0.707107  -0.707107
>  -0.707107   0.707107,
>
> [5.744562646538029,1.0],
> 3x3 Array{Float64,2}:
>  -0.615457  -0.707107 0.348155
>  -0.615457   0.707107 0.348155
>   0.492366   5.55112e-17  0.870388)
>
> which is U and V are negative
> http://www.d.umn.edu/~mhampton/m4326svd_example.pdf
>
> So did I just get back luck with example problems? I feel like it's 
> probably just a difference in convention or something, but figured I would 
> ask for a definitive answer. Thank you for any help



Re: [julia-users] Simple Quesiton about svd() function

2015-11-23 Thread Milan Bouchet-Valat
Le dimanche 22 novembre 2015 à 18:58 -0800, Michael Bullman a écrit :
> Hi All, 
> 
> I have a pretty easy question about how/why the svd() behaves how it
> does. 
> 
> Why are my U and V matrices always a factor of -1 from the textbook
> examples? I'm just getting my feet wet with all this, so I wanted to
> check what the function returns vs what the textbook says the answers
> would be, and it looks like it's always off by negative one. 
> 
> julia> A = [1 2 ; 2 2; 2 1]
> 3x2 Array{Int64,2}:
>  1  2
>  2  2
>  2  1
> 
> julia> U, s, V = svd(A, thin=false)
> (
> 3x3 Array{Float64,2}:
>  -0.514496   0.707107   0.485071
>  -0.685994   0.0   -0.727607
>  -0.514496  -0.707107   0.485071,
> 
> [4.123105625617661,0.],
> 2x2 Array{Float64,2}:
>  -0.707107  -0.707107
>  -0.707107   0.707107)
> 
> 
> text book shows the 1,1 entry of U to be 
> julia> 3/sqrt(34)
> 0.5144957554275265
> 
> without a negtive sign. really just all the negative signs are
> reversed. 
> source: http://www.math.iit.edu/~fass/477577_Chapter_2.pdf
> 
> 2nd example:
> julia> A = [3 2 -2 ; 2 3 -2]
> 2x3 Array{Int64,2}:
>  3  2  -2
>  2  3  -2
> 
> julia> U, s, V = svd(A, thin=false)
> (
> 2x2 Array{Float64,2}:
>  -0.707107  -0.707107
>  -0.707107   0.707107,
> 
> [5.744562646538029,1.0],
> 3x3 Array{Float64,2}:
>  -0.615457  -0.707107 0.348155
>  -0.615457   0.707107 0.348155
>   0.492366   5.55112e-17  0.870388)
> 
> which is U and V are negative
> http://www.d.umn.edu/~mhampton/m4326svd_example.pdf
> 
> So did I just get back luck with example problems? I feel like it's
> probably just a difference in convention or something, but figured I
> would ask for a definitive answer. Thank you for any help
Yes, this is just a matter of convention. Obviously you can flip the
sign of the first columns of U and V and still reconstruct the same
original matrix. You would need to apply additional rules if you want
to get reliably the same solution (e.g. that coefficients in the first
line of U should be positive).

FWIW, R using the reference BLAS returns the same results as Julia.


Regards


[julia-users] Simple Quesiton about svd() function

2015-11-22 Thread Michael Bullman
Hi All, 

I have a pretty easy question about how/why the svd() behaves how it does. 

Why are my U and V matrices always a factor of -1 from the textbook 
examples? I'm just getting my feet wet with all this, so I wanted to check 
what the function returns vs what the textbook says the answers would be, 
and it looks like it's always off by negative one. 

julia> A = [1 2 ; 2 2; 2 1]
3x2 Array{Int64,2}:
 1  2
 2  2
 2  1

julia> U, s, V = svd(A, thin=false)
(
3x3 Array{Float64,2}:
 -0.514496   0.707107   0.485071
 -0.685994   0.0   -0.727607
 -0.514496  -0.707107   0.485071,

[4.123105625617661,0.],
2x2 Array{Float64,2}:
 -0.707107  -0.707107
 -0.707107   0.707107)


text book shows the 1,1 entry of U to be 
julia> 3/sqrt(34)
0.5144957554275265

without a negtive sign. really just all the negative signs are reversed. 
source: http://www.math.iit.edu/~fass/477577_Chapter_2.pdf

2nd example:
julia> A = [3 2 -2 ; 2 3 -2]
2x3 Array{Int64,2}:
 3  2  -2
 2  3  -2

julia> U, s, V = svd(A, thin=false)
(
2x2 Array{Float64,2}:
 -0.707107  -0.707107
 -0.707107   0.707107,

[5.744562646538029,1.0],
3x3 Array{Float64,2}:
 -0.615457  -0.707107 0.348155
 -0.615457   0.707107 0.348155
  0.492366   5.55112e-17  0.870388)

which is U and V are negative
http://www.d.umn.edu/~mhampton/m4326svd_example.pdf

So did I just get back luck with example problems? I feel like it's 
probably just a difference in convention or something, but figured I would 
ask for a definitive answer. Thank you for any help