发表于:2009/4/10 16:11:32
#0楼
在网上找到了一个单似乎不是很好用,所以就改良了一下,法捷耶娃法求矩阵(sI-A)的逆
function [a,ainv,c,b,n]=fadlev1(a)
%
% fadlev faddeev-leverrier approach to generate coefficients of the
% characteristic polynomial and inverse of a given matrix
% uasage: [p,ainv,b]=fedlev(a)
%
% input: a - the given matrix
% output: a - the coefficient vector of the characteristic polynomial
% c - a cell array of the sequency of matrices generated, where
% c{1} = a p(1)=trace(c{1})
% c{2} = a*(c{1}-p(1)*i) p(2)=trace(c{2})/2
% .....
% c{n} = a*(c{n-1}-p(n-1)*i) p(n)=trace(c{n})/n
% b-法捷耶娃法中的伴随矩阵算子
% n-所求伴随矩阵
% ainv - the inverse of a calculated as
% ainv = (c{n-1}-p(n-1)*i)/p(n)
%
%
%
[n,m]=size(a);
if n~=m
error(the given matrix is not square!);
end
[c{1:n}]=deal(a);
a=ones(1,n+1);
b{1}=eye(n);
for k=2:n
a(k)=-trace(c{k-1})/(k-1);
c{k}=a*(c{k-1}+a(k)*eye(n));
b{k}=c{k}*inv(a);
end
a(n+1)=-trace(c{n})/n;
ainv=-(c{n-1}+a(n)*eye(n))/a(n+1);
syms s
n=0
for i=1:n
n=n+b{i}*s^(n-i)
end
----------------------------------------------
此篇文章从博客转发
原文地址: Http://blog.gkong.com/more.asp?id=83974&Name=psychekklll
function [a,ainv,c,b,n]=fadlev1(a)
%
% fadlev faddeev-leverrier approach to generate coefficients of the
% characteristic polynomial and inverse of a given matrix
% uasage: [p,ainv,b]=fedlev(a)
%
% input: a - the given matrix
% output: a - the coefficient vector of the characteristic polynomial
% c - a cell array of the sequency of matrices generated, where
% c{1} = a p(1)=trace(c{1})
% c{2} = a*(c{1}-p(1)*i) p(2)=trace(c{2})/2
% .....
% c{n} = a*(c{n-1}-p(n-1)*i) p(n)=trace(c{n})/n
% b-法捷耶娃法中的伴随矩阵算子
% n-所求伴随矩阵
% ainv - the inverse of a calculated as
% ainv = (c{n-1}-p(n-1)*i)/p(n)
%
%
%
[n,m]=size(a);
if n~=m
error(the given matrix is not square!);
end
[c{1:n}]=deal(a);
a=ones(1,n+1);
b{1}=eye(n);
for k=2:n
a(k)=-trace(c{k-1})/(k-1);
c{k}=a*(c{k-1}+a(k)*eye(n));
b{k}=c{k}*inv(a);
end
a(n+1)=-trace(c{n})/n;
ainv=-(c{n-1}+a(n)*eye(n))/a(n+1);
syms s
n=0
for i=1:n
n=n+b{i}*s^(n-i)
end
----------------------------------------------
此篇文章从博客转发
原文地址: Http://blog.gkong.com/more.asp?id=83974&Name=psychekklll
[此贴子已经被作者于2009-4-10 16:19:29编辑过]