Local polynomial approximation of functions - Taylor polynomial ?

3 views (last 30 days)
In my book I have example what I didnt know how to solve... Example: Construct the Taylor polynom for the function F (x) = (x - 1). (X - 2). (X - 3). (X - 4). (X - 5) = x.^5 - 15*x.^4 + 85*x.^3 - 225*x.^2 + 274.*x -120, in the middle u = 3 , for n = 1,3,5. Use this TaylorEval function :
---------------------------------------------------------------------------------------
function y = TaylorEval(t,u,x)
% TAYLOREVAL dava hodnoty Taylorovho polynomu vo vekt.argumente x
% y = TaylorEval(t,u,x),
% ---------------------------------------------------------------
% argin : t = vector koef. Taylor. polynom in middle u
% u = middle Tayl.pol.
% x = vector who want to evoulate p(x))
% argout: y = vector Taylor.pol. in vector x
%
n = length(t);
y = t(1)*ones(1, length(x));
for i = 2:n
y = (x - u).*y + t(i);
end
---------------------------------------------------------------------------------------
T(x,3,1) and T(x,3,3) plot in interval [2,4] must to get this plot:
http://i.imgur.com/M2gmlJv.jpg
>> I tried to solve like this:
u = 3;
n = [1 3 5];
p = poly([1 2 3 4 5]);
% for i = 0:3
% pv = polyval(p,3)
% p1 = polyder(p);
% p = p1;
% end
px1 = [-30 0 4 0];
x = linspace(2,4,201);
y = x.^5 - 15*x.^4 + 85*x.^3 - 225*x.^2 + 274.*x -120;
z1 = TaylorEval(px1,3,x);
plot(x,y,'b',x,z1,'r:')
% xlim([-2,4])
% ylim([-4,4])
shg

Answers (1)

x y
x y on 26 Oct 2014
Now I get same with this:
px1 = [4 0];
px2 = [-5 0 4 0];
x = linspace(2,4,201);
y = x.^5 - 15*x.^4 + 85*x.^3 - 225*x.^2 + 274.*x -120;
z1 = TaylorEval(px1,3,x);
z2 = TaylorEval(px2,3,x);
plot(x,y,'b',x,z1,'r:',x,z2,'r:')

Categories

Find more on Polynomials in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!