原帖由 happy 于 2006-8-23 15:22 发表
在matlab中矩阵的左除"\"是一种自适应算法
对于有唯一解的线性方程组求出精确解
对于超定方程线性方程组求出最小二乘解
对于欠定线性方程组求其基本解
这个好像是个内部函数,看不了它的代码
首选感谢教授的热心指点:@)
我现在面临的问题是欠定线性方程组的求解,即A为M*(M+1)的长方阵,X为(M+1)*3的矩阵,B为M*3的矩阵
请问教授在Matlab 里是如何求此基本解的?
我最近也看了不少广义逆矩阵的资料,有A- A+ A(1,3) A(1,4)等等,拭了几种都跟matlab 算的不一样,另外还有用QR分解的方法,现在正在做,不知道行不行
下面是matlab 里的mldivide文件,不知道是否是调用的这个函数来求"\"运行符,请指教
function X = mldivide(A, B)
%MLDIVIDE Symbolic matrix left division.
% MLDIVIDE(A,B) overloads symbolic A \ B.
% X = A\B solves the symbolic linear equations A*X = B.
% Warning messages are produced if X does not exist or is not unique.
% Rectangular matrices A are allowed, but the equations must be
% consistent; a least squares solution is not computed.
% Copyright 1993-2003 The MathWorks, Inc.
% $Revision: 1.18.4.2 $ $Date: 2004/04/16 22:22:54 $
A = sym(A);
B = sym(B);
if all(size(A) == 1)
% Division by a scalar
X = ldivide(A,B);
elseif ndims(A) > 2 | ndims(B) > 2
error('symbolic:sym:mldivide:errmsg1','Input arguments must be 2-D.')
elseif size(A,1) ~= size(B,1)
error('symbolic:sym:mldivide:errmsg2','First dimensions must agree.')
else
% Matrix divided by matrix
X = maple('linsolve',char(A),char(B),'''_rank''');
% Solution does not exist.
if isempty(X)
warning('symbolic:sym:mldivide:warnmsg1','System is inconsistent. Solution does not exist.')
X = Inf;
X = sym(X(ones(size(A,2),size(B,2))));
maple('_rank := ''_rank'';');
return
end;
% Check rank and clear _rank in Maple workspace.
if str2double(maple('_rank')) < min(size(A))
warning('symbolic:sym:mldivide:warnmsg2','System is rank deficient. Solution is not unique.')
end
maple('_rank := ''_rank'';');
% Set any free parameters, _t[k][j], to zero.
t = findstr(X,'_t[');
s = findstr(X,']');
for k = fliplr(t)
r = s(s > k);
X(k:r(2)) = '0';
end
X = maple('',sym(X));
end |