0% found this document useful (0 votes)
40 views

Practical 5 Gauss Jacobi Method To Solve Systems of Linear Equations Q: 4x + x2 + x3 2 x1 + 5x2 + x3 - 6 x1 + 2x2 + 3x3 - 4

The document shows the Gauss-Jacobi method used to solve a system of 3 linear equations with 3 unknowns. The system is written in matrix form as AX=B. The matrices L, U, and D are used to iteratively solve for the unknowns x1, x2, x3. The iterative process is repeated 5 times, showing the approximations converge to the final solution of x1=0.968889, x2=-1.03711, x3=-1.05. A second example solves another 3x3 system and again shows the iterative approximations converging to the final solution.

Uploaded by

Rito Chakraborty
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views

Practical 5 Gauss Jacobi Method To Solve Systems of Linear Equations Q: 4x + x2 + x3 2 x1 + 5x2 + x3 - 6 x1 + 2x2 + 3x3 - 4

The document shows the Gauss-Jacobi method used to solve a system of 3 linear equations with 3 unknowns. The system is written in matrix form as AX=B. The matrices L, U, and D are used to iteratively solve for the unknowns x1, x2, x3. The iterative process is repeated 5 times, showing the approximations converge to the final solution of x1=0.968889, x2=-1.03711, x3=-1.05. A second example solves another 3x3 system and again shows the iterative approximations converging to the final solution.

Uploaded by

Rito Chakraborty
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Practical 5

Gauss Jacobi Method to solve


Systems of Linear Equations
Q: 4x + x2 + x3 = 2
x1 + 5x2 + x3 = -6
x1 + 2x2 + 3x3 = -4

In[21]:= A = {{4, 1, 1}, {1, 5, 2}, {1, 2, 3}};


X = {x1, x2, x3 };
x = {0.5, - 0.5, - 0.5 };
B = {2, - 6, - 4};
Print ["AX = B"]
Print ["The System of Linear Equations in matrix form is:",
MatrixForm [A], "* " MatrixForm [X], "= " MatrixForm [B]]
l = {{0, 0, 0}, {1, 0, 0}, {1, 2, 0}}
u = {{0, 1, 1}, {0, 0, 2}, {0, 0, 0}}
d = {{4, 0, 0}, {0, 5, 0}, {0, 0, 3}}
For [k = 1, k ≤ 5, k ++ ,
y = Inverse [d].(B - l.x - u.x);
x = N[y];
Print [k, "th apporximate solution is = ", MatrixForm [x]]]
Print ["the final solution is = ", MatrixForm [x]]

AX = B

4 1 1 x1 2
The System of Linear Equations in matrix form is: 1 5 2 * x2 = - 6
1 2 3 x3 -4

Out[27]= {{0, 0, 0}, {1, 0, 0}, {1, 2, 0}}

Out[28]= {{0, 1, 1}, {0, 0, 2}, {0, 0, 0}}

Out[29]= {{4, 0, 0}, {0, 5, 0}, {0, 0, 3}}


2

0.75
1th apporximate solution is = - 1.1
- 1.16667

1.06667
2th apporximate solution is = - 0.883333
- 0.85

0.933333
3th apporximate solution is = - 1.07333
- 1.1

1.04333
4th apporximate solution is = - 0.946667
- 0.928889

0.968889
5th apporximate solution is = - 1.03711
- 1.05

0.968889
the final solution is = - 1.03711
- 1.05

In[32]:= A = {{2, 1, 1}, {- 1, 2, - 1}, {0, - 1, 2}};


X = {x1, x2, x3 };
x = {2, 1, 7};
B = {7, 1, 1};
Print ["AX = B"]
Print ["The System of Linear Equations in matrix form is:",
MatrixForm [A], "* " MatrixForm [X], "= " MatrixForm [B]]
l = {{0, 0, 0}, {- 1, 0, 0}, {0, - 1, 0}}
u = {{0, 1, 0}, {0, 0, - 1}, {0, 0, 0}}
d = {{2, 0, 0}, {0, 2, 0}, {0, 0, 2}}
For [k = 1, k ≤ 5, k ++ ,
y = Inverse [d].(B - l.x - u.x);
x = N[y];
Print [k, "th apporximate solution is = ", MatrixForm [x]]]
Print ["the final solution is = ", MatrixForm [x]]

AX = B

2 1 1 x1 7
The System of Linear Equations in matrix form is: - 1 2 - 1 * x2 = 1
0 -1 2 x3 1

Out[38]= {{0, 0, 0}, {- 1, 0, 0}, {0, - 1, 0}}

Out[39]= {{0, 1, 0}, {0, 0, - 1}, {0, 0, 0}}

Out[40]= {{2, 0, 0}, {0, 2, 0}, {0, 0, 2}}


3

3.
1th apporximate solution is = 5.
1.
1.
2th apporximate solution is = 2.5
3.
2.25
3th apporximate solution is = 2.5
1.75
2.25
4th apporximate solution is = 2.5
1.75
2.25
5th apporximate solution is = 2.5
1.75
2.25
the final solution is = 2.5
1.75

You might also like