You are on page 1of 2

Inverse problem pde example

% number of samples in x and z direction: n = 101; % amount of noise added to partial derivatives: e = 0.5; x = linspace(-1,1,n); z = linspace(-1,1,n); dx = x(2) - x(1); dz = z(2) - z(1); [X,Z] = meshgrid(x,z); % Hidden model: subplot(1,3,1); T = 0.5*sin(2*pi*X) - Z; imagesc(x,z,T); xlabel('x'); ylabel('z'); title('T = 0.5*sin(2*pi*x) - z'); colorbar; % Observed noisy data: P = pi*cos(2*pi*X) + e*randn(n,n); % Tx Q = -ones(n,n) + e*randn(n,n); % Tz subplot(1,3,2); imagesc(x,z,P); xlabel('x'); ylabel('z'); title('P = Tx + e'); colorbar; subplot(1,3,3); imagesc(x,z,Q); xlabel('x'); ylabel('z'); title('Q = Tz + e'); colorbar; % Central difference matrices: E = sparse(2:n, 1:n-1, 1, n, n); D = (E' - E) / 2; D(1,1) = -1; D(1,2) = 1; D(n,n) = 1; D(n,n-1) = -1;

I = speye(n); Dx = kron(D,I)/dx; Dz = kron(I,D)/dz; A = []; b = []; A = [A; Dx]; b = [b; P(:)]; A = [A; Dz]; b = [b; Q(:)]; % Least Squares Solution: figure; subplot(1,2,1); imagesc(x,z,T); xlabel('x'); ylabel('z'); title('T'); colorbar; tlse = lsqr(A, b, 1e-3, 1000*100); Tlse = reshape(tlse, [n n]); subplot(1,2,2); imagesc(x,z,Tlse); xlabel('x'); ylabel('z'); title('Tlse'); colorbar;

You might also like