%This fucction is called by mask1.m to optimiae the chi-square function chi = chisq(x, smat, observed, fixdensity) x = fixdensity .* x; %force zeros with fixdensity model = x * smat; %model = (fixdensity .* x) * smat ; %force zeros with fixdensity?? chi = sum ( ((observed - model) .^ 2) ./ abs(model) ); return;