Thursday, August 17, 2017

linear algebra 08/17/2017 lecture 11

symmetric & upper triangular matrix = diagonal matrix.  dimension = 3  in 3*3 matrix

Sum: symmetric or upper triangular matrix : take anything in S and anything in U. 不是并集,是相加。 所以可以得到all matrix. dimension (S+U) = 9 in 3*3 matrix

dim(S) +dim(U) = dim(S&U) + dim(S+U)

rank 1 matrix
example : A is 2*3 matrix

rank 1 matrix 像积木,eg. 一个rank 4 的matrix可以分解成4个rank 1 matrix的相乘

subset of rank 1 matrix can't form a sub space (两个rank 1 matrix相加可能得到一个rank 2 matrix)

In R4, V = [v1,v2,v3,v4], S is all v in R4 to make v1+v2+v3+v4 = 0
=>Av = 0 A = [1,1,1,1]
S 是A的null space. RA = 1 => S = R(N(A)) = n-r = 4-1 = 3
三个特殊解找出来即可

graph {nodes,edges}











Wednesday, August 16, 2017

linear algebra letcure 9 & 10 08/16/2017

lecture 9:
independence:
vector x1,x2,....xn are independent, if no combination gives 0 vector (except the 0 combinations.)

c1x1+c2x2+...+cnxn is not 0, they are independent

vectors v1,...vl span a space means: the space consists of all combinations of those vectors.

Basis for a space is a set of vectors with 2 properties:

1. they are independent.
2. they span the space

Example :
space is R3
one basis: [1;0;0] [0;1;0] [0;0;1]

n vectors give basis if the n*n matrix is invertible.
(n个vector的一种组合可以得到单元矩阵,也就是单元基basis)

every basis for the space has the same number of vectors.
It is called the dimension of the space.

rank(A) = #pivot column = dimension of the column space

dimension of null space is the number of free variables. = n - r

lecture 10:

4 subspace of A(m*n)
C(A) column space ;Rm
N(A) null space ;Rn
R(A) row space = all combination of columns of At C(At) ;Rn
N(At) :null space of At. The left null space of A ;Rm


basis? dimension?

C(A)
dimension of C(A) = r (rank of the matrix)
basis: is the pivot columns of A

R(A)

dimension of R(A) = r

N(A)
basis: special solutions
dimension: n-r

N(At)
basis: special solutions
dimension: m - r
why call it left null space?
At*y = 0 => yt*A = 0t =>左零矩阵

[A,I]=>[R,E]

如何计算y?
E*A = R
从E的最后一行找,因为E*A最后会得到一个最后一行为0的矩阵














Monday, August 14, 2017

linear algebra 08/14/2017 lecture 7 & 8

lecture 7:
the rank of the matrix. 矩阵的秩

do elimination, find the pivot columns and free columns.
pivot variables + free variables = n (column number)

reduced row echelon form 是一种矩阵的继续简化

求解null space
解法1:produce null space matrix R*N=0
R是已经被简化的矩阵,变成[I,F;0;0] I 是单元矩阵
N=[-F;I]

解法2:求解null space.把free variable 其中一个设为1,其余free variable 为0. 然后求出一组解,

lecture 8:
Ax = b
solvable when b is in C(A)
If a combination of rows of A gives 0 rows,

to find a compete solutions

1.x particular (找一个特殊解): set all free variables as 0
2. 再把其中一个free variable 换成1,其余的为0,求几组特殊解


The case of full column rank 
r = n

what that imply about the solutions? What is that mean?
No free variables
=> N(A) = {0} null space only have 零向量
solution to Ax = b
x = unique solution, if exists (0 or 1 solution)

full row rank means 

r = m
can solve Ax = b for every b.
free variables n -r = n-m 个
肯定可以得出一个最简矩阵R=[I F]

special case: r = m = n

R = I
=> N(A) = {0} null space only have 零向量
Ax = b


r= m < n 
R= [I;0] => 0  or 1 solution

r = m<n
R = [I F] => infinite solution

r<m, r<n
R = [I,F;0,0]
=> 0 or infinite solutions





Sunday, August 13, 2017

linear algebra notes 08//13/2017 lecture 5 & 6

lecture 5:

LU 分解的意义:
http://blog.csdn.net/carrierlxksuper/article/details/8487276

permutation:
P-1 = Pt
一共n!个permutation matrix

transpose 的概念

symmetric matrix:
At = A

Rt*R is always symmetric.
WHY? Take transpose!
(RtR)t = Rt*Rtt = Rt*R  (和逆矩阵的公式很像 (AB)-1 = B-1A-1)
所以这个是symmetric的


Vector space
Example: R2 = all 2 dimensional vectors

a vector space inside R2 is : a subspace of R2
一定得过零点

subspace of R2
1. all of R2 (最大子空间)
2. any lines through [0;0]
3. zero vector only (最小子空间)
子空间 补充:https://www.zhihu.com/question/48849797

column space: columns in Rn. Add their combinations form a subspace . (满足定义)


lecture 6:

Ax=b 有解 当b in A的column spaces (根据定义来的)

主列

