I am trying to implement the gauss seidel algorithim in C++. I will provide a working example so you can understand what im trying to do and how i need to set up the syntax so it can do that.
a + b = 5
a + 2b = 8
therefore the matrix would be:
[1 1 5]
[1 2 8]
Assume that the starting value of a and b is 0 and keep iterating until the answer the solution converges to the real answer for example:
a + 1*(0) = 5 => a = 5
1*(5) + 2*b = 8 => b = 1.5
a + 1*1.5 = 5 => a = 3.5
1*(3.5) + 2*b = 8 => b = 2.25
a + 1*(2.25) = 5 +> a = 2.75....
if you keep iterating this you will eventually arive to the answer b = 3 a = 2, (try it in excel if you would like)
now im trying to do this with a for loop so yes I want row and col1 to keep resetting to 0 but only the marker not the actual value inside of the array. So basically after each for loop I want the array elements to save their values and keep reassigning new values to value[row][col1] after each iteration thus converging closer and closer to the answer as you saw in the example i just showed. My code is below but it keeps outputting 5 4 regardless of what condition I set for i:
The process is rather simple, but it hurts me so much your variable names. I can't figure out their purpose from their names. Rename them to be more meaningful. In the meantime, I ask:
1. What is the array value for?
2. What is the array x for?
3. Why do you initialize the last column of the value array? (Although this may become clear once you answer #1).
Now what I think is needed:
You just need the array X to be X[2]:
I did not test the above, but I think it works. X[0] would be a and X[1] would be b. You run that for loop inside your big for loop and you get your estimation.