0% found this document useful (0 votes)
5 views1 page

Gauss-Seidel Method Implementation

The document contains a Python function implementing the Gauss-Seidel method for solving a system of linear equations. It iteratively updates the values of variables x, y, and z based on specified tolerances and prints the results after each iteration. The function limits the number of iterations to 1000 and calculates the maximum error to ensure convergence within the defined tolerances.

Uploaded by

qqempoqq
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)
5 views1 page

Gauss-Seidel Method Implementation

The document contains a Python function implementing the Gauss-Seidel method for solving a system of linear equations. It iteratively updates the values of variables x, y, and z based on specified tolerances and prints the results after each iteration. The function limits the number of iterations to 1000 and calculates the maximum error to ensure convergence within the defined tolerances.

Uploaded by

qqempoqq
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

import math

def gauss_seidel():

x = 0.55

y = 0.75

z = 0.85

tolerances = [0.1, 0.001, 0.0001, 0.000001, 0.0000001]

print(f"{'Tol':<12} | {'Iter':<5} | {'x':<10} | {'y':<10} | {'z':<10}")

print("-" * 60)

for tol in tolerances:

x, y, z = 0.55, 0.75, 0.85

iter_count = 0

error = 100.0 # Başlangıçta hatayı yüksek tutuyoruz

while error > tol and iter_count < 1000:

x_old, y_old, z_old = x, y, z

x = (26 + 4*y - 2*z) / 8

y = (12 - 5*x - 3*z) / -12

z = (6 - 2*x + 3*y) / -8

error = max(abs(x - x_old), abs(y - y_old), abs(z - z_old))

iter_count += 1

print(f"{tol:<12} | {iter_count:<5} | {x:.6f} | {y:.6f} | {z:.6f}")

gauss_seidel()

You might also like