Answered step by step
Verified Expert Solution
Link Copied!

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 30 days
mask = days <=30;
days = days(mask);
cases = cases(mask);
% Figure 1: Plot days vs. cases
figure;
figure;
plot(days, cases, 'bo'); % Plot data points using blue circles
% Calculate the linear fit (y = ax + b)
p_linear = polyfit(days, cases, 1);
a_linear = p_linear(1); % Slope
b_linear = p_linear(2); % Intercept
y_fit_linear = polyval(p_linear, days);
% Plot the linear fit line
hold on;
plot(days, y_fit_linear, 'r-'); % Plot linear fit using red line
legend('Data points', 'Linear fit');
title('Figure 1: Days vs. Cases with Linear Fit');
xlabel('Days');
ylabel('Cases');
% Add legend and labels
fprintf('Linear fit equation: y =%.2f * x +%.2f
', a_linear, b_linear);
% Display linear fit parameters and sum squared errors
SSE_linear = sum((cases - y_fit_linear).^2);
fprintf('Sum squared error for linear fit: %.4f
', SSE_linear);
% Figure 2: Plot log(cases) vs. days and calculate the best first-order
linear fit
figure;
log_cases = log(cases);
plot(days, log_cases, 'bo'); % Plot data points using blue circles
% Calculate the linear fit for log(cases)(log(y)= ax + b)
p_log = polyfit(days, log_cases, 1);
a_log = p_log(1); % Slope
b_log = p_log(2); % Intercept
log_fit = polyval(p_log, days);
% Plot the linear fit line
hold on;
plot(days, log_fit, 'r-');
legend('Data points', 'Log-linear fit');
title('Figure 2: Days vs. log(Cases) with Log-Linear Fit');
xlabel('Days');
1
ylabel('log(Cases)');
% Print log-linear fit equation and sum squared error
fprintf('Log-linear fit equation: log(y)=%.2f * x +%.2f
', a_log, b_log);
% Calculate the sum squared error for the log-linear fit
SSE_log = sum((log_cases - log_fit).^2);
fprintf('Sum squared error for log-linear fit: %.4f
', SSE_log);
% Figure 3: Use the log-linear fit to calculate the exponential fit and plot
figure;
% Exponential fit
y_exp_fit = exp(a_log * days + b_log);
% Plot the original data and the exponential fit
plot(days, cases, 'bo'); % Plot data points using blue circles
hold on;
plot(days, y_exp_fit, 'r-'); % Plot exponential fit using red line
legend('Data points', 'Exponential fit');
title('Figure 3: Days vs. Cases with Exponential Fit');
xlabel('Days');
ylabel('Cases');
% Calculate the sum squared error for the exponential fit
SSE_exp = sum((cases - y_exp_fit).^2);
fprintf('Sum squared error for exponential fit: %.4f
', SSE_exp);
% Compare the sum squared error terms and conclude which fit is better
if SSE_exp < SSE_linear
fprintf('The exponential model provides a better fit with smaller sum
squared error.
');
else
fprintf('The linear model provides a better fit with smaller sum squared
error.
');
end
% Estimate how long it takes to double the number of cases
doubling_time = log(2)/ a_log;
fprintf('Estimated number of days to double the number of cases: %.2f

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Structured Search For Big Data From Keywords To Key-objects

Authors: Mikhail Gilula

1st Edition

012804652X, 9780128046524

More Books

Students also viewed these Databases questions

Question

Evaluate the answers accurate to the cent. 5[19 + (52 - 16)2]2

Answered: 1 week ago