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

📄 demohermite.m

📁 这是《Numerical Methods with MATLAB: Implementation and Application》一书的配书程序(Matlab)
💻 M
字号:
function demoHermite(n)
% demoHermite  Cubic Hermite interpolation of y = x*exp(-x) for 0 <= x <= 8
%
% Synopsis:    demoHermite
%              demoHermite(n)
%
% Input:       n = (optional) number of knots used to define the interpolant
%                  Default:  n = 4 
%
% Output:      Plot of cubic Hermite approximation to y = x * exp(-x)

if nargin<1,  n = 4;  end

x = linspace(0,8,n);           %  vector of knots
y = x.*exp(-x);                %  f(x)
yp = (1 - x).*exp(-x);         %  f'(x)
xi = linspace(min(x),max(x));  %  Evaluate interpolant at xi
ye = xi.*exp(-xi);             %  Exact f(x) for comparison

yi = hermint(x,y,yp,xi);
err = norm(yi-ye(:));
fprintf('error = %12.2e  with %d knots\n',err,n);

plot(x,y,'bo',xi,ye,'b-',xi,yi,'r--');
legend('Given','x*exp(-x)','Hermite');
text(4,0.2,sprintf('%d knots',n));
axis([0 8 0 0.5]);

⌨️ 快捷键说明

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