% FIGURE 4.2.1
%                             N = NUMBER OF GRID POINTS
      N = 100;
      DX = pi/N;
%                             BOUNDARY VALUES SET
      U(1) =  0.5;
      U(N+1) = -0.5;
%                             INITIAL GUESS SATISFIES BNDRY. CONDITIONS
      for I=2:N
         XI = (I-1)*DX;
         U(I) = 0.5-XI/pi;
      end
%                             BEGIN NEWTON ITERATION
      for ITER=1:15
         for I=2:N
%                             CALCULATE F AND 3 DIAGONALS OF JACOBIAN
            F(I-1) = (U(I+1)-2*U(I)+U(I-1))/DX^2 -   ...
                  ((U(I+1)-U(I-1))/(2*DX))^2 - U(I)^2 + U(I) + 1;
            A(I-1) =  1/DX^2 + (U(I+1)-U(I-1))/(2*DX^2);
            B(I-1) = -2/DX^2 - 2*U(I) + 1;
            C(I-1) =  1/DX^2 - (U(I+1)-U(I-1))/(2*DX^2);
         end
%                             CALL TRI TO SOLVE TRIDIAGONAL SYSTEM
         DELTA = TRI(A,B,C,F,N-1);
%                             UPDATE SOLUTION AND CALCULATE MAX. ERROR
         ERMAX = 0.0;
         for I=2:N
            U(I) = U(I) - DELTA(I-1);
            XI = (I-1)*DX;
            ERR = abs(U(I) - sin(XI+pi/6.));
            ERMAX = max(ERMAX,ERR);
         end
         ERMAX
      end
