# 特徵值

``````>>> w, v = eig(np.diag((1, 2, 3)))
>>> w; v
array([ 1.,  2.,  3.])
array([[ 1.,  0.,  0.],
[ 0.,  1.,  0.],
[ 0.,  0.,  1.]])
>>> a = np.array([[1, 1j], [-1j, 1]])
>>> w, v = eig(a)
>>> w; v
array([ 2.+0.j,  0.+0.j])
array([[ 0.00000000+0.70710678j,  0.70710678+0.j        ],
[ 0.70710678+0.j        ,  0.00000000+0.70710678j]])
>>> a = np.array([[1 + 1e-9, 0], [0, 1 - 1e-9]])
>>> a
array([[ 1.,  0.],
[ 0.,  1.]])
>>> w, v = eig(a)
>>> w; v
array([ 1.,  1.])
array([[ 1.,  0.],
[ 0.,  1.]])
>>>```
```

# 反矩陣

``````>>> a = np.array([[1., 2.], [3., 4.]])
>>> ainv = inv(a)
>>> np.allclose(np.dot(a, ainv), np.eye(2))
True
>>> np.allclose(np.dot(ainv, a), np.eye(2))
True
>>> ainv = inv(np.matrix(a))
>>> ainv
matrix([[-2. ,  1. ],
[ 1.5, -0.5]])
>>>```
```

# 解方程式

Solve the system of equations 3 * x0 + x1 = 9 and x0 + 2 * x1 = 8:

``````>>> a = array([[3,1], [1,2]])
>>> b = array([9,8])
>>> x = solve(a, b)
>>> x
array([ 2.,  3.])
>>> (dot(a, x) == b).all()
True
>>> dot(a,x)
array([ 9.,  8.])
>>> b
array([9, 8])
>>>```
```

# 參考文獻

1. numpy.linalg.eig
2. Short IT recipes — Wednesday, January 09, 2008 Python: eigenvalues with Scipy and Sympy
3. http://docs.scipy.org/doc/numpy/reference/generated/numpy.matrix.html