Answered step by step
Verified Expert Solution
Question
1 Approved Answer
% Load the data GetEarlyCoronaData; % Limit the data to the first 3 0 days mask = days < = 3 0 ; days =
Load the data
GetEarlyCoronaData;
Limit the data to the first days
mask days ;
days daysmask;
cases casesmask;
Figure : Plot days vs cases
figure;
figure;
plotdays cases, bo; Plot data points using blue circles
Calculate the linear fit y ax b
plinear polyfitdays cases, ;
alinear plinear; Slope
blinear plinear; Intercept
yfitlinear polyvalplinear, days;
Plot the linear fit line
hold on;
plotdays yfitlinear, r; Plot linear fit using red line
legendData points', 'Linear fit';
titleFigure : Days vs Cases with Linear Fit';
xlabelDays;
ylabelCases;
Add legend and labels
fprintfLinear fit equation: y f x f
alinear, blinear;
Display linear fit parameters and sum squared errors
SSElinear sumcases yfitlinear;
fprintfSum squared error for linear fit: f
SSElinear;
Figure : Plot logcases vs days and calculate the best firstorder
linear fit
figure;
logcases logcases;
plotdays logcases, bo; Plot data points using blue circles
Calculate the linear fit for logcaseslogy ax b
plog polyfitdays logcases, ;
alog plog; Slope
blog plog; Intercept
logfit polyvalplog days;
Plot the linear fit line
hold on;
plotdays logfit, r;
legendData points', 'Loglinear fit';
titleFigure : Days vs logCases with LogLinear Fit';
xlabelDays;
ylabellogCases;
Print loglinear fit equation and sum squared error
fprintfLoglinear fit equation: logyf x f
alog blog;
Calculate the sum squared error for the loglinear fit
SSElog sumlogcases logfit;
fprintfSum squared error for loglinear fit: f
SSElog;
Figure : Use the loglinear fit to calculate the exponential fit and plot
figure;
Exponential fit
yexpfit expalog days blog;
Plot the original data and the exponential fit
plotdays cases, bo; Plot data points using blue circles
hold on;
plotdays yexpfit, r; Plot exponential fit using red line
legendData points', 'Exponential fit';
titleFigure : Days vs Cases with Exponential Fit';
xlabelDays;
ylabelCases;
Calculate the sum squared error for the exponential fit
SSEexp sumcases yexpfit;
fprintfSum squared error for exponential fit: f
SSEexp;
Compare the sum squared error terms and conclude which fit is better
if SSEexp SSElinear
fprintfThe exponential model provides a better fit with smaller sum
squared error.
;
else
fprintfThe linear model provides a better fit with smaller sum squared
error.
;
end
Estimate how long it takes to double the number of cases
doublingtime log alog;
fprintfEstimated number of days to double the number of cases: f
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started