Professional Documents
Culture Documents
Cubic Approximation
Cubic Approximation
The cubic approximation to f at x =a is a cubic, f3 (x), which has the same value,
derivative, second derivative and third derivative as f at x = a:
EXAMPLE
Taylor Series cubic approximation
Using Taylor's formula with a=0 and n=3, how would you find the cubic approximation of f(x)= 1/(1-x)
at x=0, given the upper bound for the magnitude of the error in the approximation when lxl< 0.1 ?
remainder
. Since
then
on the
and the
for i=1:s
if i==s
a(i,1)=0;
c(i,1)=0;
else
a(i,1)=n(i,1)/m(i,1)-m(i,1)*(b(i+1,1)+2*b(i,1))/3;
c(i,1)=(b(i+1,1)-b(i))/(3*m(i,1));
end
end
B=[a,b,c];
B;
le=round((x(length(x),1)-x(1,1))*100);
Mat=zeros(le,1);
YTM=zeros(le,1);
% maturity
% yield
t=1;
for i=1:s
if i==s
else
k=round(x(i+1,1)*100)-round(x(i,1)*100);
%
%
%
%
%
%
%
if k==1
Mat(t,1)=x(i,1);
YTM(t,1)=y(i,1);
Mat(t+1,1)=x(i+1,1);
YTM(t+1,1)=y(i+1,1);
t=t+1;
else
for r=0:(k)
Mat(t+r,1)=x(i,1)+r/100;
if r==0
YTM(t+r,1)=y(i,1);
else
YTM(t+r,1)=y(i,1)+a(i,1)*(r/100)+b(i,1)*(r/100)^2+c(i,1)*(r/100)^3;
end
end
t=t+k;
% end
% YTM(x(length(x),1),1)=y(length(x),1);
end
end
[Mat,YTM];
plot(Mat,YTM,'-',x,y,'ro',dataT(:,3),dataT(:,2),'o');
%zy=zeros(x(length(x),1),1);
%fy=zeros(x(length(x),1),1);
%'zero coupon yield curve (zy)'
%for i=1:s
%
if coupon(i,1)==0
%
zy(i,1)=y(i,1);
% else
% end
%end
%for i=1:C(x(length(x),1))
% if zy(i,1)==0
%
d=0;
%
for j=1:i-1
%
d=d+C1(i,1)/((1+C1(j,1)/100)^(j));
% end
%
%zy(i,1)=(((100+C1(i,1))/(100-d))^(1/i)-1)*100;
%else
% end
%end
%for i=1:C(x(length(x),1))
%
if i==length(C)
%
fy(length(C),1)=zy(length(C),1);
% else
%
fy(i,1)=(((1+zy(i+1,1)/100)^2)/(1+zy(i,1)/100)-1)*100;
%end
%end
%[C,C1,zy,fy]
%plot(C,zy,C,C1,C,fy);