% Solution for final exam problem F.3
% crack nucleation model
% needed by cracknuc.m

function f=fact(n)
%f=(n+1).^2/2.*log(n+1) - n.^2.*log(n) + (n-1).^2.*log(n-1);

f=zeros(size(n));
for i=1:length(n),
    a=abs(n(i));
    if(a==0)
        f(i)=0;
    elseif (a==1)
        f(i)=log(4);
    else
        f(i)=(a+1).^2/2.*log(a+1) - a.^2.*log(a) + (a-1).^2/2.*log(a-1);
    end
end
