def Doolittle(mat, b, n, option): lower = [[0 for x in range(n)] for y in range(n)] upper = [[0 for x in range(n)] for y in range(n)] # Decomposing matrix into Upper # and Lower triangular matrix for i in range(n): # Upper Triangular for k in range(i, n): # Summation of L(i, j) * U(j, k) sum = 0 for j in range(i): sum += (lower[i][j] * upper[j][k]) # Evaluating U(i, k) upper[i][k] = mat[i][k] - sum # Lower Triangular for k in range(i, n): if (i == k): lower[i][i] = 1 # Diagonal as 1 else: # Summation of L(k, j) * U(j, i) sum = 0 for j in range(i): sum += (lower[k][j] * upper[j][i]) # Evaluating L(k, i) lower[k][i] = int((mat[k][i] - sum) / upper[i][i]) # setw is for displaying nicely print("Lower Triangular matrix:") Services.PrintArray(lower) print("Upper Triangular matrix:") Services.PrintArray(upper) if option.lower() == 'y': Services.solveDecompositon(lower, upper, b, 'a')
import numpy as np import scipy.linalg as la import sys sys.path.append("../") import services as Services option = input("Do you want to find solution also? y or n : ") A = np.array([[4, -1, 1], [-1, 4.25, 2.75], [1, 2.75, 3.5]]) b = np.array([1, 0, 0]) print("Given Matrix=>") Services.PrintArray(A) L, D, P = la.ldl(A) Lt = np.transpose(L) print("L:") Services.PrintArray(L) print("D:") Services.PrintArray(D) print("Lt:") Services.PrintArray(Lt) if option.lower() == 'y': Services.solveLDLt(L, D, Lt, b)
# Lower Triangular for k in range(i, n): # Summation of L(k, j) * U(j, i) sum = 0 for j in range(i): sum += (lower[k][j] * upper[j][i]) # Evaluating L(k, i) lower[k][i] = int((mat[k][i] - sum) / upper[i][i]) # setw is for displaying nicely print("Lower Triangular matrix:") Services.PrintArray(lower) print("Upper Triangular matrix:") Services.PrintArray(upper) if option.lower() == 'y': Services.solveDecompositon(lower, upper, b, 'a') option = input("Do you want to find solution also? y or n : ") # Driver code mat = [[1, 2, 3], [2, -4, 6], [3, -9, -3]] b = [5, 18, 6] print("Given matrix=> ") Services.PrintArray(mat) Crouts(mat, b, len(mat), option) # This code is contributed by mits
from math import sqrt from pprint import pprint import numpy as np import scipy.linalg as la import sys sys.path.append("../") import services as Services option = input("Do you want to find solution also? y or n : ") A = np.array([[4, 2, 14], [2, 17, -5], [14, -5, 83]]) b = np.array([14, -101, 155]) print("Given Matrix=>") Services.PrintArray(A) try: Lt = la.cholesky(A) L = np.transpose(Lt) except RuntimeError as identifier: print(identifier) print("L:") for i in range(0, len(L)): for j in range(0, len(L)): print("{:15.3f}".format(L[i][j]), end=" ") print("") print("Lt:") for i in range(0, len(Lt)): for j in range(0, len(Lt)): print("{:15.3f}".format(Lt[i][j]), end=" ") print("") if option.lower() == "y": Services.solveDecompositon(L, Lt, b, 'b')
for i in range(N): x = (b - dot(R, x)) / D print("Iteratin: ", i + 1) for k in range(0, len(x)): print("x(", k + 1, ") = ", round(x[k], 6), end=", ") print("\n") return x # enter your arguments: A = [[1, 2, 1], [3, 1, 1], [1, -1, 4]] b = array([0, 0, 3]) print("Equations given =>") Services.PrintArray(A) print("Checking Condition =>") print("") arranged = copy(A) conditon = Services.CheckCondition(A) if conditon == False: arranged = Services.Arrange(arranged) if Services.isEqual(A, arranged): print( "It isn't a diagnolly dominent, Therefore solution will be diverged" ) print("") else: print("Rearranging equaitions =>")