1

So far I've tried the following code but it didn't work in R-studio; it just hangs there.

Am I doing something wrong? This is my first real R code project so I'd love suggestions!

new.rref <- function(M,fractions=FALSE)
{
#M is a matrix. 
#Require numeric matricies. 
if ((!is.matrix(M)) || (!is.numeric(M)))
stop("Sorry pal! Data not a numeric matrix.")
#Specify and differentiate between rows and columns.
r=nrow(M)
c=ncol(M)
#Now establish a continuous loop (*needed help on this one)
#According to the help documents I've read, this has to do with a
#computerized version of the Gaussian Reducing Algorithm
#While 1<r and 1<c, must set first column entries in which
#1:r < 1 equal to zero. This while loop is used to loop the
#algorithm until a specific condition is met -- in this case,
#until elements in the first column to which 1:r < 1
#are set to zero. 
while((1<=r) & (1<=c))
new <- M[,1]
new[1:r < y.position] <- 0
# Now here's the fun part :)
#We need to find the maximum leading coefficient that lies
#at or below the current row. 
new1 <- which.max(abs(new))
#We will assign these values to the vector "LC"
LC <- col[which]
#Now we need to allow for row exchange!
#Basically tells R that M[c(A,B),] = M[c(B,A),].
if (which > 1) { M[c(1,which),]<-A[c(which,1),] }
#Now we have to allow for the pivot, "sweep", and restoration
#of current row. I totally didn't know how to do this so I
#used and changed some code from different documentations.
#PIVOT (friends reference)
M[1,]<-M[1,]/LC 
new2 <-M[1,]
#CLEAN
M <- M - outer(M[,x.position],new2) 
#RESTORE
A[1,]<-new2 
#Last, but certantly not least, we're going to round the matrix
#off to a certain value. I might have did this wrong.  
round(M)
return(M)
print(M)
}

Edit: I added the first line, for some reason it got deleted. Edit 2: Say you have a matrix M=matrix(c(2,3,4,7), nrow=2, ncol=2, byrow=TRUE); new.rref(M) needs to produce the reduced row echelon form of matrix M. I already did the math; new.rref(M) should be equal to matrix(c(1,0,0,1), nrow=2, ncol=2, byrow=T

3
  • Sure! The input would be any matrix M with integer entries (no fractions) and the output would be one row-reduced matrix.
    – JerBear
    Commented Mar 14, 2020 at 11:33
  • Okay! So say you have a matrix M=matrix(c(2,3,4,7), nrow=2, ncol=2, byrow=TRUE); new.rref(M) needs to produce the row reduced form of matrix M
    – JerBear
    Commented Mar 14, 2020 at 11:41
  • Sure! :D Just uploaded it
    – JerBear
    Commented Mar 14, 2020 at 12:02

0

Browse other questions tagged or ask your own question.