The result from the loop is correct. You are using two different sets of numbers. Here is the loop computation without loops. x = {4/5,31/39} y = {2/5, 145/357} A = {62243/100000, 3239/6250, 17631/25000} A[[3]] - A[[1]]*x - A[[2]]*y