6.2: Jacobi Method for solving Linear Equations

Matrix Algebra with Computational Applications · LibreTexts

0%

Contents

    Text

    Size
    100%
    Theme
    Typeface
    Line length
    Spacing

    From LibreTexts, under CC BY-NC 4.0, as the source states it; its equations are written in TeX, which the PDF shows typeset. This page at LibreTexts.

    6.2: Jacobi Method for solving Linear Equations

    During class today we will write an iterative method (named after Carl Gustav Jacob Jacobi) to solve the following system of equations:

    \[ 6x + 2y - ~z = 4~ \nonumber \]

    \[~ x + 5y + ~z = 3~ \nonumber \]

    \[ 2x +~ y + 4z = 27 \nonumber \]

    Here is a basic outline of the Jacobi method algorithm:

    1. Initialize each of the variables as zero \( x_0 = 0, y_0 = 0, z_0 = 0 \)
    2. Calculate the next iteration using the above equations and the values from the previous iterations. For example here is the formula for calculating \(x_i\) from \(y_{(i-1)}\) and \(z_{(i-1)}\) based on the first equation: \(x_i = \dfrac{4-2y_{(i-1)} + z_{(i-1)}}{6} \). Similarly, we can obtain the update for \(y_i\) and \(z_i\) from the second and third equations, respectively.
    3. Increment the iteration counter \(i=i+1\) and repeat Step 2.
    4. Stop when the answer “converges” or a maximum number of iterations has been reached. (ex. \(i = 100\))
    Important Note

    A sufficient (but not necessary) condition for the method to converge is that the matrix A is strictly or irreducibly diagonally dominant. Strict row diagonal dominance means that for each row, the absolute value of the diagonal term is greater than the sum of absolute values of other terms. - From Wikipedia

    In other words, the Jacobi Methid will not work an all problems.

    Do This

    Write out the equations for \(x_i\), \(y_i\), and \(z_i\) based on \(x_{(i−1)}, y_{(i−1)}\), and \(z_{(i−1)}\).

    Do This

    Complete the following code by adding formulas for \(y_i\) and \(z_i\) to solve the above equations using the Jacobi method.

    %matplotlib inline
    import matplotlib.pylab as plt
    
    x = []
    y = []
    z = []
    
    #step 1: inicialize to zero
    x.append(0)
    y.append(0)
    z.append(0)
    
    for i in range(1,100):
        xi = (4 - 2*y[i-1]+ z[i-1])/6
    #####Start your code here #####
        yi = 0 #Change this line
        zi = 0 #Change this line
    #####End of your code here#####        
        #Add latest value to history
        x.append(xi)
        y.append(yi)
        z.append(zi)
    
    #Plot History of values
    plt.plot(x, label='x')
    plt.plot(y, label='y')
    plt.plot(z, label='z')
    plt.xlabel('Iteration')
    plt.ylabel('Value')
    plt.legend(loc=1);
    Illustration
    Question

    What are the final values for \(x\), \(y\), and \(z\)?

    \[ x = \nonumber \]

    \[ y = \nonumber \]

    \[ z = \nonumber \]

    Do This

    Write out each of the above equations and show that your final result is a solution to the system of equations:

    # Put your code here
    Question

    By inspecting the graph, how long did it take for the algorithum to converge to a solution?

    Question

    How could you rewrite the above program to stop earlier.


    This page titled 6.2: Jacobi Method for solving Linear Equations was last modified on Sat, 17 Sep 2022 15:14:20 GMT and is shared under a CC BY-NC 4.0 license and was authored, remixed, and/or curated by Dirk Colbry via source content that was edited to the style and standards of the LibreTexts platform.