подготовка:


In [2]:
import numpy as np
from numpy.linalg import *
rg = matrix_rank
from IPython.display import display, Math, Latex, Markdown


from sympy import *

pr = lambda s: display(Markdown('$'+str(latex(s))+'$'))

def pmatrix(a, intro='',ending='',row=False):
    if len(a.shape) > 2:
        raise ValueError('pmatrix can at most display two dimensions')
    lines = str(a).replace('[', '').replace(']', '').splitlines()
    rv = [r'\begin{pmatrix}']
    rv += ['  ' + ' & '.join(l.split()) + r'\\' for l in lines]
    rv +=  [r'\end{pmatrix}']
    if row:
        return(intro+'\n'.join(rv)+ending)
    else:
        display(Latex('$$'+intro+'\n'.join(rv)+ending+'$$'))

Задача 7

1) доно:


In [6]:
C = np.array([[1,2],
              [0,1]])
pmatrix(C, intro=r'C_{2\times 2}=')

D = np.array([[3,1],
              [1,0]])
pmatrix(D, intro=r'D_{2\times 2}=')

B = np.array([[5,1],
              [5,2]])
pmatrix(B, intro=r'B_{2\times 2}=')


$$C_{2\times 2}=\begin{pmatrix} 1 & 2\\ 0 & 1\\ \end{pmatrix}$$
$$D_{2\times 2}=\begin{pmatrix} 3 & 1\\ 1 & 0\\ \end{pmatrix}$$
$$B_{2\times 2}=\begin{pmatrix} 5 & 1\\ 5 & 2\\ \end{pmatrix}$$

In [11]:
A = np.array([[5,6],
              [3,4]])

pmatrix(rg(A), intro=r'rg(A)=')


$$rg(A)=\begin{pmatrix} 2\\ \end{pmatrix}$$

In [12]:
pmatrix(inv(C), intro=r'C^{-1}=')

pmatrix(B.T, intro=r'C^{T}=')

pmatrix(B.dot(C), intro=r'BC=')
9
pmatrix(rg(B), intro=r'rg(C)=')

pmatrix(det(B), intro=r'det(C)=')


$$C^{-1}=\begin{pmatrix} 1. & -2.\\ 0. & 1.\\ \end{pmatrix}$$
$$C^{T}=\begin{pmatrix} 5 & 5\\ 1 & 2\\ \end{pmatrix}$$
$$BC=\begin{pmatrix} 5 & 11\\ 5 & 12\\ \end{pmatrix}$$
$$rg(C)=\begin{pmatrix} 2\\ \end{pmatrix}$$
$$det(C)=\begin{pmatrix} 5.0\\ \end{pmatrix}$$

In [18]:
A = np.array([[2,6],
              [1,3]])
#pmatrix(rg(B), intro=r'rg(B)=')
pmatrix(rg(A), intro=r'rg(A)=')
#pmatrix(rg(A.dot(B)), intro=r'rg(AB)=')


$$rg(A)=\begin{pmatrix} 1\\ \end{pmatrix}$$

3 пункт

примерчик


In [10]:
a1 = Symbol('a_{12}')
b1 = Symbol('b_{11}')
c1 = Symbol('c_{22}')
d1 = Symbol('d_{21}')

X =np.array([[a1,b1],
             [c1,d1]])

B = np.array([[5,1],
              [5,2]])

C1 = np.array([[1,1],
               [1,2]])
D1 = np.array([[2,1],
               [1,0]])

C2 = np.array([[1,-1],
               [0,1]])
D2 = np.array([[1,1],
               [0,1]])
pmatrix(B.reshape((4, 1)), intro="X=")


$$X=\begin{pmatrix} 5\\ 1\\ 5\\ 2\\ \end{pmatrix}$$

In [4]:
pmatrix( (C1.dot(X)).dot(D1))
A = (C1.dot(X)).dot(D1) + (C2.dot(X)).dot(D2)
pmatrix(A)
F = np.array([[3,1,1,1],
              [2,1,0,-1],
              [2,1,5,2],
              [1,0,3,1]])

pmatrix(F, ending=pmatrix(X.reshape((4, 1)),row=True)+"="+pmatrix(B.reshape((4, 1)),row=True))
pmatrix(rg(F), intro=r'rg(F)=')
print("Зничит есть нормальное решение!)")


$$\begin{pmatrix} 2*a1 & + & b1 & + & 2*c1 & + & d1 & a1 & + & c1\\ 2*a1 & + & b1 & + & 4*c1 & + & 2*d1 & a1 & + & 2*c1\\ \end{pmatrix}$$
$$\begin{pmatrix} 3*a1 & + & b1 & + & c1 & + & d1 & 2*a1 & + & b1 & - & d1\\ 2*a1 & + & b1 & + & 5*c1 & + & 2*d1 & a1 & + & 3*c1 & + & d1\\ \end{pmatrix}$$
$$\begin{pmatrix} 3 & 1 & 1 & 1\\ 2 & 1 & 0 & -1\\ 2 & 1 & 5 & 2\\ 1 & 0 & 3 & 1\\ \end{pmatrix}\begin{pmatrix} a1\\ b1\\ c1\\ d1\\ \end{pmatrix}=\begin{pmatrix} 5\\ 1\\ 5\\ 2\\ \end{pmatrix}$$
$$rg(F)=\begin{pmatrix} 4\\ \end{pmatrix}$$
Зничит есть нормальное решение!)

Решаем этоЁ!!!


In [12]:
from sympy import Matrix, solve_linear_system
from sympy.abc import a,b,c,d

Examlpe: x + 4 y == 2 -2 x + y == 14

from sympy import Matrix, solve_linear_system from sympy.abc import x, y

system = Matrix(( (1, 4, 2), (-2, 1, 14))) solve_linear_system(system, x, y)


In [14]:
system = Matrix(( (3,1,1,1,5), (2,1,0,-1,1), (2,1,5,2,5),(1,0,3,1,2) ))
x = solve_linear_system(system, a,b,c,d)
X =np.array([[x[a],x[b]],[x[c],x[d]] ])

In [15]:
pmatrix(X,intro="X=")


$$X=\begin{pmatrix} 10/11 & 9/11\\ -2/11 & 18/11\\ \end{pmatrix}$$

In [ ]:


In [34]:
x = Symbol('x')
y = Symbol('y')
pr(integrate(sqrt(4*x-x**2), x))


$\int \sqrt{- x^{2} + 4 x}\, dx$


In [ ]: