matlab矩阵中的 */.*

Posted 流浪若相惜

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了matlab矩阵中的 */.*相关的知识,希望对你有一定的参考价值。

说实话,我知道今天才会意识到其实这些运算困扰了我不止一次两次,每次都会去查Help文档,真的是困惑的不行不行,因此,打算今天彻底的将其捋一遍。

文章目录

点乘(·*)与星乘 *

点乘(·*):矩阵A和B对应项相乘
类型:(1) A:m×n; B: m×n (2) A:m×n; B:1×n (列要一致)(3)A:m×n;B:m×1 (行一致),且后两种情况为行或者列向量时才可成立,否则需要两个矩阵具有相同的行列维度
例:

x3 =
     2     3
     3     4
y3 =
     2     1
x3.*y3
ans =
     4     3
     6     4
y4 =
     2
     1
x3.*y4
ans =
     4     6
     3     4

星乘(*):矩阵A的列项数与矩阵B的行项数一致
类型:A:m×n; B:n×l
例:

x3 =
     2     3
     3     4
y4 =
     2
     1
x3*y4
ans =
     7
    10

右除(/)与左除(\\)

左除:Solve systems of linear equations Ax = B for x (mldivide)
矩阵左除有以下几种情况:

x = A\\B solves the system of linear equations A*x = B. The matrices A and B must have the same number of rows. MATLAB® displays a warning message if A is badly scaled or nearly singular, but performs the calculation regardless.
If A is a scalar, then A\\B is equivalent to A.\\B.
If A is a square n-by-n matrix and B is a matrix with n rows, then x = A\\B is a solution to the equation A*x = B, if it exists.
If A is a rectangular m-by-n matrix with m ~= n, and B is a matrix with m rows, then A\\B returns a least-squares solution to the system of equations A*x= B.

也就是说若A是矩阵,则矩阵B必须要与A有相同的行数
例:

A = [1 2 0; 0 4 3];
b = [8; 18];
x = A\\b
x = 

         0
    4.0000
    0.6667

这个函数实则是求解线性方程的,即,
3 x 1 + 2 x 2 + 1 = 6 3 x 2 + 1 = 7 \\begincases 3x1+2x2+1=6 \\\\ 3x2+1=7 \\endcases 3x1+2x2+1=63x2+1=7
这里A=[3 2 1;0 3 1] ;X=[x1;x2;1],B=[6;7],因此X=A\\B
那么对于回归分析来说,则系数矩阵代表的是X,变量则是A(样本值),因此X=A\\B,求得的是系数矩阵

右除:Solve systems of linear equations xA = B for x (mrdivide)
矩阵右除有三种情况:

x = B/A solves the system of linear equations x*A = B for x. The matrices A and B must contain the same number of columns. MATLAB® displays a warning message if A is badly scaled or nearly singular, but performs the calculation regardless.
If A is a scalar, then B/A is equivalent to B./A.
If A is a square n-by-n matrix and B is a matrix with n columns, then x = B/A is a solution to the equation x*A = B, if it exists.
If A is a rectangular m-by-n matrix with m ~= n, and B is a matrix with n columns, then x = B/A returns a least-squares solution of the system of equations x*A = B

右除当A为矩阵时,要求B为与A同列项数的矩阵
例:

A = [1 1 3; 2 0 4; -1 6 -1];
B = [2 19 8];
x = B/A
x = 

    1.0000    2.0000    3.0000

以上是关于matlab矩阵中的 */.*的主要内容,如果未能解决你的问题,请参考以下文章

matlab中已知协方差矩阵,怎样算相关系数?

如何利用matlab求相关系数?

MATLAB如何求相关系数

手写数字识别基于matlab GUI欧拉数和二维矩阵相关系数手写数字识别含Matlab源码 1896期

主成分分析法计算过程中,相关系数矩阵用matlab求出特征值后,如何确定给出的特征值跟各个指标的对应关系

MATLAB | 好看的相关系数矩阵图绘制