clear all
close all

xx=0:0.1:1;

u = @(x) cos(x);

uex = u(xx);

uh1 = u(0)*(1-xx)+u(1)*xx;

M = length(xx);
for i=1:M
    uh2(i) = 0;
    if xx(i) <= 0.5
        uh2(i) = uh2(i) + u(0)*(1-2*xx(i)) + u(0.5)*2*xx(i);
    else 
        uh2(i) = uh2(i) + u(0.5)*(1-xx(i))*2 + u(1)*(2*xx(i)-1);
    end
end

plot(xx,uex,'k-',xx,uh1,'r-',xx,uh2,'b-');

