0% found this document useful (0 votes)
93 views4 pages

Gauss Jacobi Method

The document describes solving a system of 3 equations with 3 unknowns using the Gauss-Jacobi iterative method. The system is set up and the initial approximations are defined. Over 10 iterations, the approximations converge, with residuals and errors calculated at each step. Formulas for calculating residuals and errors at each iteration are also provided.

Uploaded by

SHRunited Fc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
93 views4 pages

Gauss Jacobi Method

The document describes solving a system of 3 equations with 3 unknowns using the Gauss-Jacobi iterative method. The system is set up and the initial approximations are defined. Over 10 iterations, the approximations converge, with residuals and errors calculated at each step. Formulas for calculating residuals and errors at each iteration are also provided.

Uploaded by

SHRunited Fc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Gauss Jacobi Method

Solve the system of equations


4x1 + x2 + x3 = 2;
x1 + 5x2 + 2x3 = -6
x1 + 2x2 + 3x3 = -4
using the Gauss Jacobi Method. Use the initial approximation x1 = 0.5, x2 = -0.5, x3 = -0.5.

In[ ]:=

mat = {{4, 1, 1}, {1, 5, 2}, {1, 2, 3}};


mat // MatrixForm
b = {2, - 6, - 4};
b // MatrixForm
Out[ ]//MatrixForm=
4 1 1
1 5 2
1 2 3
Out[ ]//MatrixForm=
2
-6
-4

In[ ]:= list = {{"Iteration", "x1", "x2", "x3"}};


x1[0] = 0.5;
x2[0] = - 0.5;
x3[0] = - 0.5;
Fori = 1, i <= 10, i ++,
-1
x1[i] = mat[[1, 2]] x2[i - 1] + mat[[1, 3]] x3[i - 1] - b[[1]];
mat[[1, 1]]

-1
x2[i] = mat[[2, 1]] x1[i - 1] + mat[[2, 3]] x3[i - 1] - b[[2]];
mat[[2, 2]]
-1
x3[i] = mat[[3, 1]] x1[i - 1] + mat[[3, 2]] x2[i - 1] - b[[3]];
mat[[3, 3]]
val = {i, x1[i], x2[i], x3[i]};
AppendTo[list, val]
Grid[list, Dividers → ALL]
Iteration x1 x2 x3
1 0.75 - 1.1 - 1.16667
2 1.06667 - 0.883333 - 0.85
3 0.933333 - 1.07333 - 1.1
4 1.04333 - 0.946667 - 0.928889
Out[ ]= 5 0.968889 - 1.03711 - 1.05
6 1.02178 - 0.973778 - 0.964889
7 0.984667 - 1.0184 - 1.02474
8 1.01079 - 0.987037 - 0.982622
9 0.992415 - 1.00911 - 1.01224
10 1.00534 - 0.993588 - 0.9914
2 GaussJacobiMethod.nb

Residual Vector
In[ ]:= A = {{4, 1, 1}, {1, 5, 2}, {1, 2, 3}};
b = {{2}, {- 6}, {- 4}};
list = {{"Iteration", "x1", "x2", "x3", "Residual Vector"}};
x1[0] = 0.5;
x2[0] = - 0.5;
x3[0] = - 0.5;
Fori = 1, i <= 3, i ++,
-1
x1[i] = mat[[1, 2]] x2[i - 1] + mat[[1, 3]] x3[i - 1] - b[[1]];
mat[[1, 1]]

