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

CMP 3

The document presents a series of systems of equations solved using the Gauss-Jacobi method, with detailed iterations for each problem. Four different sets of equations are provided, along with Python code to perform the calculations and the final solutions after five iterations. Each solution is rounded to four decimal places and includes the iteration outputs.

Uploaded by

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

CMP 3

The document presents a series of systems of equations solved using the Gauss-Jacobi method, with detailed iterations for each problem. Four different sets of equations are provided, along with Python code to perform the calculations and the final solutions after five iterations. Each solution is rounded to four decimal places and includes the iteration outputs.

Uploaded by

cynosure
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

COEP Technological University

Name: Yashashri Haresh Chaudhari


MIS No: 642310021
TY BTech Mechanical, Batch: H
Subject: Computational Methods of Programming (Laboratory)

Solve the following system of equations, correct to four decimal places, by


Gauss-Jacobi method. Perform 5 iterations in each problem:

1. 5x – y – z = 3, -x + 10y - 2z = 7 & -x -y + 10z = 8

import numpy as np

def gauss_jacobi(A, B, X, iterations):


for _ in range(iterations):
X = (B - (A @ X) + np.diag(A) * X) / np.diag(A)
print(f"Iteration {_+1}: {X}")
return np.round(X, 4)

A = np.array([[5, -1, -1], [-1, 10, -2], [-1, -1, 10]], dtype=float)
B = np.array([3, 7, 8], dtype=float)
X = np.zeros_like(B)

solution = gauss_jacobi(A, B, X, 5)
print("Final solution:", solution)

Solution:

Iteration 1: [0.6 0.7 0.8]


Iteration 2: [0.9 0.92 0.93]
Iteration 3: [0.97 0.976 0.982]
Iteration 4: [0.9916 0.9934 0.9946]
Iteration 5: [0.9976 0.99808 0.9985 ]
Final solution: [0.9976 0.9981 0.9985]

Page 1 of 4
COEP Technological University

2. 83x + 11y - 4z = 95, 7x + 52y +13z = 104 & 3x +8y + 29z = 71

import numpy as np

def gauss_jacobi(A, B, X, iterations):


for _ in range(iterations):
X = (B - (A @ X) + np.diag(A) * X) / np.diag(A)
print(f"Iteration {_+1}: {X}")
return np.round(X, 4)

A = np.array([[83, 11, -4], [7, 52, 13], [3, 8, 29]], dtype=float)


B = np.array([95, 104, 71], dtype=float)
X = np.zeros_like(B)

solution = gauss_jacobi(A, B, X, 5)
print("Final solution:", solution)

Solution:

Iteration 1: [1.14457831 2. 2.44827586]


Iteration 2: [0.99750727 1.23385318 1.77814707]
Iteration 3: [1.06674944 1.42118341 2.00471216]
Iteration 4: [1.05284134 1.35522107 1.94587188]
Iteration 5: [1.05874766 1.37180339 1.96550715]
Final solution: [1.0587 1.3718 1.9655]

3. 27x + 6y – z = 85, 6x + 15y + 2z = 72 & x + y + 54z = 110

import numpy as np

def gauss_jacobi(A, B, X, iterations):


for _ in range(iterations):
X = (B - (A @ X) + np.diag(A) * X) / np.diag(A)
print(f"Iteration {_+1}: {X}")

Page 2 of 4
COEP Technological University

return np.round(X, 4)

A = np.array([[27, 6, -1], [6, 15, 2], [1, 1, 54]], dtype=float)


B = np.array([85, 72, 110], dtype=float)
X = np.zeros_like(B)

solution = gauss_jacobi(A, B, X, 5)
print("Final solution:", solution)

Solution:

Iteration 1: [3.14814815 4.8 2.03703704]


Iteration 2: [2.1569273 3.2691358 1.88984911]
Iteration 3: [2.49166794 3.6852492 1.93655439]
Iteration 4: [2.40092812 3.54512557 1.92264968]
Iteration 5: [2.43155171 3.58327546 1.92692493]
Final solution: [2.4316 3.5833 1.9269]

4. 2x - 3y + 10z = 3, -x + 4y + 2z = 20 & 5x + 2y + z = -12

import numpy as np

def gauss_jacobi(A, B, X, iterations):


for _ in range(iterations):
X = (B - (A @ X) + np.diag(A) * X) / np.diag(A)
print(f"Iteration {_+1}: {X}")
return np.round(X, 4)

A = np.array([[2, -3, 10], [-1, 4, 2], [5, 2, 1]], dtype=float)


B = np.array([3, 20, -12], dtype=float)
X = np.zeros_like(B)

solution = gauss_jacobi(A, B, X, 5)
print("Final solution:", solution)

Page 3 of 4
COEP Technological University

Solution:

Iteration 1: [ 1.5 5. -12. ]


Iteration 2: [ 69. 11.375 -29.5 ]
Iteration 3: [ 166.0625 37. -379.75 ]
Iteration 4: [1955.75 236.390625 -916.3125 ]
Iteration 5: [ 4937.6484375 952.09375 -10263.53125 ]
Final solution: [ 4937.6484 952.0938 -10263.5312]

Page 4 of 4

You might also like