function [eta1, eta2, eta3]=three_fitting_method_and_plotting(fig_num,x,y)

%---three different methods are used to fit the x, y data
%--1. Truncated Power Law method;--- Outputs: eta1
%--2. Weibull distribution---    --- Outputs: eta2
%--3. Power Law distribution---  --- Outputs: eta3

%---THEN, a loglog plot is made on figure(fig_num)

%---start fitting the data---
%---Truncated Power law distribution---
% x=MCD_norm;
% y=N_L;
F_powerlaw=@(epsilong,x)(epsilong(1)*(x.^(-1*epsilong(2))-epsilong(3).^(-1*epsilong(2))));
epsilong0 = [min(x) 1 x(end)];
lb = [min(x)/10 0 1];
ub = [10^6 10^6 10^6];
options=optimset('LargeScale','on','MaxFunEvals',100000,'TolFun',1e-5,'MaxIter',10000);
[epsilong,resnorm,residual,exitflag,output,~,jacobian] = lsqcurvefit(F_powerlaw,epsilong0,x,y,lb,ub,options);
x_plot=[min(x):0.001:max(x)*1.5];
y_fit_powerlaw = (epsilong(1)*(x_plot.^(-1*epsilong(2))-epsilong(3).^(-1*epsilong(2))));
figure(fig_num)
hold on

loglog(x_plot,y_fit_powerlaw,'--g','LineWidth',2)
eta1 = epsilong;
clear epsilong
%---Weibull distribution---

F_weibull=@(epsilong,x)(exp(-(x./epsilong(2)).^(epsilong(1))));
epsilong0 = [1 mean(x)];
[epsilong,resnorm,residual,exitflag,output,~,jacobian] = lsqcurvefit(F_weibull,epsilong0,x,y);
x_plot=[min(x):0.001:max(x)*1.5];
y_fit_weibull =(exp(-(x_plot./epsilong(2)).^(epsilong(1))));
figure(fig_num)
hold on

loglog(x_plot,y_fit_weibull,':b', 'LineWidth',2)
eta2=epsilong;

%---Power law distribution---
clear epsilong
F_powerlaw0=@(epsilong,x)(epsilong(1)*(x.^(-1*epsilong(2))));
epsilong0 = [min(x) 1];
[epsilong,resnorm,residual,exitflag,output,~,jacobian] = lsqcurvefit(F_powerlaw0,epsilong0,x,y);
x_plot=[min(x):0.001:max(x)*1.5];
y_fit_powerlaw0 = (epsilong(1)*(x_plot.^(-1*epsilong(2))));
figure(fig_num)
hold on

loglog(x_plot,y_fit_powerlaw0,'k','LineWidth',2)
eta3=epsilong;

set(gcf, 'Color','w')
set(gca,'Box','off','Fontsize',18)
xlabel(gca,'MCD[m]','Fontsize',25,'interpreter','Latex');
ylabel(gca,'Cumulative Frequency','Fontsize',25,'interpreter','Latex');
legend(gca,{'Test data','Upper Truncated Power-Law', 'Weibull','Power-Law'},'Box','on')
legend('location','southwest')

axis tight



end