# Full/square SVD and dimension mismatch

**URL:** <https://discourse.julialang.org/t/full-square-svd-and-dimension-mismatch/8157>\
**Category:** General Usage\
**Tags:** bug\
**Created:** [January 4, 2018, 2:04pm UTC](https://discourse.julialang.org/t/full-square-svd-and-dimension-mismatch/8157 "2018-01-04T14:04:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Axel\_Gagge](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/axel_gagge/32/859_2.png) [@Axel\_Gagge](https://discourse.julialang.org/u/Axel_Gagge)\
**Post date:** [January 4, 2018, 2:04pm UTC](https://discourse.julialang.org/t/full-square-svd-and-dimension-mismatch/8157/1 "2018-01-04T14:04:22Z")

</div>

I noticed that

```julia
A = rand(2, 1)
U, S, V = svd(A; thin=false)
U*diagm(S)*V' ≈ A

```

produces the error (Julia 0.6.2):

```julia
ERROR: DimensionMismatch("A has dimensions (2,2) but B has dimensions (1,1)")
Stacktrace:
 [1] gemm_wrapper!(::Array{Float64,2}, ::Char, ::Char, ::Array{Float64,2}, ::Array{Float64,2}) at ./linalg/matmul.jl:345
 [2] *(::Array{Float64,2}, ::Array{Float64,2}, ::Array{Float64,2}) at ./operators.jl:424

```

I expected `S` to be of size `(2,)` and `V` to be of size `(1,2)`. This holds for any MxN matrix `A` when `M /= N`. The behaviour is the same with `eigfact` of course.

Is this fine or should I report it as a bug?

---

<div class="post-metadata">

**Author:** ![abelsiqueira](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abelsiqueira/32/47269_2.png) [@abelsiqueira](https://discourse.julialang.org/u/abelsiqueira)\
**Post date:** [January 4, 2018, 2:52pm UTC](https://discourse.julialang.org/t/full-square-svd-and-dimension-mismatch/8157/2 "2018-01-04T14:52:25Z")

</div>

On the classic full SVD of A, m\times n, you’ll have orthogonal U and V of sizes m\times m and n \times n respectively and \Sigma m \times n. You can’t have V with more columns than that.  
Note that `diagm(S)` won’t give you a rectangular matrix, but you can use `spdiagm`.

```julia
U * spdiagm(S, 0, 2, 1) * V'

```

---

<div class="post-metadata">

**Author:** ![Axel\_Gagge](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/axel_gagge/32/859_2.png) [@Axel\_Gagge](https://discourse.julialang.org/u/Axel_Gagge)\
**Post date:** [January 4, 2018, 2:59pm UTC](https://discourse.julialang.org/t/full-square-svd-and-dimension-mismatch/8157/3 "2018-01-04T14:59:47Z")

</div>

Of course, now it makes sense. Thanks for the clarification!
