Question

Gauss elimination using python without using any libraries for a 2d list (n x n) ....

Gauss elimination using python without using any libraries for a 2d list (n x n) .

Thanks

Homework Answers

Answer #1

CODE

def gaussElimination(A, b, n):

l = [0 for x in range(n)]

s = [0.0 for x in range(n)]

for i in range(n):

l[i] = i

max1 = 0.0

for j in range(n):

if abs(A[i][j]) > max1:

max1 = abs(A[i][j])

s[i] = max1

for i in range(n - 1):

max2 = 0.0

for j in range(i, n):

ratio = abs(A[l[j]][i]) / s[l[j]]

if ratio > max2:

max2 = ratio

rindex = j

temp = l[i]

l[i] = l[rindex]

l[rindex] = temp

for j in range(i + 1, n):

multiplier = A[l[j]][i] / A[l[i]][i]

for k in range(i, n):

A[l[j]][k] = A[l[j]][k] - multiplier * A[l[i]][k]

b[l[j]] = b[l[j]] - multiplier * b[l[i]]

x = [0.0 for y in range(n)]

x[n - 1] = b[l[n - 1]] / A[l[n - 1]][n - 1]

for j in range(n - 2, -1, -1):

summ = 0.0

for k in range(j + 1, n):

summ = summ + A[l[j]][k] * x[k]

x[j] = (b[l[j]] - summ) / A[l[j]][j]

print("\nResult = ")

for i in range(n):

print(x[i], end=" ")

matrix = [[11.0, -3.0, 5.0, 2.0], [4.0, 14.0, -1.0, -8.0], [5.0, -2.0, 4.0, 2.0], [1.0, -7.0, 5.0, 19.0]]

vector = [-13.0, -27.0, 20.0, 18.0]

gaussElimination(matrix, vector, 4)

​​​​​​​

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
WRITE A PROGRAM ON PURE PYTHON WITHOUT USING ANY LIBRARIES LIKE PANDAS AND NUMPY - Read...
WRITE A PROGRAM ON PURE PYTHON WITHOUT USING ANY LIBRARIES LIKE PANDAS AND NUMPY - Read a CSV file 'annual.csv' enterprise into a data structure - Count the number of rows and columns - Determine if the data contains empty values - Replace the empty values by 'NA' for strings, '0' for decimals and '0.0' for floats - Transform all Upper case characters to Lower case characters - Transform all Lower case characters to Upper case characters - save back...
Find the solution of the following system using Gauss elimination. (Enter your answers as a comma-separated...
Find the solution of the following system using Gauss elimination. (Enter your answers as a comma-separated list.) -18x + 2y = 6 -15x − 5y = -15 (x, y) = (  )
Solve the system of linear equations using the Gauss-Jordan elimination method x − 5y = 24...
Solve the system of linear equations using the Gauss-Jordan elimination method x − 5y = 24 4x + 2y = 8 (x, y) =
Solve the following using Gauss-Jordan elimination: x +y + z = 6, 6x +5y + 2z...
Solve the following using Gauss-Jordan elimination: x +y + z = 6, 6x +5y + 2z = 31, 4x + y -8z = 9
3x+2y=2,6x+4y=1, 5y+z=-1 solve system of eq using gauss jordan or gauss elimination
3x+2y=2,6x+4y=1, 5y+z=-1 solve system of eq using gauss jordan or gauss elimination
Solve the system of linear equations using the Gauss-Jordan elimination method. 2x + 2y + z...
Solve the system of linear equations using the Gauss-Jordan elimination method. 2x + 2y + z = 7 x + z = 2 4y − 3z = 21
1)Solve the system of linear equations, using the Gauss-Jordan elimination method. (If there is no solution,...
1)Solve the system of linear equations, using the Gauss-Jordan elimination method. (If there is no solution, enter NO SOLUTION. If there are infinitely many solutions, express your answer in terms of the parameters t and/or s.) x1 + 2x2 + 8x3 = 6 x1 + x2 + 4x3 = 3 (x1, x2, x3) = 2)Solve the system of linear equations, using the Gauss-Jordan elimination method. (If there is no solution, enter NO SOLUTION. If there are infinitely many solutions, express...
PLEASE WORK THESE OUT!! A) Solve the system of linear equations using the Gauss-Jordan elimination method....
PLEASE WORK THESE OUT!! A) Solve the system of linear equations using the Gauss-Jordan elimination method. 2x + 10y = −1 −6x + 8y = 22 x,y=_________ B) If n(B) = 14, n(A ∪ B) = 30, and n(A ∩ B) = 6, find n(A). _________ C) Solve the following system of equations by graphing. (If there is no solution, enter NO SOLUTION. If there are infinitely many solutions, enter INFINITELY MANY.) 3x + 4y = 24 6x + 8y...
Solve the following system by Gauss elimination: x + 2y?z = 22 x + 5y?2z =...
Solve the following system by Gauss elimination: x + 2y?z = 22 x + 5y?2z = ?17 x + 17y + 5z = ?1. Solve the system in from above by using Cramer’s rule. First discuss the applicabililty of Cramer’s rule to the system.
using matlab Write your own routine for Gaussian elimination without any pivoting. Input for the routine...
using matlab Write your own routine for Gaussian elimination without any pivoting. Input for the routine should consist of the number (n) of equations and the augmented matrix. Output should be the vector solution of the system. Test your code by using it to solve the following two problems: a) x + y + w + z = 10, 2x + 3y + w + 5z = 31, −x + y − 5w + 3z = −2, 3x + y...