function xnew = h_adapt(x,eta,theta) %eta is local error
xnew = x(1);
for i = 1:length(x)-1
    if eta(i) > theta*max(eta) %if local error is large, inster a midpoint
        xnew = [xnew, (x(i)+x(i+1))/2];
    end
    xnew = [xnew, x(i+1)]; %if local error is small, keep the element unchanged 
end
xnew = unique(xnew);
end
