Пример #1
0
from numpy import *
from numpy import linalg as l
from cmlib import showMatr


def make_ort(matr):
    """

    :param matr: ndarray, rows - vectors to ort***
    :return: nothing... it's just orthogonalizing
    """
    for i in range(matr.shape[0]):
        summ = matr[i]
        for j in range(i):
            summ -= dot(matr[i], matr[j]) / dot(matr[j], matr[j]) * matr[j]
        matr[i] = summ


a = array([[1, 1, 1, 1],
           [3, 3, -1, -1],
           [-2, 0, 6, 8]], dtype='float64')
print(a)
make_ort(a)
# print(a)
showMatr(a)
Пример #2
0
from numpy import *
from numpy import linalg as l
from cmlib import showMatr

A_e = array([[15, -11, 5], [20, -15, 8], [8, -7, 6]])
f_1 = array([2, 3, 1])
f_2 = array([3, 4, 1])
f_3 = array([1, 2, 2])

s_ef = vstack((f_1, f_2, f_3)).T

A_f = dot(dot(l.inv(s_ef), A_e), s_ef)

A_f = array([[int(round(elem)) for elem in row] for row in A_f])

showMatr(A_f)
Пример #3
0
from numpy import *
from cmlib import showMatr

A = matrix([[1, 1, 2], [1, -2, -1], [2, 1, 3], [-1, 2, 1]])
print(A.shape)
showMatr(array(A))
print(linalg.matrix_rank(A) < A.shape[1])
Пример #4
0
from numpy import *
from cmlib import showMatr

A = matrix([[1, 2], [3, 4]], dtype='int')
B = matrix([[3, 5], [5, 9]], dtype='int')
res = linalg.solve(A, B)
showMatr(array(res))
Пример #5
0
from numpy import *
from numpy import linalg as l
from fractions import Fraction
from cmlib import showMatr

a = array([1, 2, 0])
b = array([2, 0, -1])
ang = dot(a, b) / (l.norm(a) * l.norm(b))
print(Fraction(str(ang)))
showMatr([[Fraction(str(ang))]])
Пример #6
0
from numpy import *
from numpy import random
from cmlib import showMatr


def is_upper_triangular(matr):  # matrix as array with shape == (n, n)
    for i in range(len(matr)):
        for j in range(i):
            if matr[i][j] != 0:
                return False
    return True


a = random.randint(1, 10, (10, 10))
b = eye(10, 10, dtype='int')
showMatr(a)
print(is_upper_triangular(a))
showMatr(b)
print(is_upper_triangular(b))
Пример #7
0
from numpy import *
from cmlib import showMatr

A = matrix([[1, 2, 0],
            [0, 2, 2]])
B = matrix([[3, -1],
            [-1, 3],
            [1, 0]])
res = (A * B).T
showMatr(array(res))
Пример #8
0
from numpy import *
from cmlib import showMatr

A = matrix([[1, 1, 2],
            [1, -2, -1],
            [2, 1, 3],
            [-1, 2, 1]])
print(A.shape)
showMatr(array(A))
print(linalg.matrix_rank(A) < A.shape[1])
Пример #9
0
from numpy import *
from numpy import linalg as l
from cmlib import showMatr

A_e = array([[15, -11, 5],
             [20, -15, 8],
             [8, - 7, 6]])
f_1 = array([2, 3, 1])
f_2 = array([3, 4, 1])
f_3 = array([1, 2, 2])

s_ef = vstack((f_1, f_2, f_3)).T

A_f = dot(dot(l.inv(s_ef), A_e), s_ef)

A_f = array([[int(round(elem)) for elem in row] for row in A_f])

showMatr(A_f)