Loading [MathJax]/jax/output/HTML-CSS/jax.js
Skip to main content
Library homepage
 

Text Color

Text Size

 

Margin Size

 

Font Type

Enable Dyslexic Font
Mathematics LibreTexts
  • You do not have permission to view this page - please try signing in.

6.2: Jacobi Method for solving Linear Equations

( \newcommand{\kernel}{\mathrm{null}\,}\)

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 

 x+5y+ z=3 

2x+ y+4z=27

Here is a basic outline of the Jacobi method algorithm:

  1. Initialize each of the variables as zero x0=0,y0=0,z0=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 xi from y(i1) and z(i1) based on the first equation: xi=42y(i1)+z(i1)6. Similarly, we can obtain the update for yi and zi 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 xi, yi, and zi based on x(i1),y(i1), and z(i1).

Do This

Complete the following code by adding formulas for yi and zi to solve the above equations using the Jacobi method.

Login with LibreOne to run this code cell interactively.

If you have already signed in, please refresh the page.

%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);
%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);
Question

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

x=

y=

z=

Do This

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

Login with LibreOne to run this code cell interactively.

If you have already signed in, please refresh the page.

# Put your code here
# 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 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.

Support Center

How can we help?