% October 2017 % % Written by Per-Gunnar Martinsson, University of Oxford % % The methods follow Lloyd N. Trefethen's % % "Approximation Theory and Approximation Practice" % % textbook published by SIAM in 2013. Many code snippets are taken from % this text. They have been modified freey, however, and any errors are % due to PGM. function lecture08 DRIVER1 DRIVER2 DRIVER3 return %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function DRIVER1 x = chebfun('x'); hold off, plot(real(x),imag(x),'r') semi = 2*exp(0.5i*pi*x); S = join(x-2i, 1+semi, 2i-x, -1-semi); hold on, plot(S,'k'), axis equal off z = exp(1i*pi*x); Gamma = (2.8+.2i)*(sinh(z)+.5*real(z)); plot(Gamma,'b') text(4.2,2,'\Gamma','color','b','fontsize',12) text(3.1,.7,'S','fontsize',12) text(.9,-.3,'1','color','r') text(-1.4,-.3,'-1','color','r') return %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function DRIVER2 np = 8; xj = chebpts(np); %xj = linspace(-1,1,np); figure(1) hold off tt = linspace(-1.5,1.5); plot(tt,node_poly(tt,xj),'r',... xj,0*xj,'.k',... 'LineWidth',3,'MarkerSize',30) figure(2) hold off tt = linspace(-1.5,1.5,10000); semilogy(tt,abs(node_poly(tt,xj)),'r',... 'LineWidth',3,'MarkerSize',30) figure(3) [XX,YY] = meshgrid(linspace(-1.5,1.5,401),linspace(-1,1,301)); ZZ = XX + 1i*YY; [C,h] = contour(XX,YY,log10(abs(node_poly(ZZ,xj))),(-8):0); clabel(C,h) title('log_{10}(abs(l(z)))') keyboard return %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function DRIVER3 np = 30; xxcheb = chebpts(np); %xxuni = linspace(-1,1,np); xxuni = -1 + 2*rand(1,np); figure(1) hold off tt = linspace(-1.5,1.5); plot(tt,node_poly(tt,xxcheb),'r',... tt,node_poly(tt,xxuni),'k',... 'LineWidth',3) legend('cheb','uni') figure(2) hold off tt = linspace(-1.5,1.5,10000); semilogy(tt,abs(node_poly(tt,xxcheb)),'r',... tt,abs(node_poly(tt,xxuni)),'k',... 'LineWidth',3,'MarkerSize',30) legend('cheb','uni') figure(3) [XX,YY] = meshgrid(linspace(-2,2,161),linspace(-1,1,81)); ZZ = XX + 1i*YY; subplot(1,2,1) [C,h] = contour(XX,YY,log10(abs(node_poly(ZZ,xxcheb))),[-5,-4,-3,-2,-1,0,1,2]); clabel(C,h) title('Chebyshev nodes') subplot(1,2,2) [C,h] = contour(XX,YY,log10(abs(node_poly(ZZ,xxuni))),[-5,-4,-3,-2,-1,0,1,2]); clabel(C,h) title('Uniform nodes') keyboard return %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function ll = node_poly(xx,rr) ll = ones(size(xx)); for i = 1:length(rr) ll = ll.*(xx - rr(i)); end return