# Equivalent Function to licols in Matlab

**URL:** <https://discourse.julialang.org/t/equivalent-function-to-licols-in-matlab/32445>\
**Category:** New to Julia\
**Created:** [December 18, 2019, 1:54pm UTC](https://discourse.julialang.org/t/equivalent-function-to-licols-in-matlab/32445 "2019-12-18T13:54:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmcastro2109](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jmcastro2109/32/38427_2.png) [@jmcastro2109](https://discourse.julialang.org/u/jmcastro2109)\
**Post date:** [December 18, 2019, 1:54pm UTC](https://discourse.julialang.org/t/equivalent-function-to-licols-in-matlab/32445/1 "2019-12-18T13:54:22Z")

</div>

Hello,

I wonder whether Julia has a function to remove (or identify) the columns of a matrix that are linearly dependent similar as the [licols](https://www.mathworks.com/matlabcentral/answers/49984-how-to-remove-dependent-rows-in-a-matrix) does in Matlab.

---

<div class="post-metadata">

**Author:** ![kellertuer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kellertuer/32/220707_2.png) [@kellertuer](https://discourse.julialang.org/u/kellertuer)\
**Post date:** [December 18, 2019, 2:50pm UTC](https://discourse.julialang.org/t/equivalent-function-to-licols-in-matlab/32445/2 "2019-12-18T14:50:48Z")

</div>

Since you linked a function – this is the same function adapted to Julia. You need `LinearAlgebra` for rank and qr, the tolerances are just passed down and `q.p` of the pivoted `qr`is what `E` does in the code you linked.

```julia
using LinearAlgebra
function licols(A::AbstractMatrix; atol::Real=0, rtol::Real=atol>0 ? 0 : size(A,1)*eps(eltype(A)))
    k = rank(A; atol=atol, rtol=rtol)
    q = qr(A,Val(true)) #use pivoted qr
    idx = q.p[1:k]
    return A[:,idx]
end

```

Here’s an example: Defining a matrix and calling above function yields

```julia
julia> A = [1. 2. 3.; 2. 4. 1.; 3. 6. 1.]
3×3 Array{Float64,2}:
 1.0 2.0 3.0
 2.0 4.0 1.0
 3.0 6.0 1.0

julia> licols(A)
3×2 Array{Float64,2}:
 2.0 3.0
 4.0 1.0
 6.0 1.0

```

---

<div class="post-metadata">

**Author:** ![jmcastro2109](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jmcastro2109/32/38427_2.png) [@jmcastro2109](https://discourse.julialang.org/u/jmcastro2109)\
**Post date:** [December 18, 2019, 3:00pm UTC](https://discourse.julialang.org/t/equivalent-function-to-licols-in-matlab/32445/3 "2019-12-18T15:00:00Z")

</div>

Amazing. Thanks!

Obtener [Outlook para iOS](https://aka.ms/o0ukef)
