|
|
发表于 2005-2-20 22:12:33
|
显示全部楼层
[求助]如何用Matlab计算Jacobi多项式 (无内容)
发一个自己编的程序
你可以参考一下
% This program is used to solver hilbert array.
% 刘百仓_houston
% 2004.11.03
format long
N=120; % the dimension of hilbert array
e=1e-6; % control variable
fprintf(';%s %d %s\n';, ';There are ';,N,';vectors.';);
x(1:N,1)=0.0;
%%%%%%%% generating hilbert array %%%%%%%%%%
for i=1:1:N
for j=1:1:N
A(i,j)=1/(i+j-1);
end
b(i,1)=sum(A(i,1:N));
end
% TT=A\b
%--------------------------------------------%
%%%%%%%% generating diag array of A %%%%%%%%%%
temp=diag(A);
for i=1:1:N
D(i,i)=temp(i,1);
end
%--------------------------------------------%
U=triu(A)-D; % Extract upper triangular part of A(not contain D)
DsL=tril(A); % Extract lower triangular part (D+L)
Bg=-inv(DsL)*U; % -inv(D+L)*U
u=inv(DsL); % inv(D+L)
x0(1:N,1)=-10.0; % initial vector
x1(1:N,1)=0.0;
Iteration=0; % count
while norm(x-x0)>e
x1=Bg*x0+u*b;
x=x0;
x0=x1;
Iteration=Iteration+1;
end
K=cond(Bg);
%%%%%%%% Output the calculated results %%%%%%%%%%
fmt = ';%7.4f';; for i=2:10; fmt = strcat(fmt, '; %7.4f';); end;fmt = strcat(fmt,';\n';);
fprintf(fmt, x1);
fprintf(';\n';);
fprintf(';%s %d %s\n';, ';Iteration= ';,Iteration,';times.';);
K
%-------------------------------------------------% |
|