⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 compsplintflops.m

📁 这是《Numerical Methods with MATLAB: Implementation and Application》一书的配书程序(Matlab)
💻 M
字号:
function compSplintFlops
% compSplintFlops  Show flops savings due to sparse storage in spline interp
%
% Synopsis:  compSplintFlops
%
% Input:  None
%
% Output:  Table of flops to compute spline interpolant

fprintf('            sparse      full    relative\n');
fprintf(' knots      flops       flops    effort\n');

nk = [4 8 16 32 64 128 256 512];
for k = 1:length(nk)
  x = linspace(0,5,nk(k))';  %  Generate discrete data set
  y = x.*exp(-x);
  xi = mean(x);              %  Evaluate spline at this xi
  flops(0);                  %  Reset flops counter
  yi = splint(x,y,xi);       %  Spline with not-a-knot end conditions
  fs(k) = flops;
  
  flops(0);                  %  Reset flops counter
  yi = splintFull(x,y,xi);   %  Repeat with full storage
  ff(k) = flops;
  fprintf('%5d  %10d  %10d  %8.4f\n',nk(k),fs(k),ff(k),fs(k)/ff(k));
end

loglog(nk,fs,'ro',nk,ff,'bs');
xlabel('knots');   ylabel('flops');
legend('sparse','full',2);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -