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

📄 demotaylor.txt

📁 这是《Numerical Methods with MATLAB: Implementation and Application》一书的配书程序(Matlab)
💻 TXT
字号:
function demoTaylor(x0,dx)
% demoTaylor  Taylor Series approximations for f(x) = 1/(1-x)
%          
% Synopsis:  demoTaylor
%            demoTaylor(x0,dx)
%
% Input:  x0 = (optional) point about which the Taylor Series expansion is
%              made.  Default:  x0 = 1.6;
%         dx = (optional) size of neighborhood over which the expansion
%              is evaluated.  Default:  dx = 0.8
%
%  Output:  a plot of f(x) and its Taylor Series approximations

if nargin<2,  x0 = 1.6;  dx = 0.8;  end

x = linspace(x0-dx/2,x0+dx/2,20);   %  x-values at which f(x) is evaluated
fx = 1./(1-x);                      %  Exact f(x); notice the array operator

h = x - x0;                      %  Avoid recomputing intermediate values,
t = 1/(1-x0);                    %    h and t
p1x = t*ones(size(x)) + h*t^2;   %  First order Taylor polynomial
p2x = p1x + (h.^2)*t^3;          %  Second order "  "  "
p3x = p2x + (h.^3)*t^4;          %  Third

plot(x,fx,'-',x,p1x,'o-',x,p2x,'^-',x,p3x,'s-');
legend('exact  ','P_1(x)','P_2(x)','P_3(x)',4);
xlabel('x');    ylabel('Approximations to f(x) = 1/(1-x)');

⌨️ 快捷键说明

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