# fit the six parameters of the semi-empirical mass formula to
# experimental binding energy per nucleon data

# initial guess
a1 = 15
a2 = 15
a3 = 1
a4 = 20
a5 = 1
gamma = 0.5

# the functional form of weiszacker's formula
delta(A,Z) := if(is_odd(A), 0, if(is_even(Z), +1, -1))
W(A,Z) := a1 - a2*A^(-1/3) - a3*Z*(Z-1)*A^(-4/3) - a4*(A-2*Z)^2*A^(-2) + delta(A,Z) * a5*A^(-gamma)

# the experimental data
FUNCTION D(A,Z) FILE binding.dat

# fit W to D using the six parameters
FIT W TO D VIA a1 a2 a3 a4 a5 gamma 

PRINT_FUNCTION FILE_PATH fsm-fit.dat D W D(A,Z)-W(A,Z)
PRINT SEP " " TEXT "a1 ="     %.3f  a1
PRINT SEP " " TEXT "a2 ="     %.3f  a2
PRINT SEP " " TEXT "a3 ="     %.3f  a3
PRINT SEP " " TEXT "a4 ="     %.3f  a4
PRINT SEP " " TEXT "a5 ="     %.3f  a5
PRINT SEP " " TEXT "gamma ="  %.3f  gamma
