matlab的左除和右除

Posted

tags:

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

参考技术A

matlab的左除和右除,按矩阵、数组类型来分有矩阵左除和矩阵右除,数组左除和数组右除。

matlab的矩阵左除是这样表示的,A\\B

matlab的矩阵右除是这样表示的,A/B

matlab的数组左除是这样表示的,A.\\B

matlab的数组右除是这样表示的,A./B

例如:

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求逆运算:左除( )和右除( / ),inv,pinv的用法及区别

matlab中\ \是啥意思

Matlab基本运算

MATLAB002 -- 左除与右除的区别