Code covered by the BSD License  

Highlights from
NLCSmoothReg

image thumbnail
from NLCSmoothReg by Michael Wendlandt
Computes a smooth regularized solution of an ill-posed discrete linear inverse problem.

[f,d]=chi2spectrum(gcol,guesscol,s,K,dL2xx,dL2yy,dL2xy,method,lambda),
function [f,d]=chi2spectrum(gcol,guesscol,s,K,dL2xx,dL2yy,dL2xy,method,lambda),          

% calculate deviation vector in spectral domain
dS=s-K*gcol;

% calculate chi2  
if strcmp(method,'TIK')
    f=sum(dS.^2)  + lambda^2 * sum(((gcol-guesscol)).^2);
elseif strcmp(method,'QV')
    ddxg=dL2xx*gcol;
    ddyg=dL2yy*gcol;
    dxyg=dL2xy*gcol;
    f=sum(dS.^2)  + lambda^2 * (sum(ddxg.^2) + sum(ddyg.^2) + 2 * sum(dxyg.^2));
    %f=f / sum(s.^2);
end
    
% calculate the derivative df/dg(k)
if nargout>1
    d=zeros(1,length(gcol));
    if strcmp(method,'QV')
        d= 2 * dS' * (-K)  + lambda^2 * 2 * ( (ddxg)' * dL2xx + (ddyg)' * dL2yy + 2 * (dxyg)' * dL2xy  );
    elseif strcmp(method,'TIK')
        d= 2 * dS' * (-K)  + lambda^2 * 2 * (gcol - guesscol)';
    end
end 
%d=d / sum(s.^2);

Contact us at files@mathworks.com