David C. Lay의 Linear Algebra에서 1.2장의 Example 3에 sympy적용.
- RREF는 unique하기 때문에 sympy에서 지원함.
import numpy as np
import sympy as sp
# ----------------------------------
# colab에서 sympy의 값을 latex 지원하여 출력하기 위해 정의
def custom_latex_printer(exp, **options):
from google.colab.output._publish import javascript
url = "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/latest.js?config=default"
javascript(url=url)
return sp.printing.latex(exp, **options)
sp.init_printing(use_latex="mathjax", latex_printer=custom_latex_printer)
# end ----------------------------------
A = np.array([
[0 , 3, -6, 6, 4,-5],
[3 ,-7 , 8,-5, 8, 9],
[3 ,-9 ,12,-9, 6,15]
], dtype=float)
A = sp.Matrix(A)
rref_A = A.rref()
rref_A # rref and pivot columns
결과는 다음과 같음.
$$\displaystyle \left( \left[\begin{matrix}1 & 0 & -2.0 & 3.0 & 0 & -24.0\\0 & 1 & -2.0 & 2.0 & 0 & -7.0\\0 & 0 & 0 & 0 & 1 & 4.0\end{matrix}\right], \ \left( 0, \ 1, \ 4\right)\right)$$
References
https://gist.github.com/dsaint31x/72fa6d150b869c561eded8f745004913
반응형
'... > Math' 카테고리의 다른 글
[LA] Signal Space : Vector Space (0) | 2022.09.30 |
---|---|
[LA] Set of Real-valued Functions defined on a set of real number : Vector Space (1) | 2022.09.30 |
[LA] tf.linalg.solve 로 linear system 의 solution 구하기. (0) | 2022.09.01 |
[LA] Data Types (or The Types of Variable) (0) | 2022.09.01 |
[LA] Introduction of Linear Algebra (0) | 2022.09.01 |