x = [1; 2; 3; 4; 5];
y = [100; 250; 300; 450; 500];

p1 = polyfit(x, y, 1);
fprintf('Linear Model (Order 1): y = %.2f*x + %.2f\n', p1(1), p1(2));

p2 = polyfit(x, y, 2);
fprintf('Quadratic Model (Order 2): y = %.2f*x^2 + %.2f*x + %.2f\n\n', p2(1), p2(2), p2(3));

figure;
plot(x, y, 'ko', 'MarkerFaceColor', 'k', 'MarkerSize', 8);
hold on;
grid on;

x_plot = linspace(0, 6, 100);
y_plot1 = polyval(p1, x_plot);
y_plot2 = polyval(p2, x_plot);

plot(x_plot, y_plot1, 'b-', 'LineWidth', 2);
plot(x_plot, y_plot2, 'r--', 'LineWidth', 2);

xlabel('Advertising Budget (P1,000)');
ylabel('Collection Visitors');
title('Social Media Campaign Data Fitting');
legend('Actual Data', 'Order 1 (Linear)', 'Order 2 (Quadratic)', 'Location', 'northwest');

spend1 = 7;
spend2 = 8.5;

pred1 = polyval(p1, spend1);
pred2 = polyval(p1, spend2);

fprintf('--- Predictions (Using Linear Model) ---\n');
fprintf('Predicted visitors for P7,000 budget: %.0f\n', pred1);
fprintf('Predicted visitors for P8,500 budget: %.0f\n\n', pred2);

target_visitors1 = 800;
target_visitors2 = 1200;

est_budget1 = (target_visitors1 - p1(2)) / p1(1);
est_budget2 = (target_visitors2 - p1(2)) / p1(1);

fprintf('--- Budget Estimations (Using Linear Model) ---\n');
fprintf('Estimated budget for 800 visitors: P%.0f\n', est_budget1 * 1000);
fprintf('Estimated budget for 1,200 visitors: P%.0f\n', est_budget2 * 1000);

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: