声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 3367|回复: 7

[编程技巧] 请教matlab编写矩阵求逆程序

[复制链接]
发表于 2006-12-6 21:51 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

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

使用道具 举报

发表于 2006-12-6 23:09 | 显示全部楼层
Matlab中有现成的函数啊,inv,pinv,等,看一下在线帮助你的问题就解决了!
 楼主| 发表于 2006-12-7 10:23 | 显示全部楼层
不是,我想要写inv和pinv的程序,而不是用这两个命令
发表于 2006-12-7 17:14 | 显示全部楼层
呵呵
我想2,3楼的朋友是让你看inv的m文件~~~
 楼主| 发表于 2006-12-10 08:13 | 显示全部楼层
请问怎么看他们的m文件啊
发表于 2006-12-10 23:43 | 显示全部楼层
function z = inv(A)
%INV  Inverse 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)));
   [L,U,P] = 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
发表于 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 $

[m,n] = size(A);
if n > m
   X = pinv(A',varargin{:})';
else
   [U,S,V] = 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这种也是自己写的那中程序
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-5-9 22:23 , Processed in 0.109828 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表