矩陣

線性代數

簡介

線性方程組

向量

矩陣

代數

空間

行列式

線性變換

特徵向量

LU 分解

SVD 分解

相關書籍

應用數學

微積分

離散數學

線性代數

機率統計

訊息

相關網站

參考文獻

最新修改

簡體版

English

矩陣

形式:

(1)
\begin{align} A = \begin{bmatrix} a_{1,1} & a_{1,2} & ... & a_{1,m} \\ a_{2,1} & a_{2,2} & ... & a_{2,m} \\ ... \\ a_{n,1} & a_{n,2} & ... & a_{n,m} \end{bmatrix} \end{align}

範例:

(2)
\begin{bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \end{bmatrix}

矩陣的加法

形式:

(3)
\begin{align} A + B = \begin{bmatrix} a_{1,1} & ... & a_{1,m} \\ ... \\ a_{n,1} & ... & a_{n,m} \end{bmatrix} + \begin{bmatrix} b_{1,1} & ... & b_{1,m} \\ ... \\ b_{n,1} & ... & b_{n,m} \end{bmatrix} = \begin{bmatrix} a_{1,1}+b_{1,1} & ... & b_{1,m}+b_{1,m} \\ ... \\ a_{n,1}+b_{n,1} & ... & a_{n,m}+b_{n,m} \end{bmatrix} \end{align}

範例:

(4)
\begin{align} A+B = \begin{bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \end{bmatrix} + \begin{bmatrix} 1 & 3 & 5 \\ 2 & 4 & 6 \end{bmatrix} = \begin{bmatrix} 2 & 5 & 8 \\ 6 & 9 & 12 \end{bmatrix} \end{align}

數*矩陣

形式:

(5)
\begin{align} c * A = c * \begin{bmatrix} a_{1,1} & a_{1,2} & ... & a_{1,m} \\ a_{2,1} & a_{2,2} & ... & a_{2,m} \\ ... \\ a_{n,1} & a_{n,2} & ... & a_{n,m} \end{bmatrix} = \begin{bmatrix} c*a_{1,1} & c*a_{1,2} & ... & c*a_{1,m} \\ c*a_{2,1} & c*a_{2,2} & ... & c*a_{2,m} \\ ... \\ c*a_{n,1} & c*a_{n,2} & ... & c*a_{n,m} \end{bmatrix} \end{align}

範例:

(6)
\begin{align} 2 * \begin{bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \end{bmatrix} = \begin{bmatrix} 2 & 4 & 6 \\ 8 & 10 & 12 \end{bmatrix} \end{align}

矩陣的轉置

形式:

(7)
\begin{align} A^T = \begin{bmatrix} a_{1,1} & a_{1,2} & ... & a_{1,m} \\ a_{2,1} & a_{2,2} & ... & a_{2,m} \\ ... \\ a_{n,1} & a_{n,2} & ... & a_{n,m} \end{bmatrix} ^T = \begin{bmatrix} a_{1,1} & a_{2,1} & ... & a_{n,1} \\ a_{1,2} & a_{2,2} & ... & a_{n,2} \\ ... \\ a_{1,m} & a_{2,m} & ... & a_{n,m} \end{bmatrix} \end{align}

範例:

(8)
\begin{align} A^T = \begin{bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \end{bmatrix} ^T = \begin{bmatrix} 1 & 4 \\ 2 & 5 \\ 3 & 6 \end{bmatrix} \end{align}

矩陣*矩陣

形式 1:

(9)
\begin{bmatrix} a_{1,1} & ... & a_{1,k} \\ ... \\ a_{n,1} & ... & a_{n,k} \end{bmatrix} * \begin{bmatrix} b_{1,1} & ... & b_{1,m} \\ ... \\ b_{k,1} & ... & b_{k,m} \end{bmatrix} = \begin{bmatrix} \sum_{i=1}^k a_{1,i}*b_{i,1} & ... & \sum_{i=1}^k a_{1,i}*b_{i,m} \\ ... \\ \sum_{i=1}^k a_{n,i}*b_{i,1} & ... & \sum_{i=1}^k a_{n,i}*b_{i,m} \end{bmatrix}

形式2:

(10)
\begin{align} A * B = \begin{bmatrix} \vec{A_1} \\ ... \\ \vec{A_n } \end{bmatrix} * \begin{bmatrix} \vec{B_1} & ... & \vec{B_m} \end{bmatrix} = \begin{bmatrix} \vec{A_1}*\vec{B_1} & ... & \vec{A_1}*\vec{B_m} \\ ... \\ \vec{A_n}*\vec{B_1} & ... & \vec{A_n}*\vec{B_m} \end{bmatrix} \end{align}

範例:

(11)
\begin{bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \end{bmatrix} * \begin{bmatrix} 1 & 4 \\ 2 & 5 \\ 3 & 6 \\ \end{bmatrix} = \begin{bmatrix} 1*1+2*2+3*3 & 1*4+2*5+3*6 \\ 1*4+2*5+3*6 & 4*4+5*5+6*6 \end{bmatrix} = \begin{bmatrix} 14 & 32 \\ 32 & 77 \end{bmatrix}

Python 矩陣程式範例

>>> import numpy as np
>>> a = np.matrix([[1,2],[3,4]])
>>> b = np.matrix([[5,6],[7,8]])
>>> a*b
matrix([[19, 22],
        [43, 50]])
>>> a+b
matrix([[ 6,  8],
        [10, 12]])
>>> a-b
matrix([[-4, -4],
        [-4, -4]])
>>> a*b
matrix([[19, 22],
        [43, 50]])
>>> a/b
matrix([[ 0.2       ,  0.33333333],
        [ 0.42857143,  0.5       ]])
>>> b*a
matrix([[23, 34],
        [31, 46]])
>>> add(a,b)
matrix([[ 6,  8],
        [10, 12]])
>>> subtract(a,b)
matrix([[-4, -4],
        [-4, -4]])
>>> multiply(a,b)
matrix([[ 5, 12],
        [21, 32]])
>>> multiply(b,a)
matrix([[ 5, 12],
        [21, 32]])
>>> divide(a,b)
matrix([[0, 0],
        [0, 0]])
>>> divide(b,a)
matrix([[5, 3],
        [2, 2]])
>>> inv(a)
matrix([[-2. ,  1. ],
        [ 1.5, -0.5]])
>>> a*inv(a)
matrix([[  1.00000000e+00,   0.00000000e+00],
        [  8.88178420e-16,   1.00000000e+00]])
>>> a*inv(a)*b
matrix([[ 5.,  6.],
        [ 7.,  8.]])
>>> eig(a)
(array([-0.37228132,  5.37228132]), matrix([[-0.82456484, -0.41597356],
        [ 0.56576746, -0.90937671]]))
>>>
>>> from numpy import *
>>> from scipy import linalg
>>> A = mat('[1 3 5; 2 5 1; 2 3 8]')
>>> A.I
matrix([[-1.48,  0.36,  0.88],
        [ 0.56,  0.08, -0.36],
        [ 0.16, -0.12,  0.04]])
>>> inv(A)
matrix([[-1.48,  0.36,  0.88],
        [ 0.56,  0.08, -0.36],
        [ 0.16, -0.12,  0.04]])
>>> linalg.inv(A)
array([[-1.48,  0.36,  0.88],
       [ 0.56,  0.08, -0.36],
       [ 0.16, -0.12,  0.04]])
>>> b = mat('[10;8;3]')
>>> A.I*b
matrix([[-9.28],
        [ 5.16],
        [ 0.76]])
>>> linalg.solve(A,b)
array([[-9.28],
       [ 5.16],
       [ 0.76]])
>>> linalg.det(A)
-25.000000000000004
>>> A = mat('[1 5 2; 2 4 1; 3 6 2]')
>>> la,v = linalg.eig(A)
>>> la
array([ 7.95791620+0.j, -1.25766471+0.j,  0.29974850+0.j])
>>> v
array([[-0.5297175 , -0.90730751,  0.28380519],
       [-0.44941741,  0.28662547, -0.39012063],
       [-0.71932146,  0.30763439,  0.87593408]])
>>> A = mat('[1 3 2; 1 2 3]')
>>> M,N = A.shape
>>> M, N
(2, 3)
>>> U,s,Vh = linalg.svd(A)
>>> Sig = mat(linalg.diagsvd(s,M,N))
>>> U, Vh = mat(U), mat(Vh)
>>> U
matrix([[-0.70710678, -0.70710678],
        [-0.70710678,  0.70710678]])
>>> Sig
matrix([[ 5.19615242,  0.        ,  0.        ],
        [ 0.        ,  1.        ,  0.        ]])
>>> Vh
matrix([[ -2.72165527e-01,  -6.80413817e-01,  -6.80413817e-01],
        [  2.42861287e-16,  -7.07106781e-01,   7.07106781e-01],
        [ -9.62250449e-01,   1.92450090e-01,   1.92450090e-01]])
>>> U*Sig*Vh
matrix([[ 1.,  3.,  2.],
        [ 1.,  2.,  3.]])
>>>

參考文獻

  1. http://en.wikipedia.org/wiki/Matrix_(mathematics)
  2. Numpy and Scipy Documentation » SciPy v0.11.dev Reference Guide (DRAFT) » SciPy Tutorial » Linear Algebra (scipy.linalg)

Facebook

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License