% fftneum1d  -u''=f  u'(0,2pi)=0
clear all
nn=2.^[13:18];
for j=1:size(nn,2)
    n=nn(j); n1=n+1; h=1/n; x=[0:h:1]'; uex=cos(pi*x).^2-.5;
    c=[1; -1]; for k=2:log2(n); c=[c; c]; end; 
    c=[c; zeros(n,1)]/2; d=2*c; d(1)=.5; d(n1)=-.5;
    tic 
    lam=4*n*n*sin(x*pi/2).^2; f=2*pi^2*cos(2*pi*x); 
    v=real(fft([f(1:n);zeros(n,1)])); 
    v=v-f(1)/2*ones(2*n,1)+f(n1)*c; v(1)=0; %v(n1)=f'*d(1:n1); 
    v(n+2:end)=zeros(n-1,1); v(2:n1)=v(2:n1)./lam(2:n1);
    u=real(fft(v)); u=u+v(n1)*c; u(n1)=v(1:n1)'*d(1:n1); u=u(1:n1)*2/n;
    t(j)=toc;
    norm(u-uex,inf),
end
plot(nn.*log(nn),t,'-o'); xlabel('n log n'); ylabel('time');