<jupyter_start><jupyter_text>def gauss:|x1|x2|x3|x4|b||---|---|---|---|---||-2|-9|-3|7|-26||-7|2|2|5|-25||-6|2| | |-16|| |-3|8|-3|-5|<jupyter_code>#Вывод таблицы для ввода
box_layout = wd.Layout(display='flex',
                        flex_flow='row',
                        align_items='stretch',
                        width='100%')
w_row_1 = wd.Box(children=rows[0], layout=box_layout)
w_row_2 = wd.Box(children=rows[1], layout=box_layout)
w_row_3 = wd.Box(children=rows[2], layout=box_layout)
w_row_4 = wd.Box(children=rows[3], layout=box_layout)
box = wd.VBox(children=[w_row_1, w_row_2, w_row_3, w_row_4])
display(box)
def gauss():
    A = get_values_from_matrix(rows)
    n, m = len(A), len(A[0])
    if not check_matrix(A): return -1
    #Прямой ход
    for k in range(n):
        select_leading_elem(A, k)
        for i in range(k + 1, n):
            f = float(A[i][k])/A[k][k]
            for j in range(k, m):
                A[i][j] -= A[k][j] * f
        print_iteration(A, k+1) #Вывод изменений по итерациям
    #Обратний ход
    print("_________________________________________________________________________________________________________")
    x = []
    for i in range(n - 1, -1, -1):
        x.insert(0, A[i][n] / A[i][i])
        A[i][n] = A[i][n] / A[i][i]
        for k in range(i - 1, -1, -1):
            A[k][n] -= A[k][i] * x[0]
            A[k][i] = 0
        A[i][i] = 1
        print_iteration(A, 4-i)
    return x
p = gauss()
import numpy as np
display(Markdown(f"### x<sub>1</sub> = {p[0]}\n"
f"### x<sub>2</sub> = {p[1]} \n ### x<sub>3</sub> = {p[2]} \n ### x<sub>4</sub> = {p[3]} "))
#Решение через библиотеку numpy
A1 = np.array([])
A1 = np.append(A1, get_values_from_matrix(rows))
A1 = A1.reshape(4,5)
b = A1[:, -1]
A1 = A1[:, :-1]

print(A1.shape, b.shape)
x = np.linalg.solve(A1, b)
display(Markdown(f"### x<sub>1</sub> = {x[0]}\n"
f"### x<sub>2</sub> = {x[1]} \n ### x<sub>3</sub> = {x[2]} \n ### x<sub>4</sub> = {x[3]} "))
B = np.dot(A1, p)
print(B)<jupyter_output>[-26. -25. -16.  -5.]
{'fraction_non_alphanumeric': 0.2315270935960591, 'fraction_numerical': 0.04532019704433497, 'mean_word_length': 2.810506566604128, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '402869', 'license': 'MIT', 'n_tokens_mistral': 931, 'n_tokens_neox': 919, 'n_words': 167, 'path': 'Labs_1.ipynb', 'repo_name': 'Dotyushka666/Labs_num_methods_6sem', 'size': '2030'}