%
% -----------------------------------------------------
%
%   Approximation im Wintersemester 2013/14
%
%   Aufgabe 17g: 
%   Berechnung der Bernstein-Approximationen 
%
% -----------------------------------------------------
%
%
clear all
close all
%
n    = 10; 
t    = [0:0.005:1];
%
for iteil=1:3,
%
bern(1,:) = 1+0*t;
%
for i=1:n,
    h1  =  0*t;
    for k=1:i,
        h2  =  bern(k,:);
        bern(k,:) = t.*h1 + (1-t).*h2;
        h1  =  h2;
    end
    bern(i+1,:) = t.*h1;   
end
%
y    =  (1+0*t)./(1+25*(2*t-1).^2);
yapp =  0*t;
for i=1:n+1,
    t1   = (i-1)/n;
    y1   = (1+0*t1)./(1+25*(2*t1-1).^2);
    yapp = yapp + y1*bern(i,:);
end
%  
if iteil == 1
   subplot(221)
   plot(t,y,'k','Linewidth',1.2)
   set(gca,'FontSize',12)
   xlabel('Bernstein-Approximation, N=10','FontSize',12)
   axis([0 1 -0.1 1.1])
   hold
   plot(t,yapp,'b','Linewidth',1.2)
   hold off
   n = 50;   
end
%  
if iteil == 2
   subplot(222)
   plot(t,y,'k','Linewidth',1.2)
   set(gca,'FontSize',12)
   xlabel('Bernstein-Approximation, N=50','FontSize',12)
   axis([0 1 -0.1 1.1])
   hold
   plot(t,yapp,'b','Linewidth',1.2)
   hold off
   n = 100;   
end
%
if iteil == 3
   subplot(223)
   plot(t,y,'k','Linewidth',1.2)
   set(gca,'FontSize',12)
   xlabel('Bernstein-Approximation, N=100','FontSize',12)
   axis([0 1 -0.1 1.1])
   hold
   plot(t,yapp,'b','Linewidth',1.2)
   hold off
end
%
print -depsc aufg17g
%
end
return
%
