Q. This is gauss elimination python code. I want to solve gauss-jordan code with this code. import numpy as np A = np.ar

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

Q. This is gauss elimination python code. I want to solve gauss-jordan code with this code. import numpy as np A = np.ar

Post by answerhappygod »

Q. This is gauss elimination python code. I want to
solve gauss-jordan code with this code.
import numpy as np
A = np.array([[1.0, -1.0, 2.0, -1.0],
[5.0, 8.0, 6.0, 3.0],
[4.0, 2.0, 5.0, 3.0],
[3.0, 2.0, 1.0, 4.0]])
b = np.array([2.0, 10.0, 3.0, 1.0])
x = np.zeros((4,))
for i in range(0,A.shape[0]):
for j in range(i+1, A.shape[0]):
mul = A[j,i]/A[i,i]
for k in range(i,A.shape[1]):
A[j,k] -= mul*A[i,k]
b[j] -= mul*b
x[3] = b[3]/A[3,3]
for j in range (2,-1,-1):
sum = b[j]
for k in range(j+1,4):
sum -= A[j,k] * x[k]
x[j] = sum / A[j,j]
print(A)
print("x =",x)
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply