function [y_err] = finderror(X)

global datain

% Shows plots while fitting
plotfit(X)
pause(0.1)

t = datain(:,1) ;
ydat = datain(:,2);

amplitude = X(1);
omega = X(2);
phi = X(3);
dc = X(4);

y = amplitude*sin(omega*t + phi)+dc;

y_err = norm(y - ydat);