def OkButtonClicked(self): """listwidgitem = QListWidgetItem() listwidgitem.setSizeHint(QtCore.QSize(self.listWidget.width(), 100)) listwidgitem.setText("ress") self.listWidget.addItem(listwidgitem) self.listWidget.setItemWidget(self.listWidget.item(1), QTextEdit("1)<html><head/><body><p>x<span style=\" vertical-align:sub;\">0</span></p></body></html>")) """ a = np.empty((self.Dim, self.Dim)) b = np.empty((self.Dim)) for i in range(self.Dim): for j in range(self.Dim): try: a[i, j] = np.float64(self.InputTableWidget.item(i, j).text()) self.InputTableWidget.item(i,j).setBackground(QtGui.QColor(255,255,255)) except: self.InputTableWidget.setItem(i, j, QTableWidgetItem()) self.InputTableWidget.item(i,j).setBackground(QtGui.QColor(255,128,128)) return -1; if self.methodBox.currentIndex() != 3: for i in range(self.Dim): try: b[i] = np.float64(self.InputTableWidget.item(i, self.Dim).text()) self.InputTableWidget.item(i,self.Dim).setBackground(QtGui.QColor(255,255,255)) except: self.InputTableWidget.setItem(i, self.Dim, QTableWidgetItem()) self.InputTableWidget.item(i, self.Dim).setBackground(QtGui.QColor(255,128,128)) return -1; if self.methodBox.currentIndex()==0: tabels = [] tabels.append(genTable(a, b, np.sum(a, 1)+b, np.sum(a, 1)+b)) gauss_d = gauss_det(a) a, b, Sum, S, tabels1 = gauss(a, b) tabels += tabels1 html = genHtml(tables=tabels) self.textBrowser.setText(html.replace('{%det%}','Det(A) = {0}'.format(gauss_d))) elif self.methodBox.currentIndex() == 1: for i in range(self.Dim): for j in range(self.Dim): if a[i, j] != a[j, i]: QtGui.QMessageBox.warning(None, 'Warning', 'Matrix is asymetric') return x, L, D = sqrt_method(a, b) Dtmp = np.zeros((len(D), len(D))) for i in range(len(D)): Dtmp[i, i] = D[i] tabels = [] tabels.append(genMatrix(L)) tabels.append(genMatrix(Dtmp)) tabels.append(genVector(x)) self.textBrowser.setText(genHtml(tabels, labels=['L', 'D', 'X']).replace('{%det%}','Det(A) = {0}'.format(np.prod(D)))) elif self.methodBox.currentIndex() == 2: C = np.zeros(self.Dim) B = np.zeros(self.Dim) A = np.zeros(self.Dim) for i in range(self.Dim): C[i] = a[i, i] if i!= self.Dim-1: B[i] = a[i, i+1] A[i+1] = a[i+1, i] x = TDMA(A, B, C, b) tabels = [] tabels.append(genVector(x)) self.textBrowser.setText(genHtml(tabels, ['X']).replace('{%det%}','Det(A) = {0}'.format(np.linalg.det(a)))) elif self.methodBox.currentIndex() == 3: inverse = inverse_matrix(a) self.textBrowser.setText(genHtml(np.array([genMatrix(inverse)]), ['Inverse Matrix']).replace('{%det%}', '')) elif self.methodBox.currentIndex() == 4: x0 = np.zeros(self.Dim) for i in range(self.Dim): try: x0[i] = np.float64(self.InputTableWidget.item(i, self.Dim+1).text()) except: continue try: N = np.int32(self.InputTableWidget.item(0, self.Dim+2).text()) except: pass x = jacobi(a, b, N, x0) self.textBrowser.setText(genHtml(np.array([genVector(x)]), ['X']).replace('{%det%}', '')) elif self.methodBox.currentIndex() == 5: try: eps = np.float64(self.InputTableWidget.item(0, self.Dim+1).text()) except: eps = 10**(-10) x, N = seidel(a, b, eps) self.textBrowser.setText(genHtml(np.array([genVector(x)]), ['X']).replace('{%det%}', str(N)))
def main(): for n in range(100, 2000, 100): start = datetime.now() a = numpy.array([[1 / (i + j - 1) for i in range(1, n + 1)] for j in range(1, n + 1)]) b = numpy.array([sum(a[i]) for i in range(n)]) seidel.seidel(a, b, eps=0.01) end = datetime.now() print(n, end - start)
def check(N, a, o): alfa = a A = np.zeros((N, N), float) AA = np.zeros((N, N), float) b = np.zeros(N) bb = np.zeros(N, float) x0 = np.zeros(N) A[0, 0] = 2 A[0, 1] = -1 + alfa A[N - 1, N - 1] = 2 A[N - 1, N - 2] = -1 + alfa b[0] = 1 - alfa b[N - 1] = 1 + alfa x0[0] = 0.7 x0[N - 1] = 0.8 for i in range(1, N - 1, 1): A[i, i] = 2 A[i, i + 1] = -1 + alfa A[i, i - 1] = -1 + alfa b[i] = 0 x0[i] = 0.1 * i xj, kj, tj = jacobi.jacobi(A, b, x0, 0.00001, 1000) xjv, kjv, tjv = jacobi.jacobi_vec(A, b, x0, 0.00001, 1000) xs, ks, tjs = seidel.seidel(A, b, x0, 0.00001, 1000) xsv, ksv, tsv = seidel.seidel_vec(A, b, x0, 0.00001, 1000) xsor, ksor, tsor = sor.sor(A, b, x0, o, 0.00001, 1000) xsorv, ksorv, tsorv = sor.sor_vec(A, b, x0, o, 0.00001, 1000) xcg, kcg, tcg = cg.cg(A, b, 0.00001, 1000) return kj, kjv, ks, ksv, ksor, ksorv, kcg
try: if 'input_file' in params: matr_list, vect_list = io_lib.read(params['input_file'], params['input_type'], params['separator'], matr_list, vect_list, True) else: matr_list, vect_list = io_lib.read('', params['input_type'], params['separator'], matr_list, vect_list, False) except Exception as error_msg: print(error_msg) exit(1) matr = matrix(matr_list) vect = vector(vect_list) deltatime = 0 try: if params['method'] == 'SEIDEL': solver = seidel() deltatime = datetime.now() statistics, solution = solver.use_seidel(matr, vect, precision, iterations, silent, interval) deltatime = datetime.now() - deltatime else: solver = implicit() deltatime = datetime.now() statistics, solution = solver.use_implicit(matr, vect, precision, iterations, silent, interval) deltatime = datetime.now() - deltatime except Exception as error_msg: print(error_msg) exit(1) if not silent: print('time - ' + str(deltatime)) print('Dimension of matrix ' + str(matr.cnt_row())) if 'output_file' in params:
def Parse(equations, type, n, IntialGuesses, ea, it): # It will read the entire file global con global a global x a = np.zeros((n, n + 1)) x = np.zeros(n) k = 0 alphabets = {} while k < n: con = equations[k] con = con.replace(' ', '') for element in con: if element.isalpha(): alphabets[element] = 0 k += 1 j = 0 for i in alphabets: alphabets[i] = j j += 1 k = 0 while k < n: con = equations[k] con = con.replace(' ', '') count = 0 while (count < len(con)): if con[count].isalpha() and ((con[count - 2].isdigit() == False and con[count - 1].isdigit() == False) or (count == 0)): con = con[:count] + '1*' + con[count:] count += 1 count = 0 z = re.findall(r"[+-]?\d+(?:\.\d+)?", con) f = 0 for element in con: if element.isalpha() and (con[count - 2].isdigit() or con[count - 1].isdigit()): a[k][alphabets[element]] = z[f] f += 1 if count + 1 >= len(con) and element.isdigit(): a[k][n] = -1 * float(z[f]) f += 1 elif count + 1 < len(con) and element.isdigit(): if con[count + 1] != "*" and con[count + 1] != "." and con[ count + 1].isdigit() == False and con[count + 1].isalpha() == False: a[k][n] = -1 * float(z[f]) f += 1 count += 1 k += 1 if type == 'LU': arr1 = temp.LU(a) f = open("LU.txt", "w") for i in range(0, len(arr1)): f.write(str(arr1[i])) f.write(" ") f.close() return arr1, string elif type == "Gaussian-jordan": arr2 = Gauss_Jordan.Gaussian_jordan(a) f = open("jordan.txt", "w") for i in range(0, len(arr2)): f.write(str(arr2[i])) f.write(" ") f.close() elif type == 'Gaussian-elimination': arr3 = Gaussian_elimination.Gaussian_elimination(a) f = open("elimination.txt", "w") for i in range(0, len(arr3)): f.write(str(arr3[i])) f.write(" ") f.close() elif type == 'seidel': results = [] errors = [] seidel.seidel(a, IntialGuesses, ea, it) f = open("seidel.txt", "w") for i in range(0, len(results)): f.write(str(i)) f.write(" ") for j in range(0, len(a)): f.write(str(results[i][j])) f.write(" ") for j in range(0, len(a)): if (i > 0): f.write(str(errors[i - 1][j])) f.write(" ") f.write("\n") f.close()
params['input_type'], params['separator'], matr_list, vect_list, True) else: matr_list, vect_list = io_lib.read('', params['input_type'], params['separator'], matr_list, vect_list, False) except Exception as error_msg: print(error_msg) exit(1) matr = matrix(matr_list) vect = vector(vect_list) deltatime = 0 try: if params['method'] == 'SEIDEL': solver = seidel() deltatime = datetime.now() statistics, solution = solver.use_seidel(matr, vect, precision, iterations, silent, interval) deltatime = datetime.now() - deltatime else: solver = implicit() deltatime = datetime.now() statistics, solution = solver.use_implicit(matr, vect, precision, iterations, silent, interval) deltatime = datetime.now() - deltatime except Exception as error_msg: print(error_msg) exit(1)