function [ni,x]=corr(ni,x,res,errnorm,tol)
disp('corr')
h=x(2:ni+1)-x(1:ni);
%
%computing new mesh size
%
if errnorm=='en';
hnew=(tol^2*ones(size(h))./(res+eps*ones(size(res))).^2/ni).^(1/3);
%
elseif errnorm=='l2'
hnew=(tol^2*ones(size(h))./(res+eps*ones(size(res))).^2/ni).^(1/5);
elseif errnorm=='ma'
hnew=sqrt(tol*ones(size(h))./(res+eps*ones(size(res))));
end
%
%computing new mesh points
%
sons=max(ones(size(h)),ceil(h./hnew));
hnew=h./sons;
xnew=[x(1):hnew(1):x(2)];
for j=2:ni;
add=[x(j)+hnew(j):hnew(j):x(j+1)];
xnew=[xnew,add];
end
x=xnew;
ni=length(x)-1;


