Maths
Maths
ASSIGNMENT REPORT on
Submitted by
Amrithavarsha 4SF21CY008
BACHELOR OF ENGINEERING
in
at
1) Flowchart
2) Code
Parameters:
A: Coefficient matrix (list of lists or 2D array)
b: Constant terms vector (list or 1D array)
x0: Initial guess vector (list or 1D array)
tol: Tolerance for convergence (default: 1e-10)
max_iter: Maximum number of iterations (default: 100)
Returns:
x: Solution vector
"""
n = len(b)
x = x0.copy()
for _ in range(max_iter):
x_new = x.copy()
for i in range(n):
sum1 = sum(A[i][j] * x_new[j] for j in range(i))
sum2 = sum(A[i][j] * x[j] for j in range(i + 1, n))
x_new[i] = (b[i] - sum1 - sum2) / A[i][i]
# Interactive Input
def main():
n = int(input("Enter the number of equations: "))
print("Enter the coefficient matrix (row by row):")
A = []
for i in range(n):
row = list(map(float, input(f"Row {i + 1}: ").split()))
A.append(row)
if __name__ == "__main__":
main()
3) Output