<jupyter_start><jupyter_text>Question 1<jupyter_code>from functionLibrary import fwdSub
from functionLibrary import bwdSub
from functionLibrary import dlittle
from functionLibrary import crout
from functionLibrary import solver

matrixA = open("q1-A.txt", "r+")
A = []
for row in matrixA:
    e1 = row.split()
    fe1 = []
    for i in range(len(e1)):
        fe1.append(float(e1[i]))
    A.append(fe1)


matrixb = open("q1-b.txt", "r+")
b = []
for row in matrixb:
    e1 = row.split()
    for i in range(len(e1)):
        b.append(float(e1[i]))


print("The solution using Doolittle's algorithm:" + "\n")
print( "x = " + str(solver(A,b, dlittle)) + "\n" )


print("\n" + "The solution using Crout's algorithm:" + "\n")
print( "x = " + str(solver(A,b, crout)) + "\n")<jupyter_output>The solution using Doolittle's algorithm:

L = [[1, 0, 0, 0], [0.0, 1, 0, 0], [1.0, 2.0, 1, 0], [2.0, 1.0, 1.5, 1]]

U = [[1.0, 0.0, 1.0, 2.0], [0, 1.0, -2.0, 0.0], [0, 0, 2.0, -2.0], [0, 0, 0, -3.0]]

x = [1.0, -1.0, 1.0, 2.0]


The solution using Crout's algorithm:

L = [[1.0, 0, 0, 0], [0.0, 1.0, 0, 0], [1.0, 2.0, 2.0, 0], [2.0, 1.0, 3.0, -3.0]]

U = [[1, 0.0, 1.0, 2.0], [0, 1, -2.0, 0.0], [0, 0, 1, -1.0], [0, 0, 0, 1]]

x = [1.0, -1.0, 1.0, 2.0]<jupyter_text>Question 2<jupyter_code>from functionLibrary import inverseLU
from functionLibrary import swapRows
from functionLibrary import LUDecomp
from functionLibrary import fwdBwdSub
from functionLibrary import PartialPivot
from functionLibrary import multiplysquare

matrixA = open("q2.txt", "r+")
A = []
for row in matrixA:
    e1 = row.split()
    fe1 = []
    for i in range(len(e1)):
        fe1.append(float(e1[i]))
    A.append(fe1)

I = [[0 for i in range(len(A))] for j in range(len(A))]
for k in range(len(A)):
    I[k][k] = 1.0


X = inverseLU(A,I)

verification = multiplysquare(X,A)<jupyter_output>Lower Triangular
[1, 0, 0, 0]
[0.0, 1, 0, 0]
[0.0, 0.5, 1, 0]
[0.0, 0.0, -0.25, 1]
Upper Triangular
[3.0, 7.0, 1.0, 0.0]
[0, 2.0, 8.0, 6.0]
[0, 0, -4.0, -2.0]
[0, 0, 0, 1.5]
The inverse of the given matrix is 
[0.3333333333333333, -0.25000000000000006, -1.8333333333333333, 1.6666666666666667]
[0.0, 0.08333333333333337, 0.8333333333333333, -0.6666666666666667]
[-0.0, 0.16666666666666666, -0.3333333333333333, -0.3333333333333333]
[0.0, -0.08333333333333333, 0.16666666666666666, 0.6666666666666666]
The product of 
[0.3333333333333333, -0.25000000000000006, -1.8333333333333333, 1.6666666666666667]
[0.0, 0.08333333333333337, 0.8333333333333333, -0.6666666666666667]
[-0.0, 0.16666666666666666, -0.3333333333333333, -0.3333333333333333]
[0.0, -0.08333333333333333, 0.16666666666666666, 0.6666666666666666]
and 
[3.0, 7.0, 1.0, 0.0]
[0.0, 2.0, 8.0, 6.0]
[0.0, 1.0, 0.0, 1.0]
[0.0, 0.0, 1.0, 2.0]
is
[1.0, 0, 0, 0]
[0, 1.0, 0, 0]
[0, 0, 1.0, 0]
[0, 0, 0, 1.0]<jupyter_text>Question 3<jupyter_code>from functionLibrary import cholesky
from functionLibrary import choleskySolver
from functionLibrary import transpose


matrixA = open("q3-A.txt", "r+")
A = []
for row in matrixA:
    e1 = row.split()
    fe1 = []
    for i in range(len(e1)):
        fe1.append(float(e1[i]))
    A.append(fe1)


matrixb = open("q3-b.txt", "r+")
b = []
for row in matrixb:
    e1 = row.split()
    for i in range(len(e1)):
        b.append(float(e1[i])) 

l = cholesky(A)

x = choleskySolver(l, transpose(l), b)
print("Using Cholesky algorithm, the solution matrix is: ")
print(x)<jupyter_output>Using Cholesky algorithm, the solution matrix is: 
[0.09999999999999996, 0.2, 0.3, 0.4000000000000001]
{'fraction_non_alphanumeric': 0.18902439024390244, 'fraction_numerical': 0.20814855875831487, 'mean_word_length': 3.3169856459330145, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 28, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '332956', 'license': 'Apache-2.0', 'n_tokens_mistral': 2108, 'n_tokens_neox': 1621, 'n_words': 403, 'path': 'assignment-4/assignment-4.ipynb', 'repo_name': 'peakcipher/p346-computational-lab', 'size': '3608'}