Matlab中的\ 和/和pinv的关系以及运算



最近解师弟一个43758*43758的稀疏方程,发现一个很困扰的问题:师弟使用SSOR-PCG法解了66分钟,得到了一个不准确的结果,也就是说解的精度很低。在我这,不管是Matlab还是我使用的数值库来解,只要是迭代法,比如使用ILU预分解的BiCG、GMRES(m),迭代收敛速度都很慢,迭代上十万次精度只达1.e-2量级。偶尔间使用Matlab的'\'发现不到2秒便解出了十分精确的解,惊讶万分。查阅Matlab的文档得到以下资料:

inv:

Y = inv(X) returns the inverse of the square matrix X. Awarning message is printed if X is badly scaled or nearlysingular.

In practice, it is seldom necessary to form the explicitinverse of a matrix. A frequent misuse of inv arises when solvingthe system of linear equations Ax=b. One way to solve this is withx = inv(A)*b. A better way, from both an execution time andnumerical accuracy standpoint, is to use the matrix divisionoperator x = A\b. This produces the solution using Gaussianelimination, without forming the inverse. See \ and /for further information.

'\':

Backslash or matrix left division. If A is a square matrix,A\B is roughly the same as inv(A)*B, except it is computed in adifferent way. If A is an n-by-n matrix and B is a column vectorwith n components, or a matrix with several such columns, then X =A\B is the solution to the equation AX = B. A warning message isdisplayed if A is badly scaled or nearly singular. A\EYE(SIZE(A))produces the inverse of A. See the reference page for mldivide formore information.

If A is an m-by-n matrix with m ~= n and B is a column vectorwith m components, or a matrix with several such columns, then X =A\B is the solution in the least squares sense to the under- oroverdetermined system of equations AX = B. The effective rank, k,of A is determined from the QR decomposition with pivoting. Asolution X is computed that has at most k nonzero components percolumn. If k < n, this is usually not the samesolution as pinv(A)*B, which is the least squares solution with thesmallest norm||X||.    A\EYE(SIZE(A)) producesa  generalized inverse of A.

mldivide \:

Left matrix division

mldivide(A,B) and the equivalent A\B perform matrix leftdivision (back slash). A and B must be matrices that have the samenumber of rows, unless A is a scalar, in which case A\B performselement-wise division — that is, A\B = A.\B.

If A is a square matrix, A\B is roughly the same as inv(A)*B,except it is computed in a different way. If A is an n-by-n matrixand B is a column vector with n elements, or a matrix with severalsuch columns, then X = A\B is the solution to the equation AX = B.A warning message is displayed if A is badly scaled or nearlysingular.

If A is an m-by-n matrix with m ~= n and B is a column vectorwith m components, or a matrix with several such columns, then X =A\B is the solution in the least squares sense to the under- oroverdetermined system of equations AX = B. In other words, Xminimizes norm(A*X - B), the length of the vector AX - B. The rankk of A is determined from the QR decomposition with columnpivoting. The computed solution X has at most k nonzero elementsper column. If k < n, this is usually not the samesolution as x = pinv(A)*B, which returns a least squaressolution.

就是说当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<N通常结果与PINV(A)*B不等(PINV(A)是求A的广义逆矩阵)。 A\EYE(SIZE(A))得到的是A的广义逆矩阵。

总而言之,A\B就是求A*X=B的解,你可以看作是A的逆矩阵,只不过是广义逆矩阵,这样A不是方阵也可以计算的。

至于A/B,在解线性方程组上比\少用一些,因为通常都把B写成列向量,所以用反除\就可以了。用/的话,B通常是行向量。
可以把B/A看作是X*A=B的解,这里B的列数等于A的列数。

A\B=pinv(A)*B 
A/B=A*pinv(B)

可见,'\'用的是高斯消元法。

同时还查到:
Square Matrices

If A is symmetric and has real, positive diagonal elements, MATLABattempts a Cholesky factorization. If the Cholesky factorizationfails, MATLAB performs a symmetric, indefinite factorization. If Ais upper Hessenberg, MATLAB uses Gaussian elimination to reduce thesystem to a triangular matrix. If A is square but is neitherpermuted triangular, symmetric and positive definite, orHessenberg, MATLAB performs a general triangular factorizationusing LU factorization with partial pivoting.


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值