Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
gj4
# augmented matrix matrix = [[3, 2, 3, 4, 2, 1, 0, 0, 0, 0], [2, 3, 4, 2, 1, 0, 1, 0, 0, 0], [3, 1, 2, 5, 2, 0, 0, 1, 0, 0], [1, 3, 1, 4, 1, 0, 0, 0, 1, 0], [3, 2, 2, 3, 1, 0, 0, 0, 0, 1]] def matrix_elimination(matrix): # pollaplasiazoume ta stoixeia 1hs grammis me ton antistrofo tou protou stoixeiou # afairoume tin 1h grammi apo ti 2h (elimination) # epanalamvanoume tin parapano diadikasia, # oste na afairethei h 1h grammi apo oles # epanalambanetai h idia diadikasia gia ti 2h grammi i, k, m, n = 0, 0, 0, 5 while i < n: # o vroxos aftos pollaplasiazei ta stoixeia kathe grammis me ton antistrofo 1ou, 2ou k.o.k stoixeiou analoga me ti grammi pou vriskomaste j = 0 # i -> diasxizei tis grammes var = matrix[i][i] # j -> diasxizei ta stoixeia kathe grammis # print ("var =", var, "", "i =", i) for e in matrix[i]: if var != 0: e = e * (1 / var) matrix[i][j] = e j = j + 1 # print ("matrix = ", matrix) m = k + 1 while m < n: # o vroxos aftos pollaplasiazei ta stoixeia mias grammis me tin "var1" kai ektelei afairesi ton grammon var1 = matrix[m][i] # print ("var1 =", var1) k = i while k < 2*n: # k -> diasxizei ola ta stoixeia mias grammis matrix[m][k] = matrix[m][k] - (matrix[i][k] * var1 ) k = k + 1 m = m + 1 k = i k = k + 1 i = i + 1 # print (*matrix, sep = "\n") return matrix upper_triangular_matrix = matrix_elimination(matrix) print ("upper_triangular_matrix =",*upper_triangular_matrix, sep = "\n") def upper_triangular_matrix_elimination(upper_triangular_matrix): n = 5 i, j, k = n-1, n - 1, 0 # pollaplasiazoume tin teleftea grammi me to telefteo stoixeio tis protelefteas kai afairoume "proteleftea - teleftea"... # anaferomaste sto proto miso tou arxikou pinaka while j > 0: # print ("j =", j) i = n - 1 - k while i > 0: p = 0 var = upper_triangular_matrix[i - 1][j] # print ("var =", var, "", "i =", i) for e in upper_triangular_matrix[j]: e = e * var if e != 0: break upper_triangular_matrix[i - 1][p] = upper_triangular_matrix[i - 1][p] - e p = p + 1 # print (*inverse_matrix, sep = "\n") i = i - 1 k = k + 1 j = j - 1 return upper_triangular_matrix diagonal_matrix = upper_triangular_matrix_elimination(upper_triangular_matrix) print ("diagonal_matrix =", *diagonal_matrix, sep = "\n")
run
|
edit
|
history
|
help
0
python, Polymorphie, attributes, setter and getter the pythonic way (V3)
Convert to lowercase
Ok
0403_diamond
Bucket sort using LinkedList for each bucket
quck sort
My Personal data
Hello wold Happy
Quick sort
gj