null space (零空间) of A
all vectors x to let Ax = 0
at least contains [0;0;0]

solutions to Ax = 0 always gives a subspace.

subspace 一定会过零点







Friday, August 11, 2017

MIT linear algebra course note

08/11/2017 lecture 1 & 2
1. permutation matrix
2. inverse matrix E*E-1 = I
3. identity matrix
4. 如何做矩阵变换。E*A=B 使得 第二行substract 第一行

08/12/2017 lecture 3&4
4种方法计算矩阵乘法:
1. 正常法,每个值都是1 row * 1 column
2. column way. A乘以B的每个column
3. row way. A的每个row 乘以B
4. A的每个column 乘以 B的每个row。加在一起
5. cut matrix into blocks。 然后把每个block之间进行运算

A的左逆 矩阵和右逆矩阵是相同的 if matrix is invertible (non singular)

Singular case (no inverse)
比如[1,3;2,6]

singular matrix can get 0 by some matrix x
Ax = 0 if A is singular matrix. x 是存在的

A times B的一列j,得到的是结果的C的一列j
A的一行j times B,得到的是结果的C的一行j

Gauss - Jordan (solve 2 equations at once)
[A,I]--->[I,A-1]




AB 的逆矩阵 = B-1A-1

矩阵的转置
(A-1)t = (At)-1
A 的逆矩阵的转置是A的转置的逆矩阵
A= LU
if there is no row exchange, the multiplers will directly go into L

how many operations on n *n matrix?
n^3

permutation:
可以在单元矩阵中变换

原矩阵乘以这个矩阵(permuatation matrix)表示第二行第三行互换

permutation matrix : p-1 = pt 如果第二行和第三行 换了,那么再换一次第二行和第三行就是还是原来的矩阵

置换矩阵(Permutation matrix):矩阵的每一行和每一列的元素中只有一个1,其余元素都为0。(不严谨的解释)
转置矩阵(Transpose matrix):矩阵的行变成对应的列,矩阵的列变成对应的行。(不严谨的直白解释)
性质:置换矩阵(P)的逆是其(置换矩阵自己的)转置(T),
即:P^(-1)= P^T
如:3×3的置换矩阵群(共3! = 6个,补充4×4的置换矩阵共4! = 4×3×2×1 = 24个)
1 0 0 | 0 1 0
0 1 0 | 1 0 0
0 0 1 | 0 0 1
----------------
0 0 1 | 1 0 0  
0 1 0 | 0 0 1 
1 0 0 | 0 1 0 
置换矩阵的逆=置换矩阵的转置(上面4个置换矩阵的转置矩阵都是自身,又因为他们的逆=他们的转置,所以他们的逆=自身)

0 1 0 | 0 0 1 
0 0 1 | 1 0 0 
1 0 0 | 0 1 0 
置换矩阵的逆=置换矩阵的转置(这两个矩阵的转置=对方,因此这两个矩阵的逆=对方)

LU分解

LU分解是指,把矩阵分解为 消元矩阵E 的逆操作 L(下三角)
和 A 被消元后的结果矩阵 U(上三角)的乘积.
  • LU分解不借助 行交换的关键是是 中间不能出现 0 pivot
  • 但是对最后一个 pivot 没有 非0的要求
  • 因为奇异矩阵也有LU分解

http://blog.csdn.net/qq_25834201/article/details/59748093
http://blog.csdn.net/lc013/article/details/52244464
https://github.com/mebusy/notes/blob/master/dev_notes/LinearAlgebra.md

Sunday, July 30, 2017

quickly log in remote sever

reference:
http://blog.csdn.net/leexide/article/details/17252369
https://my.oschina.net/aiguozhe/blog/33994

process:
local server:
1. ssh-keygen -t rsa (连续三次回车,即在本地生成了公钥和私钥,不设置密码)
2. ssh root@172.24.253.2 "mkdir .ssh;chmod 0700 .ssh" (需要输入密码, 注:必须将.ssh的权限设为700) (if remote server doesn't have ssh file)
3. scp ~/.ssh/id_rsa.pub root@172.24.253.2:.ssh/id_rsa.pub (需要输入密码)

remote server:
1. 
cat id_rsa.pub >> ~/.ssh/authorized_keys
2. 
 chmod 600 authorized_keys
3.
 chmod 700 -R ~/.ssh
注意都要在对应.ssh 文件目录下进行

Wednesday, July 19, 2017

python write to file buffer

https://stackoverflow.com/questions/18984092/python-2-7-write-to-file-instantly
https://stackoverflow.com/questions/3167494/how-often-does-python-flush-to-a-file
Use flush() or

For file operations, Python uses the operating system's default buffering unless you configure it do otherwise. You can specify a buffer size, unbuffered, or line buffered.
For example, the open function takes a buffer size argument.
"The optional buffering argument specifies the file’s desired buffer size: 0 means unbuffered, 1 means line buffered, any other positive value means use a buffer of (approximately) that size. A negative buffering means to use the system default, which is usually line buffered for tty devices and fully buffered for other files. If omitted, the system default is used."
bufsize = 0
f = open('file.txt', 'w', bufsize)
shareimprove this answer