// make the jacobian matrix. J(i,j) is the distnace the i-th ray // travels in the j-th cell. function jacobian = makejacobian(nrows,ncols,deltaz,rec) jacobian = zeros(nrows,ncols); for i = 1:nrows ndepth = floor(rec(i)/deltaz); // ndepth is layer you're in eps = rec(i) - ndepth * deltaz; for j = 1:ncols if(j <= ndepth) jacobian(i,j) = deltaz; elseif(j > ndepth) jacobian(i,j) = eps; break end end end