solvespeed.m
来自「数值方法和MATLAB实现与应用.zip」· M 代码 · 共 31 行
M
31 行
function solveSpeed
% solveSpeed Measure elapsed time and flop rate for solving Ax=b
%
% Synopsis: solveSpeed
%
% Input: none
%
% Output: Print out of elapsed time, flop rate and memory use
% as function of matrix dimension. Flop rate vs. matrix
% dimension is plotted
if ~isstudent
n = [8 16 32 64 128 256 512 1024]; % solve this range of n by n systems
else
n = [8 16 32 64 128]; % student edition is limited to n=128
end
fprintf(' n et Mflop rate MBytes for A\n');
for i=1:length(n);
A = rand(n(i),n(i)); b = rand(n(i),1);
flops(0);
tic;
x = A\b;
elapsedTime(i) = toc;
frate(i) = flops/elapsedTime(i)/1e6;
fprintf(' %6d %10.3f %8.3f %8.2f\n',...
n(i),elapsedTime(i),frate(i),8*n(i)*n(i)/1e6);
end
loglog(n,frate,'o');
xlabel('Matrix dimension'); ylabel('Megaflop rate');
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?