function [beta,gamma,t_offset]=get_params1(t_data,I_data)

% Create an anonymous function handle to the MATLAB file.
f = @(x)mycost(x);


% Initial guess - beta, gamma, t_offset:
x0 = [2,1,-2];

lb=[0,0, -10];
ub=[10,10,0];

options = optimoptions('fmincon','Display','final');
[x, fval] = fmincon(f,x0,[],[],[],[],lb,ub,[],options);

beta=x(1);
gamma=x(2);
t_offset=x(3);

disp('************************************************')
display(strcat('cost function=',num2str(fval)));
disp('optimum parameters=')
display(strcat('beta=',num2str(beta)));
display(strcat('gamma=',num2str(gamma)));
display(strcat('t_offset=',num2str(t_offset)));
disp('************************************************')

[~,I,~,t]=sir_solve(beta,gamma,t_offset,1);
semilogy(t,I,t_data,I_data,'o')
drawnow

function y=mycost(x)
    beta_loc=x(1);
    gamma_loc=x(2);
    t_offset_loc=x(3);
    % Patient zero is introduced at t=t_offset:
    I_init_loc=1;

    [~,I,~,t]=sir_solve(beta_loc,gamma_loc,t_offset_loc,I_init_loc);

    % semilogy(t,I,t,I_data,'o')
    % drawnow

    corr=0.1;
    y=sum( (log(I+corr)-log(I_data+corr)).^2);
end

end

