Skip to content

Instantly share code, notes, and snippets.

@siddMahen
Created November 22, 2015 02:34
Show Gist options
  • Save siddMahen/509dd7cac08dba77610e to your computer and use it in GitHub Desktop.
Save siddMahen/509dd7cac08dba77610e to your computer and use it in GitHub Desktop.
function swap_col(A, i, j)
col_i = A[:,i]
col_j = A[:,j]
A[:,i] = col_j
A[:,j] = col_i
end
function swap_row(A, i, j)
row_i = A[i,:]
row_j = A[j,:]
A[i,:] = row_j
A[j,:] = row_i
end
function move_entry(A, i, j, m, n)
swap_row(A, i, m)
swap_col(A, j, n)
end
function add_row(A, i, j, k)
A[i,:] += k*A[j,:]
end
function strike_col(A, j)
for i = (j + 1):size(A,1)
println(-(A[i,j]*(1/A[j,j])))
add_row(A, i, j, -(A[i,j]*(1/A[j,j])))
end
end
function choose_non_zero(A, j)
for i = j:size(A,2)
for k = j:size(A,1)
if A[k,i] != 0
return (k,i)
end
end
end
return (0,0)
end
function make_ut(A)
for j = 1:(size(A,1) - 1)
(alpha, beta) = choose_non_zero(A,j)
if alpha == 0
return A
end
move_entry(A, alpha, beta, j, j)
strike_col(A, j)
end
return A
end
println(make_ut([1.0 3.0 2.0; 3.0 2.0 4.0; 5.0 -6.0 3.2]))
@siddMahen
Copy link
Author

Transforms a matrix A into an upper triangular matrix, using only row operations of type 1 and 3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment