📄 examp.m
字号:
%initialize the workspaceclearrand('state',0);randn('state',0);%initialize the design matrixG = zeros(94,256);%number of model parameters in the problemm = 256;%parameter indices increase going down each column%m(1) is in the NW corner, m(16) is in the SW corner%m(241) in the NE corner, and m(256) is in the SE corner%design matrix entries for the column scan%ones where each ray hits a block, zeros otherwisefor i=1:16 for j=(i-1)*16+1:i*16 G(i,j) = 1.; endend%design matrix for the row scan%ones where each ray hits a block, zeros otherwisefor i=1:16 for j=i:16:240+i G(i+16,j) = 1.; endend%enlarge the g design matrix to accommodate the diagonal scans%g matrix for the SW to NE diagonal scan, upper part%because we're now going through blocks on the diagonal, we%have entries of sqrt(2) where we intersect a blockfor i=1:16for j=0:i-1G(i+32,i+j*15) = sqrt(2.);endend%g matrix for the SW to NE diagonal scan, lower partfor i=1:15for j=0:15-iG(i+48,(i+1)*16+j*15) = sqrt(2.);endend%g matrix for the NW to SE diagonal scan, lower partfor i=1:16for j=0:i-1G(i+63,17-i+17*j) = sqrt(2.);endend%g matrix for the NW to SE diagonal scan, upper partfor i=1:15for j=0:15-iG(i+79,(i*16)+1+17*j) = sqrt(2.);endend%% Setup the true model.%mtruem=zeros(16,16);mtruem(9,9)=1;mtruem(9,10)=1;mtruem(9,11)=1;mtruem(10,9)=1;mtruem(10,11)=1;mtruem(11,9)=1;mtruem(11,10)=1;mtruem(11,11)=1;mtruem(2,3)=1;mtruem(2,4)=1;mtruem(3,3)=1;mtruem(3,4)=1;mtruev=reshape(mtruem,256,1);%% Compute the data.%dtrue=G*mtruev;%% Add the noise.%rand('state',0);d=dtrue+0.01*randn(size(dtrue));%% First, plot the true model.%figure(1);bookfonts;imagesc(mtruem,[-0.2 1.2]);%;colormap(gray);H=colorbar;set(H,'FontSize',18);%print -deps mtomo.eps%% Next, compute the generalized inverse solution, using 87 singular values.%t=cputime;[U,S,V]=svd(G);UP=U(:,1:87);VP=V(:,1:87);SP=S(1:87,1:87);mg=VP*inv(SP)*UP'*d;disp('cputime for gen inv solution ');cputime-t%% And plot the solution.%figure(2);bookfonts;imagesc(reshape(mg,16,16),[-0.2 1.2]);%;colormap(gray);H=colorbar;set(H,'FontSize',18);%print -deps mg.eps%% Next,compute the Kaczmarz solution, 94 iterations.%t=cputime;mkac=kac(G,d,0.0,200);disp('Kac time');cputime-t%% And plot the solution.%figure(3);bookfonts;imagesc(reshape(mkac,16,16),[-0.2 1.2]);%;colormap(gray);H=colorbar;set(H,'FontSize',18);%print -deps mkac.eps%% Next,compute the ART solution, 200 iterations.%t=cputime;mart=art(G,d,0.0,200);disp('ART time');cputime-t%% And plot the solution.%figure(4);bookfonts;imagesc(reshape(mart,16,16),[-0.2 1.2]);%;colormap(gray);H=colorbar;set(H,'FontSize',18);%print -deps mart.eps%% Next,compute the SIRT solution, 200 iterations.%t=cputime;msirt=sirt(G,d,0.0,200);disp('SIRT time');cputime-t%% And plot the solution.%figure(5);bookfonts;imagesc(reshape(msirt,16,16),[-0.2 1.2]);colormap(gray);H=colorbar;set(H,'FontSize',18);%print -deps msirt.epsdisp('kac relative error')norm(mkac-mtruev)/norm(mtruev)disp('ART relative error')norm(mart-mtruev)/norm(mtruev)disp('SIRT relative error')norm(msirt-mtruev)/norm(mtruev)disp('SVD relative error')norm(mg-mtruev)/norm(mtruev)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -