예제 #1
0
def matrix_product(rows1, cols1, rows2, cols2):
    '''Матричное произведение'''
    number_of_rows_for_first_matrix, number_of_cols_for_first_matrix = rows1, cols1
    number_of_rows_for_second_matrix, number_of_cols_for_second_matrix = rows2, cols2
    try:
        first_matrix = Matrix(matrix_parsing(number_of_rows_for_first_matrix, number_of_cols_for_first_matrix))
        second_matrix = Matrix(matrix_parsing(number_of_rows_for_second_matrix, number_of_cols_for_second_matrix))
        result = first_matrix.matrix_product(second_matrix)
        click.echo(result)
    except ValueError:
        click.echo('Количество столбцов первой матрицы не равно количеству строк второй матрицы')
    except TypeError:
        click.echo('Это не матрица')
예제 #2
0
def el_by_el_mul(rows1, cols1, rows2, cols2):
    '''Поэлементное произведение'''
    number_of_rows_for_first_matrix, number_of_cols_for_first_matrix = rows1, cols1
    number_of_rows_for_second_matrix, number_of_cols_for_second_matrix = rows2, cols2
    try:
        first_matrix = Matrix(matrix_parsing(number_of_rows_for_first_matrix, number_of_cols_for_first_matrix))
        second_matrix = Matrix(matrix_parsing(number_of_rows_for_second_matrix, number_of_cols_for_second_matrix))
        result = first_matrix * second_matrix
        click.echo(result)
    except ValueError:
        click.echo('Размеры матриц должны совпадать')
    except TypeError:
        click.echo('Это не матрица')
예제 #3
0
def transpose_matrix(rows, cols):
    '''Транспонирование'''
    number_of_rows, number_of_cols = rows, cols
    try:
        mtrx = Matrix(matrix_parsing(number_of_rows, number_of_cols))
        result = mtrx.get_transpose_matrix
        click.echo(result)
    except ValueError:
        click.echo('Ошибка')
    except TypeError:
        click.echo('Возникла ошибка')
예제 #4
0
def trace(rows, cols):
    '''Вычисление следа'''
    number_of_rows, number_of_cols = rows, cols
    try:
        mtrx = Matrix(matrix_parsing(number_of_rows, number_of_cols))
        result = mtrx.get_trace
        click.echo(result)
    except ValueError:
        click.echo('Количество столбцов первой матрицы не равно количеству строк второй матрицы')
    except TypeError:
        click.echo('Возникла ошибка')
예제 #5
0
def vec_by_matrix(vec, rows, cols):
    '''Умножение вектора на матрицу'''
    number_of_rows = rows
    number_of_cols = cols
    try:
        vec = Vector(vec)
        mtrx = Matrix(matrix_parsing(number_of_rows, number_of_cols))
        result = vec.vector_by_matrix(mtrx)
        click.echo(result)
    except ValueError:
        click.echo('Ошибка')
    except TypeError:
        click.echo('Возникла ошибка')
예제 #6
0
def matrix_by_scalar(scal, rows, cols):
    '''Умножение матрицы на скаляр'''
    number_of_rows = rows
    number_of_cols = cols
    try:
        scal = Scalar(scal)
        mtrx = Matrix(matrix_parsing(number_of_rows, number_of_cols))
        result = mtrx * scal
        click.echo(result)
    except ValueError:
        click.echo('Ошибка')
    except TypeError:
        click.echo('Возникла ошибка. Скаляр - число')
예제 #7
0
def inverse_matrix(rows, cols):
    '''Вычисление обратной матрицы'''
    number_of_rows, number_of_cols = rows, cols
    if number_of_rows != number_of_cols:
        click.echo('Количество строк должно совпадать с количеством столбцов')
        return
    try:
        mtrx = Matrix(matrix_parsing(number_of_rows, number_of_cols))
        result = mtrx.get_inverse_matrix
        click.echo(result)
    except ValueError:
        click.echo('Ошибка')
    except TypeError:
        click.echo('Возникла ошибка')
예제 #8
0
def determinant(rows, cols):
    '''Вычисление определителя'''
    number_of_rows, number_of_cols = rows, cols
    if number_of_rows != number_of_cols:
        click.echo('Количество строк должно совпадать с количеством столбцов')
        return
    try:
        mtrx = Matrix(matrix_parsing(number_of_rows, number_of_cols))
        result = mtrx.get_determinant
        click.echo(result)
    except ValueError:
        click.echo('Ошибка')
    except TypeError:
        click.echo('Возникла ошибка')