请教有关“数值代数中Arnoldi 算法的块状化的比较”的问题
数值代数中Arnoldi 算法的块状化的比较;%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%使用 double 数据类型%%
function = blockArnoldi(A,m,r)
% % Input: A -- an n by n matrix
% m -- a positive integer
% r -- an Nxp block vector (v .ne. 0 assumed)
% % Output: V -- an n by m*p orthogonal matrix
% H -- a m*p by (m-1)*p upper Hessenberg matrix
if isnumeric(A)
A = @(x)(A*x);
end
n = length(r);
p = size(r,2);
H (m*p,(m-1)*p)= 0;
v (n, m*p) = 0;
= sqr(r);
k = 0;
while k < m
k = k +1;
kp = k*p;
tic;
w = A(v(:,kp-p+1:kp));
toc,
for j =1:k
jp = j*p;
h = v(:,jp-p+1:jp)' * w;
w = w - v(:,jp-p+1:jp)*h;
H(jp-p+1:jp,kp-p+1:kp) = h;
end
= sqr(w);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% 使用 cell 数据类型
function = blockArnoldi_cell(A,m,r)
% % Input: A -- an n by n matrix
% m -- a positive integer
% r -- an Nxp block vector (v .ne. 0 assumed)
% % Output: V -- an n by m*p orthogonal matrix
% H -- a m*p by (m-1)*p upper Hessenberg matrix
if isnumeric(A)
A = @(x)(A*x);
end
%n = length(r);
p = size(r,2);
%H (m*p,(m-1)*p)= 0;
%v (n, m*p) = 0;
v = {}; h ={};
= sqr(r);
k = 0;
while k < m
k = k + 1;
w = A(v{k});
for j =1:k
h{j,k} = v{j}' * w;
w = w - v{j} * h{j,k};
end
= sqr(w);
end
H = zeros(p,p);
for j = 1: m-1
fork = j+2 : m+1
h{k,j} = H;
end
end
%h
cell2mat(v);
H =cell2mat(h);
%%%%%%%%%%%%%%%%%%%%
实验结果: cell 数据类型的程序比double类型的程序快!
问题1,不是double类型数组访问是效率比cell数据类型的数组访问效率快很多吗? 为何这里的cell 数据类型的程序比double类型的程序快?
问题2, 如何把下列程序向量化?或者有更好的方法使得下列程序执行效率快一些?
for j = 1: m-1
fork = j+2 : m+1
h{k,j} = H;
end
end
%%%%%%%%%%%
在这里先谢谢各位了!!
怎么没有人回帖啊.....................{:{13}:}
页:
[1]