%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Plot misfit function ||Ls-t|| for a nlinex2 system % of equations against variables s(1) and s(2). % % N - input - Number of equations in matrix-vector Ls=t % slope - input - Slope of line % L -variable- Nx2 matrix % s -variable- 2x1 vector of unknowns % t -variable- Nx1 RHS vector % eps -output - misfit function ||Lx-t|| % | -m 1 | |s(1)| |t(1)| % | -m 1 | |s(2)| = |t(2)| % | -m 1 | |t(3)| %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% t=0;L=0;s=0; for iter=1:7; N=5;slope=.1*iter xstart=-30;xend=30; x=xstart:1:xend;y=x; x0=0;y0=1;subplot(111) % Compute Nx2 L matrix and Nx1 t vector for m=1:N mm=(m-3)*slope; if m==1;L=[-mm 1];t=L*[x0 y0]';else; L=[L;-mm 1];t0=[-mm 1]*[x0 y0]';t=[t;t0];end end; s = inv(L'*L)*L'*t;e = (L*s-t)'*(L*s-t) % % Compute Misfit Function for different values s(1) & s(2) % for i=xstart:xend ii=i-xstart+1; for j=xstart:xend jj=j-xstart+1;xx=[i j];eps(ii,jj)=(L*xx'-t)'*(L*xx'-t); end;end imagesc([xstart:xend],[xstart:xend],eps');colorbar;hold on title('Misfit Function: ||Ls-t||');xlabel('s(1)');ylabel('s(2)');hold on; axis([xstart xend xstart xend]) % % Plot Lines % for m=1:N;plot(x,-L(m,1)*x+t(m),'-w');end;hold off;c1=cond(L); text(xstart+2,xstart+2,['condition # =',num2str(c1)]); pause(1);end