# Range and direct sum decomposition

**URL:** <https://discourse.julialang.org/t/range-and-direct-sum-decomposition/66961>\
**Category:** New to Julia\
**Tags:** question, linearalgebra\
**Created:** [August 25, 2021, 4:51am UTC](https://discourse.julialang.org/t/range-and-direct-sum-decomposition/66961 "2021-08-25T04:51:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![yewalenikhil65](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yewalenikhil65/32/26873_2.png) [@yewalenikhil65](https://discourse.julialang.org/u/yewalenikhil65)\
**Post date:** [August 25, 2021, 4:51am UTC](https://discourse.julialang.org/t/range-and-direct-sum-decomposition/66961/1 "2021-08-25T04:51:11Z")

</div>

1. Is there anyway to find range of a matrix in julia?
2. is there any way to find direct sum decomposition to two Matrices

---

<div class="post-metadata">

**Author:** ![gustaphe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gustaphe/32/18174_2.png) [@gustaphe](https://discourse.julialang.org/u/gustaphe)\
**Post date:** [August 25, 2021, 5:55am UTC](https://discourse.julialang.org/t/range-and-direct-sum-decomposition/66961/2 "2021-08-25T05:55:59Z")

</div>

1. Not sure how you want that to be represented. One way is to choose a symbolic package, define a symbolic vector `b` of variables and say `r = A*b`
2. If I understand correctly,

```julia
directsum(A,B) = [A zeros(size(A,1), size(B,2)); zeros(size(B,1), size(A,2)) B]

```

---

<div class="post-metadata">

**Author:** ![zdenek\_hurak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zdenek_hurak/32/53118_2.png) [@zdenek\_hurak](https://discourse.julialang.org/u/zdenek_hurak)\
**Post date:** [August 25, 2021, 11:05am UTC](https://discourse.julialang.org/t/range-and-direct-sum-decomposition/66961/3 "2021-08-25T11:05:56Z")

</div>

Range of a matrix is a (sub)space spanned by the columns of the matrix. Now, how do you want to characterize it? The immediate solution is really just to grab the columns of the matrix and your range is then given by an arbitrary linear combination of the columns. If you prefer orthonormal basis and want to consider just the minimal necessary set of basis vectors, then SVD is your friend:

```julia
julia> using LinearAlgebra

julia> A = [1.0 2.0 4.0
            2.0 3.0 6.0
            3.0 4.0 8.0
            4.0 5.0 10.0]
4×3 Matrix{Float64}:
 1.0 2.0 4.0
 2.0 3.0 6.0
 3.0 4.0 8.0
 4.0 5.0 10.0

julia> F = svd(A)
SVD{Float64, Float64, Matrix{Float64}}
U factor:
4×3 Matrix{Float64}:
 -0.263393 -0.794119 -0.171407
 -0.404182 -0.369644 0.616285
 -0.544971 0.0548299 -0.718349
 -0.685761 0.479304 0.273471
singular values:
3-element Vector{Float64}:
 17.310872175339917
  0.5776716446584025
  2.3860836081194186e-17
Vt factor:
3×3 Matrix{Float64}:
 -0.314814 -0.424474 -0.848948
  0.949153 -0.140789 -0.281579
  0.0 -0.894427 0.447214

julia> F.U[:,1:2]
4×2 Matrix{Float64}:
 -0.263393 -0.794119
 -0.404182 -0.369644
 -0.544971 0.0548299
 -0.685761 0.479304

```

---

<div class="post-metadata">

**Author:** ![yewalenikhil65](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yewalenikhil65/32/26873_2.png) [@yewalenikhil65](https://discourse.julialang.org/u/yewalenikhil65)\
**Post date:** [August 29, 2021, 7:11am UTC](https://discourse.julialang.org/t/range-and-direct-sum-decomposition/66961/4 "2021-08-29T07:11:35Z")

</div>

Thanks for replying, @gustaphe @zdenek_hurak  
i however have found what i was looking for here  
[https://jutho.github.io/TensorKit.jl/stable/lib/spaces/#TensorKit.:⊕](https://jutho.github.io/TensorKit.jl/stable/lib/spaces/#TensorKit.:%E2%8A%95)

Hope you find it useful too
