线性代数回顾
来源:互联网 发布:cst仿真软件价格 编辑:程序博客网 时间:2024/06/07 17:13
矩阵与向量
此处,不做过多叙述。如若忘记相关概念请自行充电学习。
补充笔记
Matrices and Vectors
Matrices are 2-dimensional arrays:
The above matrix has four rows and three columns, so it is a 4*3 matrix.
A vector is a matrix with one column and many rows:
So vectors are a subset of matrices. The above vector is a 4*1 matrix.
Notation and terms:
- Aij refers to the element in the ith row and jth column of matrix A.
- A vector with 'n' row is referred to as an 'n'-dimensional vector.
- vi refers to the element in the ith row of the vector.
- In general, all our vectors and matrices will be 1-indexed. Note that for some programming languages, the arrays are 0-indexed.
- Matrices are usually denoted by uppercase names while vectors are lowercase.
- "Scalar" means that an object is a single value, not a vector or matrix.
- R refers to set of scalar real numbers.
- Rn refers to the set of n-dimensional vectors of real numbers.
Run the cell below to get familiar with the commands in Octave/Matlab. Feel free to create matrices and vectors and try out different things.
% The ; denotes we are going back to a new row.A = [1, 2, 3; 4, 5, 6; 7, 8, 9; 10, 11, 12]% Initialize a vector v = [1;2;3] % Get the dimension of the matrix A where m = rows and n = columns[m,n] = size(A)% You could also store it this waydim_A = size(A)% Get the dimension of the vector v dim_v = size(v)% Now let's index into the 2nd row 3rd column of matrix AA_23 = A(2,3)
A = 1 2 3 4 5 6 7 8 9 10 11 12v = 1 2 3m = 4n = 3dim_A = 4 3dim_v = 3 1A_23 = 6
Addition and Scalar Multiplication
Addition and subtraction are element-wise, so you simply add or subtract each corresponding element:
Subtracting Matrices:
To add or subtract two matrices, their dimensions must be the same.
In scalar multiplication, we simply multiply every element by the scalar value:
In scalar division, we simply divide every element by the scalar value:
Experiment below with the Octave/Matlab commands for matrix addition and scalar multiplication. Feel free to try out different commands. Try to write out your answers for each command before running the cell below.
% Initialize matrix A and B A = [1, 2, 4; 5, 3, 2]B = [1, 3, 4; 1, 1, 1]% Initialize constant s s = 2% See how element-wise addition worksadd_AB = A + B % See how element-wise subtraction workssub_AB = A - B% See how scalar multiplication worksmult_As = A * s% Divide A by sdiv_As = A / s% What happens if we have a Matrix + scalar?add_As = A + s
A = 1 2 4 5 3 2B = 1 3 4 1 1 1s = 2add_AB = 2 5 8 6 4 3sub_AB = 0 -1 0 4 2 1mult_As = 2 4 8 10 6 4div_As = 0.50000 1.00000 2.00000 2.50000 1.50000 1.00000add_As = 3 4 6 7 5 4
Matrix-Vector Multiplication
We map the column of the vector onto each row of the matrix, multiplying each element and summing the result.
The result is a vector. The number of columns of the matrix must equal the number of rows of the vector.
An m * n matrix multiplied by an n * 1 vector.
Below is an example of a matrix-vector multiplication. Make sure you understand how the multiplication works. Feel free to try different matrix-vector multiplications.
% Initialize matrix A A = [1, 2, 3; 4, 5, 6;7, 8, 9] % Initialize vector v v = [1; 1; 1] % Multiply A * vAv = A * v
A = 1 2 3 4 5 6 7 8 9v = 1 1 1Av = 6 15 24
Matrix-Matrix Multiplication
We multiply two matrices by breaking it into several vector multiplications and concatenating the result.
An m * n matrix multiplied by an n * o matrix results in an m * o matrix. In the above example, a 32 matrix times a 22 matrix resulted in a 3*2 matrix.
To multiply two matrices, the number of columns of the first matrix must equal the number of rows of the second matrix.
For example:
% Initialize a 3 by 2 matrix A = [1, 2; 3, 4;5, 6]% Initialize a 2 by 1 matrix B = [1; 2] % We expect a resulting matrix of (3 by 2)*(2 by 1) = (3 by 1) mult_AB = A*B% Make sure you understand why we got that result
mult_AB = 5 11 17
Matrix Multiplication Properties
- Matrices are not commutative: A * B ≠ B * A
- Matrices are associative: (A * B) * C = A * (B * C)
The identity matrix, when multiplied by any matrix of the same dimensions, results in the original matrix. It's just like multiplying numbers by 1. The identity matrix simply has 1's on the diagonal (upper left to lower right diagonal) and 0's elsewhere.
When multiplying the identity matrix after some matrix (A * l), the square identity matrix's dimension should match the other matrix's columns. When multiplying the identity matrix before some other matrix (l * A), the square identity matrix's dimension should match the other matrix's rows.
% Initialize random matrices A and B A = [1,2;4,5]B = [1,1;0,2]% Initialize a 2 by 2 identity matrixI = eye(2)% The above notation is the same as I = [1,0;0,1]% What happens when we multiply I*A ? IA = I*A % How about A*I ? AI = A*I % Compute A*B AB = A*B % Is it equal to B*A? BA = B*A % Note that IA = AI but AB != BA
A = 1 2 4 5B = 1 1 0 2I = Diagonal Matrix 1 0 0 1IA = 1 2 4 5AI = 1 2 4 5AB = 1 5 4 14BA = 5 7 8 10
Inverse and Transpose
The inverse of matrix A is denoted A-1. Multiplying by the inverse result in the identity matrix.
A non square matrix does not have an inverse matrix. We can compute inverse of matrices in octave with the pinv(A) function and in Matlab with the inv(A) function. Matrices that don't have an inverse are singular or degenerate.
The transposition of a matrix is like rotating the matrix 90° in clockwise direction and then reversing it. We can compute transposition of matrices in matlab with the transpose(A) function or A':
In other words:
% Initialize matrix A A = [1,2,0;0,5,6;7,0,9]% Transpose A A_trans = A' % Take the inverse of A A_inv = inv(A)% What is A^(-1)*A? A_invA = inv(A)*A
A = 1 2 0 0 5 6 7 0 9A_trans = 1 0 7 2 5 0 0 6 9A_inv = 0.348837 -0.139535 0.093023 0.325581 0.069767 -0.046512 -0.271318 0.108527 0.038760A_invA = 1.00000 -0.00000 0.00000 0.00000 1.00000 -0.00000 -0.00000 0.00000 1.00000
- 线性代数回顾
- Notes: 线性代数基础回顾
- 【线性代数】私人回顾
- 线性代数、微积分学习与回顾
- 斯坦福大学CS224d基础1:线性代数回顾
- 斯坦福大学CS224d基础1:线性代数回顾
- 机器学习入门——线性代数简单回顾
- 2017.03.16回顾 线性代数 最小二乘 pdo 3C
- 【机器学习】Andrew Ng——03线性代数知识回顾
- 斯坦福机器学习笔记 第1周 三、线性代数回顾
- 斯坦福大学CS224d基础1:线性代数回顾 Linear Algebra
- 线性代数
- 线性代数
- 线性代数
- 线性代数
- 线性代数
- 线性代数
- 线性代数
- Monkeyrunner基于python编写脚本通用方法
- Stanford 英文词性标注(Part-of-speech)缩写查询
- rsync error: protocol incompatibility / mismatch
- 伦敦用人脸识别抓错人!专家:要结合DNA技术才行 | 研究
- NavicatPremium连接Oracle登入时候报ORA-12638: 身份证明检索失败的解决办法
- 线性代数回顾
- 单变量线性回归(一)
- 单变量线性回归(二)
- 多变量线性回归(一)
- 多变量线性回归(二)
- Octave教程(一)
- 56G 线缆在数据中心的应用
- Octave教程(二)
- Octave教程(三)