-1
x2[i] = mat[[2, 1]] x1[i - 1] + mat[[2, 3]] x3[i - 1] - b[[2]];
mat[[2, 2]]
-1
x3[i] = mat[[3, 1]] x1[i - 1] + mat[[3, 2]] x2[i - 1] - b[[3]];
mat[[3, 3]]
r[i - 1] = b - A.{{x1[i - 1]}, {x2[i - 1]}, {x3[i - 1]}};
val = {i, x1[i], x2[i], x3[i], r[i - 1] // MatrixForm};
AppendTo[list, val]
Grid[list, Dividers → ALL]
Iteration x1 x2 x3Residual Vector
1.
1 {0.75} {- 1.1} {- 1.16667} - 3.
- 2.
( 1.26667 )
Out[ ]=
2 {1.06667} {- 0.883333} {- 0.85} ( 1.08333 )
( 0.95 )
( - 0.533333 )
3 {0.933333} {- 1.07333} {- 1.1} ( - 0.95 )
( - 0.75 )
GaussJacobiMethod.nb 3

Error
In[ ]:= A = {{4, 1, 1}, {1, 5, 2}, {1, 2, 3}};
b = {{2}, {- 6}, {- 4}};
list = {{"Iteration", "x1", "x2", "x3", "Residual Vector", "Error"}};
x1[0] = 0.5;
x2[0] = - 0.5;
x3[0] = - 0.5;
Fori = 1, i <= 3, i ++,
-1
x1[i] = mat[[1, 2]] x2[i - 1] + mat[[1, 3]] x3[i - 1] - b[[1]];
mat[[1, 1]]

-1
x2[i] = mat[[2, 1]] x1[i - 1] + mat[[2, 3]] x3[i - 1] - b[[2]];
mat[[2, 2]]
-1
x3[i] = mat[[3, 1]] x1[i - 1] + mat[[3, 2]] x2[i - 1] - b[[3]];
mat[[3, 3]]
r[i - 1] = b - A.{{x1[i - 1]}, {x2[i - 1]}, {x3[i - 1]}};
error[i - 1] = {{x1[i] - x1[i - 1]}, {x2[i] - x2[i - 1]}, {x3[i] - x3[i - 1]}};
val = {i, x1[i], x2[i], x3[i], r[i - 1] // MatrixForm, error[i - 1] // MatrixForm};
AppendTo[list, val]
Grid[list, Dividers → ALL]
Iteration x1 x2 x3Residual Vector Error
1. ( 0.25 )
1 {0.75} {- 1.1} {- 1.16667} - 3. ( - 0.6 )
- 2. ( - 0.666667 )
( 1.26667 ) ( 0.316667 )
Out[ ]=
2 {1.06667} {- 0.883333} {- 0.85} ( 1.08333 ) ( 0.216667 )
( 0.95 ) ( 0.316667 )
( - 0.533333 ) ( - 0.133333 )
3 {0.933333} {- 1.07333} {- 1.1} ( - 0.95 ) ( - 0.19 )
( - 0.75 ) ( - 0.25 )
4 GaussJacobiMethod.nb

Error Format Formula :


In[ ]:= A = {{4, 1, 1}, {1, 5, 2}, {1, 2, 3}};
b = {{2}, {- 6}, {- 4}};
d = DiagonalMatrix[Diagonal[A]];
list = {{"Iteration", "x1", "x2", "x3", "Residual Vector", "Error"}};
x1[0] = 0.5;
x2[0] = - 0.5;
x3[0] = - 0.5;
Fori = 1, i <= 3, i ++,
-1
x1[i] = mat[[1, 2]] x2[i - 1] + mat[[1, 3]] x3[i - 1] - b[[1]];
mat[[1, 1]]

-1
x2[i] = mat[[2, 1]] x1[i - 1] + mat[[2, 3]] x3[i - 1] - b[[2]];
mat[[2, 2]]
-1
x3[i] = mat[[3, 1]] x1[i - 1] + mat[[3, 2]] x2[i - 1] - b[[3]];
mat[[3, 3]]
r[i - 1] = b - A.{{x1[i - 1]}, {x2[i - 1]}, {x3[i - 1]}};
error[i - 1] = Inverse[d].r[i - 1];
val = {i, x1[i], x2[i], x3[i], r[i - 1] // MatrixForm, error[i - 1] // MatrixForm};
AppendTo[list, val]
Grid[list, Dividers → ALL]
Iteration x1 x2 x3Residual Vector Error
1. 0.25
1 {0.75} {- 1.1} {- 1.16667} - 3. - 0.6
- 2. - 0.666667
( 1.26667 ) ( 0.316667 )
Out[ ]=
2 {1.06667} {- 0.883333} {- 0.85} ( 1.08333 ) ( 0.216667 )
( 0.95 ) ( 0.316667 )
( - 0.533333 ) ( - 0.133333 )
3 {0.933333} {- 1.07333} {- 1.1} ( - 0.95 ) ( - 0.19 )
( - 0.75 ) ( - 0.25 )

You might also like