function fit_check(x,y,f,p)

fit_function=@(x) f(x,p);
yfit=arrayfun(fit_function,x);
res=y-yfit;

disp('RMS residual = ');
rms_res=std(res, 1); % notice 1 which normalizes by N i(not N-1) points
disp(rms_res);

figure(1)
subplot(2,1,1)
plot(x,y,'x'); % plotting data points
hold on;
plot(x,yfit,'r-'); % plotting fitted values
hold off;
legend('data','fit');
xlabel('x'); ylabel('y');
subplot(2,1,2)
plot(x,res,'x');  % plotting residuals
hold on;
plot(x,x*0, 'k-'); % this will plot a line along x axis
legend('residuals');
xlabel('x'); ylabel('residuals');
hold off;

