Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8774125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:28:51+00:00 2026-06-13T18:28:51+00:00

I have a large mxn matrix, and I have identified the linearly dependent columns.

  • 0

I have a large mxn matrix, and I have identified the linearly dependent columns. However, I want to know if there’s a way in R to write the linearly dependent columns in terms of the linearly independent ones. Since it’s a large matrix, it’s not possible to do based on inspection.

Here’s a toy example of the type of matrix I have.

> mat <- matrix(c(1,1,0,1,0,1,1,0,0,1,1,0,1,1,0,1,0,1,0,1), byrow=TRUE, ncol=5, nrow=4)
> mat
      [,1] [,2] [,3] [,4] [,5]
[1,]    1    1    0    1    0
[2,]    1    1    0    0    1
[3,]    1    0    1    1    0
[4,]    1    0    1    0    1

Here it’s obvious that x3 = x1-x2, x5=x1-x4. I want to know if there’s an automated way to get that for a larger matrix.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T18:28:52+00:00Added an answer on June 13, 2026 at 6:28 pm

    I’m sure there is a better way but I felt like playing around with this. I basically do a check at the beginning to see if the input matrix is full column rank to avoid unnecessary computation in case it is full rank. After that I start with the first two columns and check if that submatrix is of full column rank, if it is then I check the first thee columns and so on. Once we find some submatrix that isn’t of full column rank I regress the last column in that submatrix on the previous one which tells us how to construct linear combinations of the first columns to get the last column.

    My function isn’t very clean right now and could do some additional checking but at least it’s a start.

    mat <- matrix(c(1,1,0,1,0,1,1,0,0,1,1,0,1,1,0,1,0,1,0,1), byrow=TRUE, ncol=5, nrow=4)
    
    
    linfinder <- function(mat){
        # If the matrix is full rank then we're done
        if(qr(mat)$rank == ncol(mat)){
            print("Matrix is of full rank")
            return(invisible(seq(ncol(mat))))
        }
        m <- ncol(mat)
        # cols keeps track of which columns are linearly independent
        cols <- 1
        for(i in seq(2, m)){
            ids <- c(cols, i)
            mymat <- mat[, ids]
            if(qr(mymat)$rank != length(ids)){
                # Regression the column of interest on the previous
                # columns to figure out the relationship
                o <- lm(mat[,i] ~ mat[,cols] + 0)
                # Construct the output message
                start <- paste0("Column_", i, " = ")
                # Which coefs are nonzero
                nz <- !(abs(coef(o)) <= .Machine$double.eps^0.5)
                tmp <- paste("Column", cols[nz], sep = "_")
                vals <- paste(coef(o)[nz], tmp, sep = "*", collapse = " + ")
                message <- paste0(start, vals)
                print(message)
            }else{
                # If the matrix subset was of full rank
                # then the newest column in linearly independent
                # so add it to the cols list
                cols <- ids
            }
        }
        return(invisible(cols))
    }
    
    linfinder(mat)
    

    which gives

    > linfinder(mat)
    [1] "Column_3 = 1*Column_1 + -1*Column_2"
    [1] "Column_5 = 1*Column_1 + -1*Column_4"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have large sets of data but somewhere in columns there is missing data
I have large set of flow charts and workflow diagrams. I want to draw
I have large tables, contains DateTime columns to store exact time of some events
I have large table. consisting of only 3 columns (id(INT),bookmarkID(INT),tagID(INT)).I have two BTREE indexes
I have large String variable named text . I want to be able to
I have large zoomable bitmaps with text, that I want to resize a little
I have large text containers and i want to compare and highlight them using
The problem: We have large product images we want thumbnails of at various size
I have large data nearly about 5,00,000 of record.I have to write it to
I have large set of images with .PNG extension (say image00.PNG). I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.