CHAPTER 04.08: GAUSS-SEIDEL METHOD: Example: Part 1 of 2

 

In this segment, we're going to talk about the Gauss-Seidel method, and we're going to take the example for Gauss-Seidel method of solving simultaneous linear equations.  So somebody's giving us, let's suppose, equations like this, three equations, three unknowns, 12 x1, plus 3 x2, minus 5 x3 is equal to 1, x1, plus 5 x2, plus 3 x3 is equal to 28, and 3 x1, plus 7 x2, plus 13 x3 is equal to 76.  Somebody's asking you to find x1, x2, x3 after two iterations, just to keep it simple, of course, in real life you will conduct more iterations than that, because you do have to try to get convergence, starting from x1, x2, x3 equal to 1, 0, 1.  So that's the initial guess which is given to us.  Some of the things which I do want to mention is that, first, how do we come up with the initial guess?  If you know the physics of the problem, that should help you, what the order of the initial guess should be, that's one way of knowing what the initial guess is.  And the other thing which I wanted to mention was that many times people think that the initial guess is always 0, 0, 0, because many of the examples in the books are given like that, but that's not necessarily true, you don't have to start from 0, 0, 0.  If you have some good idea of what the order of this . . . of the output looks like, you can use that to your advantage, because it's going to converge faster.  That's one of the advantages of using Gauss-Seidel method, that if you have some idea of what the solution will look like in terms of its order of numbers, you can use that to make it converge faster. So let's go ahead and start this as the initial guess and go ahead and apply Gauss-Seidel method to solve this example for two iterations.  So the first thing which I have to do is I have to rewrite each equation.  So the first equation I'm going to rewrite as x1 is equal to 1, minus 3 x2, plus 5 x3, divided by 12.  So you're writing the first equation by rewriting it in terms of, just in terms of x1.  Same thing you're going to do for x2, for the second equation, you're going to write it for x2, so it all makes algorithmic sense, that the first equation is written for x1, second equation for x2, third equation for x3. So x2 will be written as 28, minus x1, minus 3 x3, divided by 5. And the third equation which you have, again it will be written now for x3, so the third equation is written for the third unknown, and that will be rewritten as 76, minus 3 x1, so you're taking everything to the right-hand side except for the x3, minus 7 x2, divided by 13, because that's the coefficient of x3.  So once we have that, now we have to conduct the first iteration. So I'm going to write down here iteration number 1, and I know that the initial guess which we chose for . . . which was given to us is 1, 0, 1.  So we're going to substitute this into our equation.  So I get x1, so I'm going to substitute 1, 0, 1, into this equation, I get 1, minus 3 times x2, which is 0, plus 5 times x3, which is 1, divided by 12, and this number here turns out to be 0.5. x2 is 28, minus 3 times . . . minus x1, not 3 times, but minus x1, which is right here, and x1 is 0.5.  So it's very important that you understand that you're not using the value which you obtained, which was given to you as the solution here, initial guess here, you are using always the most recent values which you have.  So what happens is that 0.5 gets . . . this 1 gets substituted by 0.5 now for any operations which are done after that.  So that's why here for x1 you're going to substitute 0.5, not 1, minus 3 times x3, which will be still this 1, because that has not gotten updated yet, divided by 5, and that value turns out to be equal to 4.9.  Now I'm going to calculate x3. So x3 will be 76, minus 3 times x1, which is 0.5, because that's the most recent value for x1, minus 7 times x2, which is 4.9, and that's the most recent value for x2, not 0, divided by 13, and this number here turns out to be equal to 3.0923.  I'm using five significant digits in my answers, I'm not showing you the ensuing 0s here, but if you want to, you can always go ahead and do that. So this becomes my solution, or this becomes my . . . this becomes my solution at the end of the first iteration.  So what I have now is that x1, x2, x3, is now the solution which I have is 0.5, 4.9, and 3.0923. And before I go to the next iteration, what I need to do is I need to calculate the absolute relative approximate error.  So this is my new guess, and what was my old guess?  My old guess was x1, x2, x3, I started with 1, 0, 1.  So this was my old guess, this is my new guess now, or new estimate for the solution. So the first absolute relative approximate error which I get for x1, so 1 standing for x1, is present approximation, which is 0.5, minus the previous approximation, divided by the present approximation, times 100, which is 100 percent. Then I have what is the absolute relative approximate error for the second unknown, for x2, it is the present approximation, which is 4.9, minus the previous approximation, which is 0, divided by the present approximation, times 100, and that also turns out to be 100 percent, it's all coincidence, so please don't think that the first time you calculate these errors they turn out to be 100 percent, and that won't be the case, as you will see in a little bit.  And then I calculate the absolute relative approximate error now, absolute relative approximate error for the third unknown, I will get the present approximation, which is 3.0923, minus the previous approximation, which is 1, divided by the present approximation, times 100, and that number turns out to be 67.662 percent. So what you have basically done is that you have calculated the absolute relative approximate error corresponding to each of the three unknowns here, and now what you're going to do is you're going to find the maximum of these numbers.  The maximum of 100, 100, and 67.662, the maximum of the three absolute relative approximate errors which have been calculated is simply 100 percent, and that's the number which you have to compare with the . . . with the pre-specified tolerance.  You cannot compare this, or this, or this separately, but the maximum of those numbers, which is 100 percent, and that's the number which you're going to compare with the pre-specified tolerance to see that whether you have achieved that or not.  If you have not achieved the pre-specified tolerance, what that means is that you have to continue doing the iteration.  However, in this example we are only asked to conduct two iterations, so we're going to conduct one more iteration and see what happens, and then we will look at a table to see that how does this progress.  So let's go ahead and conduct iteration number 2.