%zero out slip on plane 3
zeroslip=ones(size(Lap,1),1);
%zeroslip(66:95)=0;
zeroslip=[zeroslip;zeroslip];

%arbitrary smoothing parmater
gamma=.0275;


G = [G11,G21, -G31, G41, G12, G22, G32, G42];
C=eye(size(dsig));

for q=1:size(dsig,1)
C(q,q)=dsig(q,q)^(-1);
end

data=[C*d;zeros(size(Lapp,1),1)];

%zero out terms belonging to patch with zero slip
wG=C*G;

zeroslip=diag(zeroslip);
wG=wG*zeroslip;
Lapp=Lapp*zeroslip;

A=[wG;Lapp/(gamma^2)];


%s=A\data;

	s=fnnls(A'*A,A'*data);

	chngsign=[ones(size(G11,2),1);ones(size(G21,2),1);-1*ones(size(G31,2),1);ones(size(G41,2),1);ones(size(G12,2)+size(G22,2)+size(G32,2)+size(G42,2),1)];
%	chngsign=[ones(size(G11,2),1);ones(size(G21,2),1);-1*ones(size(G31,2),1);ones(size(G41,2)+size(G12,2)+size(G22,2)+size(G32,2),1);-1*ones(size(G42,2),1)];

	s=s.*chngsign;
	

  % residuals

   G = [G11, G21, G31, G41, G12, G22, G32, G42];
	dhat = G*s;
	r = C*(d - dhat);
	rnorm = r'*r;


	zeroslip=diag(zeroslip);
