function exacterror=exacterr(ni,x,u,uexact,errnorm)
global qrule
%gauss=1/sqrt(3);
%gauss1=1/2-gauss/2;
%gauss2=1/2+gauss/2;
ucomp=(u(2:ni+1)+u(1:ni))/2;
%ucomp(1:2:2*ni-1)=(gauss1*u(2:ni+1)+(1-gauss1)*u(1:ni));
%ucomp(2:2:2*ni)=(gauss2*u(2:ni+1)+(1-gauss2)*u(1:ni));
h=x(2:ni+1)-x(1:ni);
Ducomp=(u(2:ni+1)-u(1:ni))./h;
%Ducomp(1:2:2*ni-1)=(u(2:ni+1)-u(1:ni))./h;
%Ducomp(2:2:2*ni)=Ducomp(1:2:2*ni-1);
xcopy=x;
%
for i=1:ni;
x=xcopy(i)+h(i)/2;
%x=xcopy(i)+gauss1*h(i);
uex(i)=eval(uexact);
%uex(2*i-1)=eval(uexact);
%x=xcopy(i)+qrule*h(i)/2;
Duex(i)=eval(uexact);
%Duex(2*i-1)=eval(uexact);
x=x+0.01*h(i);
Duex(i)=(eval(uexact)-Duex(i))/(0.01*h(i));
%Duex(2*i-1)=(eval(uexact)-Duex(2*i-1))/(0.01*h(i));
%
%x=xcopy(i)+gauss2*h(i);
%uex(2*i)=eval(uexact);
%Duex(2*i)=eval(uexact);
%x=x+0.01*h(i);
%Duex(2*i)=(eval(uexact)-Duex(2*i))/(0.01*h(i));
end
%
hh(1:2:2*ni-1)=h;
hh(2:2:2*ni)=h;
%abs(Ducomp-Duex)
if errnorm=='en';
exacterror=sqrt(sum((Ducomp-Duex).*(Ducomp-Duex).*h));
elseif errnorm=='l2';
exacterror=sqrt(sum((ucomp-uex).*(ucomp-uex).*h));
elseif errnorm=='ma';
exacterror=max(abs(uex-ucomp));
end
