<jupyter_start><jupyter_text><jupyter_code>import pandas as pd
import numpy as np
from numpy.linalg import solve, inv, det, norm, cond
from scipy.linalg import hilbert<jupyter_output><empty_output><jupyter_text>Качественные критерии<jupyter_code>def volume_criterion(matrix):
    vol = 1
    for n in range(matrix.shape[0]):
        vol *= norm(matrix[n])
    return vol/abs(det(matrix))
def spectrum_criterion(matrix): 
    return norm(matrix)*norm(inv(matrix))
def angle_criterion(matrix): #угловой критерий
    C = inv(matrix)
    return max([norm(a_n)*norm(c_n) for a_n, c_n in zip(matrix,np.transpose(C))])<jupyter_output><empty_output><jupyter_text>Тесты<jupyter_code>matrix1 = np.array([[-401.64, 200.12], 
               [21200.72,  -601.76]]) 

matrix2 = np.array([[-400.94, 200.02],
               [1200.12, -600.96]])
matrix3 = np.array([[1,2],
              [2,3]])

matrix4 = np.array([
    [0.1,0.2,0.3],
    [0.3,0.3,0.3],
    [0.3,0.9,0.7]])<jupyter_output><empty_output><jupyter_text>Решение<jupyter_code>array = [matrix1,matrix2, matrix3, matrix4,hilbert(4),hilbert(5)]
def solution(matrix):
    res = []
    b = np.random.uniform(-100,100,size=matrix.shape[0])
    sol = solve(matrix,b)
    for i in (-2,-5,-8):
        res.append(norm(solve(matrix-10**(i),b - 10**(i))-sol))
    return sol,res
def conditioning_numbers(matrix):
    return(spectrum_criterion(matrix),volume_criterion(matrix),angle_criterion(matrix))
X = pd.DataFrame(columns=['Спектральный критерий','Критерий Ортеги','Угловой критерий','eps=10^(-2)','eps=10^(-5)','eps=10^(-8)'])

for matrix in array:
    row = []
    row.extend(conditioning_numbers(matrix))
    row.extend(solution(matrix)[1])
    row_series = pd.Series(row,index=X.columns)
    X = X.append(row_series,True)
    
X.index = ['matrix1','matrix2','matrix3', 'matrix4','hilbert(4)','hilbert(5)']

X<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.18128654970760233, 'fraction_numerical': 0.05688463583200425, 'mean_word_length': 4.703030303030303, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '642953', 'license': 'Apache-2.0', 'n_tokens_mistral': 799, 'n_tokens_neox': 765, 'n_words': 107, 'path': 'metod1.ipynb', 'repo_name': 'ancka019/ComputationsMethods6sem', 'size': '1881'}