% Fit data ti sech^2 function

N=78;
%Brange=['B1:B',num2str(N)];
Crange=['C1:C',num2str(N)];
%A = xlsread('COVID19data.xlsx', 1, Brange);
C = xlsread('COVID19data.xlsx', 1, Crange);
x=1:2*N;
% My fit
a=.5E8;
alpha=0.075;
phi=117;

% First plot
figure(1)
y = a*(sech(alpha*(x-phi))).^2;
plot(x,y,1:N,C,'bo')
axis([0,100,0,1E6])
xlabel('Time (days) since Jan 22')
ylabel('Population')
title('Function Fit to COVID-19 Infected Data')

% Second plot - nonlinear fit

modelfun = @(b,x) b(1)*(sech(b(2)*(x-b(3)))).^2;
x2=1:N;
b=[a,alpha,phi];
bnew = nlinfit(x2',C,modelfun,b);
y = 1.*bnew(1)*(sech(bnew(2)*(x-bnew(3)))).^2;
figure(2)

plot(x,y,1:N,C,'bo')
axis([0,100,0,1E6])
xlabel('Time (days) since Jan 22')
ylabel('Population')
title('Function Fit to COVID-19 Infected Data')