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 does in Matlab.

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 does in Matlab.

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.

```
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> 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
```

1 Like