I'm working on a linear algebra homework for a data science class. I'm suppose to make this matrix into row echelon form but I'm stuck.
Here's the current output
I would like to get rid of -0.75, 0.777, and 1.333 in A[2,0], A[3,0], and A[3,1] respectively; they should be zeroed out.
Below is my current code... can anybody please nudge me in the right direction and tell me what step I'm missing?
import numpy as np
def fixRowTwo(A) :
# Sets the sub-diagonal elements of row two to zero
A[2] = A[2] - A[2,0] * A[1]
A[2] = A[2] - A[2,1] * A[1]
# Test if diagonal element is not zero.
if A[2,2] == 0 :
# Add a lower row to row two.
A[2] = A[2] + A[3]
# Sets the sub-diagonal elements to zero again ???
A[2] = A[2] - A[2,0] * A[1]
A[2] = A[2] - A[2,1] * A[1]
if A[2,2] == 0 :
print("S I N G U L A R")
sys.Exit()
# Set the diagonal element to one
A[2] = A[2] / A[2,2]
return A
def fixRowThree(A) :
# Sets the sub-diagonal elements of row two to zero
A[3] = A[3] - A[3,0] * A[2]
A[3] = A[3] - A[3,1] * A[2]
A[3] = A[3] - A[3,2] * A[2]
# Test if diagonal element is not zero.
if A[3,3] == 0:
print("S I N G U L A R")
sys.Exit()
# Set the diagonal element to one
A[3] = A[3] / A[3,3]
return A
A = np.array([
[1, 7, 4, 3],
[0, 1, 2, 3],
[3, 2, 0, 3],
[1, 3, 1, 3]
], dtype=np.float_)
fixRowTwo(A)
print("")
print("Row Two:")
print(A)
fixRowThree(A)
print("")
print("Row Three:")
print(A)