%   Programmer: Jannis Kreß
%   Date:       02/12/2017
%   Task:       Taylor-23/1+x

% init
clc
clear all
close all
%-------------------------------------------------------------------------%
f_x         = @(x) 3/(1+x);
f_x_strich  = @(x) -3/(1+x)^2;
f_x_2strich = @(x) 6/(1+x)^3;
f_x_3strich = @(x) -18/(1+x)^4;

f0 = [f_x(0) f_x_strich(0) f_x_2strich(0) f_x_3strich(0)];
%-------------------------------------------------------------------------%
x = 0:0.05:0.9;
for n=1:1:length(x);
    y(n)=f_x(x(n));
end
figure('Name','Testat','Numbertitle','off');
plot(x,y,'linewidth',1.5);hold on;grid on;
title('f(x)');xlabel('x');ylabel('y');
%-------------------------------------------------------------------------%
T_x = 0;
x0 = 0;
for i=0:1:3
    T_x = T_x + f0(1+i)*((x-x0)/factorial(i)).^i;
    plot(x,T_x,'r');
    a = abs(y(x==0.5)-T_x(x==0.5));
    fprintf('Die Genauigkeit der %g Ordnung beträgt: %g!\n',i,a);
end
%-------------------------------------------------------------------------%