关于matlab中矩阵运算A/B的疑问A/B按我的解释应该是A乘以B的逆矩阵,这样的话B必须是一个方阵才可逆呀!可是我运行时出现:>> a=[1;2;3;4;5;6];>> b=a;>> a/bans =0 0 0 0 0 0.16670 0 0 0 0 0.33330 0 0 0 0 0.50000 0 0
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/16 20:55:13
关于matlab中矩阵运算A/B的疑问A/B按我的解释应该是A乘以B的逆矩阵,这样的话B必须是一个方阵才可逆呀!可是我运行时出现:>> a=[1;2;3;4;5;6];>> b=a;>> a/bans =0 0 0 0 0 0.16670 0 0 0 0 0.33330 0 0 0 0 0.50000 0 0
关于matlab中矩阵运算A/B的疑问
A/B按我的解释应该是A乘以B的逆矩阵,这样的话B必须是一个方阵才可逆呀!
可是我运行时出现:
>> a=[1;2;3;4;5;6];
>> b=a;
>> a/b
ans =
0 0 0 0 0 0.1667
0 0 0 0 0 0.3333
0 0 0 0 0 0.5000
0 0 0 0 0 0.6667
0 0 0 0 0 0.8333
0 0 0 0 0 1.0000
运算的结果是6维的矩阵,这并不是什么点除呀!再者:
>> a=[1;2;3;4;5;6];
>> b=[4;2;6;4;5;6];
>> a/b
ans =
0 0 0.1667 0 0 0
0 0 0.3333 0 0 0
0 0 0.5000 0 0 0
0 0 0.6667 0 0 0
0 0 0.8333 0 0 0
0 0 1.0000 0 0 0
>> a=[1;2;3;4;5;6];
>> b=[4;2;6;4;5;6];
>> a/b
ans =
0 0 0.1667 0 0 0
0 0 0.3333 0 0 0
0 0 0.5000 0 0 0
0 0 0.6667 0 0 0
0 0 0.8333 0 0 0
0 0 1.0000 0 0 0
还有行向量的运算:
>> a=[1 2 3 4 5 6];
>> b=[4 5 5 4 5 6];
>> b/a
ans =
1.1978
看不懂,就是不清楚这些结果如何算出来的,拒绝无意义的回答!
关于matlab中矩阵运算A/B的疑问A/B按我的解释应该是A乘以B的逆矩阵,这样的话B必须是一个方阵才可逆呀!可是我运行时出现:>> a=[1;2;3;4;5;6];>> b=a;>> a/bans =0 0 0 0 0 0.16670 0 0 0 0 0.33330 0 0 0 0 0.50000 0 0
matlab里的'/'不完全等于矩阵除法.
你可以用help mrdivide看一下'/'的帮助:
>> help mrdivide
/ Slash or right matrix divide.
A/B is the matrix division of B into A, which is roughly the
same as A*INV(B) , except it is computed in a different way.
More precisely, A/B = (B'\A')'. See MLDIVIDE for details.
就是说A/B可以大致看成A*inv(B),但用的是另一种方法.更确切的讲A/B = (B'\A')'.
那再看看'\'(左除或者反除)是什么东东.
>> help mldivide
\ Backslash or left matrix divide.
A\B is the matrix division of A into B, which is roughly the
same as INV(A)*B , except it is computed in a different way.
If A is an N-by-N matrix and B is a column vector with N
components, or a matrix with several such columns, then
X = A\B is the solution to the equation A*X = B computed by
Gaussian elimination. A warning message is printed if A is
badly scaled or nearly singular. A\EYE(SIZE(A)) produces the
inverse of A.
If A is an M-by-N matrix with M < or > N and B is a column
vector with M components, or a matrix with several such columns,
then X = A\B is the solution in the least squares sense to the
under- or overdetermined system of equations A*X = B. The
effective rank, K, of A is determined from the QR decomposition
with pivoting. A solution X is computed which has at most K
nonzero components per column. If K < N this will usually not
be the same solution as PINV(A)*B. A\EYE(SIZE(A)) produces a
generalized inverse of A.
就是说当A是N阶方阵B为N行的列向量时,X=A\B就是线性方程组A*X=B的解,算法是用高斯消去法.A\EYE(SIZE(A))产生的是方阵A的逆矩阵.
如果A是M*N的矩阵且M≠N,B是跟A行数(M行)相同的列向量时,X=A\B是非满秩的线性方程组A*X=B的解系,A的秩K由QR分解得出.如果K> A=pascal(3) %A赋值为3*3的方阵.
A =
1 1 1
1 2 3
1 3 6
>> b=[1:3]' % b是3*1的列向量.
b =
1
2
3
>> x=A\b % 用反除求Ax=b的解,结果x是个列向量,注意是A\b不是b\A
x =
0
1
0
>> A*x % 验证一下A*x刚好等于b
ans =
1
2
3
>> x=b'/A' % 这回是正除了,不过b'是行向量,A'也倒一下,正除的时候就是b'/A'了,不是A'/b'了,结果x是个行向量
x =
0 1 0
>> x*A' % 验证一下,跟b'一样.
ans =
1 2 3
>> A=rand(3,4) % 这回重新赋值,A不是方阵了,是3*4的矩阵
A =
0.5298 0.3798 0.4611 0.0592
0.6405 0.7833 0.5678 0.6029
0.2091 0.6808 0.7942 0.0503
>> x=A\b % 实际上方程组没有唯一确定的解,而是无数解,所以解出来的是一个特解
x =
-1.5132
4.9856
0
-1.5528
>> A*x % 验证,跟b相等.
ans =
1.0000
2.0000
3.0000
>> A=rand(3,2) % 再看看3*2的矩阵,行数>列数的情况
A =
0.4154 0.0150
0.3050 0.7680
0.8744 0.9708
>> x=A\b
x =
1.8603
1.5902
>> A*x % 验证一下,嗯?怎么不等于b了?
ans =
0.7966
1.7886
3.1704
% 为什么呢?因为方程数(行数)太多,未知数(列数)个数太少,2个未知数,用2个线性无关的方程就可以求确定的解了,现在方程多了,不能同时满足所有方程,所以实际上是无解,只不过matlab里用的是一个最小二乘意义上的近似解,所以验证时不等,只是尽可能近似的满足所有方程.