function [Eb, Weizaecker]=CalcEb(Z,A,M)
%Z: atomic number
%A: atomic mass number
%M: nuclear mass in GeV/c^2 

mp=0.93827; %GeV
mn=0.93957; %GeV

N=A-Z;

Eb=(Z*mp+N*mn-M)*1000; %(MeV)
fprintf('binding energy Eb is %5.1f MeV\n',Eb)

Weizaecker_evenodd=15.75*A-17.8*A^(2/3)-.711*Z^2/A^(1/3)-23.7*(A-2*Z)^2/A;

Weizaecker=Weizaecker_evenodd;
%even-even
if (2*round(Z/2)==Z)&(2*round(N/2)==N)
    Weizaecker=Weizaecker+11.18/sqrt(A);
    fprintf('This is an even-even nucleus. Weizaecker binding energy is %5.1f MeV\n',Weizaecker)
end
%odd odd
if (2*round(Z/2)>Z)&(2*round(N/2)>N)
    'odd-odd'
    Weizaecker=Weizaecker+11.18/sqrt(A);
    fprintf('This is an odd-odd nucleus. Weizaecker binding energy is %5.1f MeV\n',Weizaecker)
end
%else its just the even-odd part
if Weizaecker==Weizaecker_evenodd
    fprintf('This is an even-odd or odd-even nucleus. Weizaecker binding energy is %5.1f MeV\n',Weizaecker)
end

err=abs(Eb-Weizaecker)/Eb;
fprintf('Wiezaecher is off by %5.2f percent\n',err*100)
