Page 114 - Applied Numerical Methods Using MATLAB
P. 114

ITERATIVE METHODS TO SOLVE EQUATIONS  103
              The following example illustrates that the Jacobi iteration and the Gauss–Seidel
            iteration can also be used for solving a system of nonlinear equations, although there
            is no guarantee that it will work for every nonlinear equation.

            Example 2.5. Gauss–Seidel Iteration for Solving a Set of Nonlinear Equations.
              We are going to use the Gauss–Seidel iteration to solve a system of nonlinear
            equations as
                                   2
                                               2
                                  x + 10x 1 + 2x − 13 = 0
                                   1           2
                                                                        (E2.5.1)
                                           2
                                      3
                                    2x − x + 5x 2 − 6 = 0
                                      1    2
              In order to do so, we convert these equations into the following form, which
            suits the Gauss–Seidel scheme.
                                               2     2
                                         (13 − x − 2x )/10
                                 x 1           1     2
                                     =          3    2                  (E2.5.2)
                                 x 2      (6 − 2x + x )/5
                                                1    2
            We make the MATLAB program “nm2e05.m”, which uses the Gauss–Seidel
            iteration to solve these equations. Interested readers are recommended to run
            this program to see that this simple iteration yields the solution within the given
            tolerance of error in just six steps. How marvelous it is to solve the system of
            nonlinear equations without any special algorithm!


            (cf) Due to its remarkable capability to deal with a system of nonlinear equations, the
               Gauss–Seidel iterative method plays an important role in solving partial differential
               equations (see Chapter 9).

             %nm2e05.m
             % use Gauss–Seidel iteration to solve a set of nonlinear equations
             clear
             kmax = 100; tol = 1e-6;
             x = zeros(2,1); %initial value
             for k = 1:kmax
                xp = x; % to remember the previous solution
                x(1) = (13 - x(1)^2 - 2*x(2)^2)/10; % (E2.5.2)
                x(2) = (6 - x(1)^3)/5;
                if norm(x - xp)/(norm(xp) + eps)<tol, break; end
             end
             k, x



            2.5.3  The Convergence of Jacobi and Gauss–Seidel Iterations

            Jacobi and Gauss–Seidel iterations have a very simple computational structure
            because they do not need any matrix inversion. So, it may be of practical use, if
            only the convergence is guaranteed. However, everything cannot always be fine,
   109   110   111   112   113   114   115   116   117   118   119