I have this code:
for(b in seq(nrow(A), 1, -1)){
result[nrow(A)-b+1]<-A[b,ncol(A)]/A[b,b]
for(t in seq(b,(nrow(A)-1), 1)){
result[nrow(A)-b+1]<- result[nrow(A)-b+1]-(result[t,b]/A[b,b])
and getting this errorError in seq.default(b, (nrow(A) - 1), 1) : wrong sign in 'by' argument
My idea is, that second cycle in first step of first cycle doesnt run, in second step once, in third step twice...
What is wrong? It thinks maybe I wrote it bad, because in first step i have "start number" bigger by one then "end number" and with the sign of "by number" this cycle can not reach the end number.
But I need it in this way, i assumed that it in that case it just jump over that cycle...
I know I can do it with some condition before cycle, but I want to know core of the problem.
Thank you very much,
Martin!
Whole code:
Gaus<-function(A){
for(i in seq(1, nrow(A)-1, 1)){
for(n in seq(i, nrow(A)-1, 1)){
multiplier<-A[n+1,i]/A[i,i]
if(multiplier!=0)
for(ch in seq(i, ncol(A), 1)){
print(ch)
A[n+1,ch]<-A[n+1,ch]-(A[i,ch]*multiplier)
print(A)
}
}
}
result <-c()
for(b in seq(nrow(A), 1, -1)){
result[nrow(A)-b+1]<-A[b,ncol(A)]/A[b,b]
for(t in b:(nrow(A)-1)){
result[nrow(A)-b+1]<- result[nrow(A)-b+1]-(result[t,b]/A[b,b])
}
} }
A <- matrix(c(2,4,5,8,3,2,8,7,9,1,6,5), 3, 4, TRUE)
Gaus(A)`