北欧的冬天 发表于 2006-12-6 21:51

请教matlab编写矩阵求逆程序

谁有矩阵求逆的程序和求广义逆的程序吗?我编不出来,能给我一份吗
我的qq是93629184
油箱是chenwen40117@126.com

shenyongjun 发表于 2006-12-6 23:09

Matlab中有现成的函数啊,inv,pinv,等,看一下在线帮助你的问题就解决了!

北欧的冬天 发表于 2006-12-7 10:23

不是,我想要写inv和pinv的程序,而不是用这两个命令

moller 发表于 2006-12-7 17:14

呵呵
我想2,3楼的朋友是让你看inv的m文件~~~

北欧的冬天 发表于 2006-12-10 08:13

请问怎么看他们的m文件啊

shenyongjun 发表于 2006-12-10 23:43

function z = inv(A)
%INVInverse of GF matrix.
%   INV(X) is the inverse of the square matrix X.
%   An error message is printed if X is singular.
%
%   See also LU, LSOLVE, USOLVE.

%    Copyright 1996-2002 The MathWorks, Inc.
%    $Revision: 1.3 $$Date: 2002/03/27 00:15:02 $

if size(A.x,1)~=size(A.x,2)
   error('Matrix must be square.')
else
   z = A;
   z.x = uint16(zeros(size(A.x)));
    = lu(A);
   for i = 1:size(A.x,2)
      temp = lsolve(L,gf(double(P.x)*((1:size(A.x,2))'==i),A.m,A.prim_poly));
      temp = usolve(U,temp);      
      z.x(:,i) = temp.x;
   end
end

shenyongjun 发表于 2006-12-10 23:44

function X = pinv(A,varargin)
%PINV   Pseudoinverse.
%   X = PINV(A) produces a matrix X of the same dimensions
%   as A' so that A*X*A = A, X*A*X = X and A*X and X*A
%   are Hermitian. The computation is based on SVD(A) and any
%   singular values less than a tolerance are treated as zero.
%   The default tolerance is MAX(SIZE(A)) * NORM(A) * EPS.
%
%   PINV(A,TOL) uses the tolerance TOL instead of the default.
%
%   Class support for input A:
%      float: double, single
%
%   See also RANK.

%   Copyright 1984-2004 The MathWorks, Inc.
%   $Revision: 5.12.4.1 $$Date: 2004/03/02 21:47:30 $

= size(A);
if n > m
   X = pinv(A',varargin{:})';
else
    = svd(A,0);
   if m > 1, s = diag(S);
      elseif m == 1, s = S(1);
      else s = 0;
   end
   if nargin == 2
      tol = varargin{1};
   else
      tol = max(m,n) * eps(max(s));
   end
   r = sum(s > tol);
   if (r == 0)
      X = zeros(size(A'),class(A));
   else
      s = diag(ones(r,1)./s(1:r));
      X = V(:,1:r)*s*U(:,1:r)';
   end
end

北欧的冬天 发表于 2006-12-11 19:44

ls的提供的广义逆程序还是用matlab编写的,里面还是有svd()的matlab的命令,我想求的是最通用的程序,如fortun或c编写的,svd这种也是自己写的那中程序
页: [1]
查看完整版本: 请教matlab编写矩阵求逆程序