function demo5 close all format long format compact % % *** user specified quantities ********** nsub=100 % number of subdivisions lambda=0.999 % parameter lambda theta=pi/2 % corner opening angle npan=10; % number of coarse panels evec=1; % a unit vector % **************************************** T16=Tinit16; W16=Winit16; [IP,IPW]=IPWinit(T16,W16); T16p1=T16+1; % Pbc=zeros(96,64); Pbc( 1:16, 1:16)=eye(16); Pbc(17:48,17:32)=IP; Pbc(49:96,33:64)=flipud(fliplr(Pbc(1:48,1:32))); % PWbc=zeros(96,64); PWbc( 1:16, 1:16)=eye(16); PWbc(17:48,17:32)=IPW; PWbc(49:96,33:64)=flipud(fliplr(PWbc(1:48,1:32))); check_PwTP=norm(PWbc'*Pbc-eye(64)) % % *** panel breakpoints and interval lengths in parameter *** sinter=linspace(0,1,npan+1); sinterdiff=ones(npan,1)/npan; % % *** discretization points and weights *** npcoa=16*npan scoa=zeros(npcoa,1); wcoa=zeros(npcoa,1); for k=1:npan myind=k*16-15:k*16; sdif=sinterdiff(k)/2; scoa(myind)=(sinter(k)+sinter(k+1))/2+sdif*T16; wcoa(myind)=W16*sdif; end zcoa=zfunc(scoa,theta) ; zpcoa=zpfunc(scoa,theta); zppcoa=zppfunc(scoa,theta); % *** some extra presicion gained from symmetry *** zcoa(npcoa/2+1:npcoa)=conj(flipud(zcoa(1:npcoa/2))); zpcoa(npcoa/2+1:npcoa)=-conj(flipud(zpcoa(1:npcoa/2))); zppcoa(npcoa/2+1:npcoa)=conj(flipud(zppcoa(1:npcoa/2))); % ************************************************* nzcoa=-1i*zpcoa./abs(zpcoa); wzpcoa=wcoa.*zpcoa; arclength=sum(abs(wzpcoa)) area=0.5*imag(conj(zcoa).'*wzpcoa) % % *** The K_coa^{\circ} matrix is set up *** Kcirccoa=M1Ainit(zcoa,zpcoa,zppcoa,nzcoa,wcoa,wzpcoa,npcoa); starind=[npcoa-31:npcoa 1:32]; Kcirccoa(starind,starind)=zeros(64); % % *** recursion for the R matrix *** Rstor=zeros(64,64,nsub); Klocstor=zeros(96,96,nsub); for level=1:nsub sloc=[T16p1/4;T16/4+0.75;T16/2+1.5]/2^(nsub-level)/npan; wloc=[W16/4;W16/4;W16/2]/2^(nsub-level)/npan; zloc=zfunc(sloc,theta); zploc=zpfunc(sloc,theta); zpploc=zppfunc(sloc,theta); zloc=[conj(flipud(zloc));zloc]; zploc=[-conj(flipud(zploc));zploc]; zpploc=[conj(flipud(zpploc));zpploc]; wloc=[flipud(wloc);wloc]; nzloc=-1i*zploc./abs(zploc); wzploc=wloc.*zploc; Kloc=M1Ainit(zloc,zploc,zpploc,nzloc,wloc,wzploc,96); Klocstor(:,:,level)=Kloc; MAT=eye(96)+lambda*Kloc; if level==1 R=inv(MAT(17:80,17:80)); end Rstor(:,:,level)=R; R=SchurBana(PWbc,Pbc,MAT,R); end Rcoa=eye(npcoa); Rcoa(starind,starind)=R; % % *** Solving main linear system *** g=2*real(conj(evec)*nzcoa); [rhotildecoa,it]=myGMRESR(lambda*Kcirccoa,Rcoa,lambda*g, ... abs(wzpcoa),npcoa,100,eps); GMRES_iter_RCIP=it % % *** Reconstruction of rhofin on Gamma^{\star} *** for premature=1:nsub nse=nsub-premature+1; rhotilde=rhotildecoa(starind); rhofinloc=zeros(16*(4+2*nse),1); for k=nsub:-1:premature lmbKcirc=lambda*Klocstor(:,:,k); lmbKcirc(17:80,17:80)=zeros(64); MAT=eye(96)+lmbKcirc; MAT(17:80,17:80)=inv(Rstor(:,:,k)); myind1L=(nsub-k)*16+(1:16); myind2L=(nsub+k-2*premature+5)*16+(1:16); tmp=Pbc*rhotilde; rhotilde=tmp-lmbKcirc*(MAT\tmp); rhofinloc([myind1L myind2L])=rhotilde([1:16 81:96]); rhotilde=rhotilde(17:80); end rhofinloc(nse*16+1:(4+nse)*16)=Rstor(:,:,premature)*rhotilde; % % *** rhofin globally *** rhofin=zeros(16*(npan+2*nse),1); rhofin(1:16*(2+nse))=rhofinloc(16*(2+nse)+1:16*(4+2*nse)); rhofin(16*(2+nse)+1:16*(2+nse)+(npan-4)*16)=rhotildecoa(33:(npan-2)*16); rhofin(16*(2+nse)+(npan-4)*16+1:16*(npan+2*nse))=rhofinloc(1:16*(2+nse)); % % *** q from rhofin *** [zfin,wzpfin]=finegrid(nse,theta,npan,W16,T16); zeta=real(conj(evec)*zfin.*abs(wzpfin)); qfin=rhofin'*zeta qref=1.1300163213105365; myerr=abs(qref-qfin)/abs(qref); myerr(myerrabs(a) temp=a/b; s=1/sqrt(1+temp^2); c=temp*s; else temp=b/a; c=1/sqrt(1+temp^2); s=temp*c; end function M1=M1Ainit(z,zp,zpp,nz,w,wzp,N) % *** adjoint of double layer potential *** M1=zeros(N); for m=1:N M1(:,m)=abs(wzp(m))*real(nz./(z(m)-z)); M1(m,m)=-w(m)*imag(zpp(m)/zp(m))/2; end M1=M1/pi; function zout=zfunc(s,theta) zout=sin(pi*s).*exp(1i*theta*(s-0.5)); function zpout=zpfunc(s,theta) zpout=(pi*cos(pi*s)+1i*theta*sin(pi*s)).*exp(1i*theta*(s-0.5)); function zppout=zppfunc(s,theta) zppout=(2i*pi*theta*cos(pi*s)-(theta^2+pi^2)*sin(pi*s)).* ... exp(1i*theta*(s-0.5)); function T=Tinit16 % *** 16-point Gauss-Legendre nodes *** T=zeros(16,1); T( 1)=-0.989400934991649932596154173450332627; T( 2)=-0.944575023073232576077988415534608345; T( 3)=-0.865631202387831743880467897712393132; T( 4)=-0.755404408355003033895101194847442268; T( 5)=-0.617876244402643748446671764048791019; T( 6)=-0.458016777657227386342419442983577574; T( 7)=-0.281603550779258913230460501460496106; T( 8)=-0.095012509837637440185319335424958063; T( 9)= 0.095012509837637440185319335424958063; T(10)= 0.281603550779258913230460501460496106; T(11)= 0.458016777657227386342419442983577574; T(12)= 0.617876244402643748446671764048791019; T(13)= 0.755404408355003033895101194847442268; T(14)= 0.865631202387831743880467897712393132; T(15)= 0.944575023073232576077988415534608345; T(16)= 0.989400934991649932596154173450332627; function W=Winit16 % *** 16-point Gauss-Legendre weights *** W=zeros(16,1); W( 1)= 0.027152459411754094851780572456018104; W( 2)= 0.062253523938647892862843836994377694; W( 3)= 0.095158511682492784809925107602246226; W( 4)= 0.124628971255533872052476282192016420; W( 5)= 0.149595988816576732081501730547478549; W( 6)= 0.169156519395002538189312079030359962; W( 7)= 0.182603415044923588866763667969219939; W( 8)= 0.189450610455068496285396723208283105; W( 9)= 0.189450610455068496285396723208283105; W(10)= 0.182603415044923588866763667969219939; W(11)= 0.169156519395002538189312079030359962; W(12)= 0.149595988816576732081501730547478549; W(13)= 0.124628971255533872052476282192016420; W(14)= 0.095158511682492784809925107602246226; W(15)= 0.062253523938647892862843836994377694; W(16)= 0.027152459411754094851780572456018104; function [IP,IPW]=IPWinit(T16,W16) A=ones(16); AA=ones(32,16); T32=[(T16-1)/2;(T16+1)/2]; W32=[W16;W16]/2; for k=2:16 A(:,k)=A(:,k-1).*T16; AA(:,k)=AA(:,k-1).*T32; end IP=AA/A; IPW=IP.*(W32*(1./W16)');