clc
clear
% Data
t = 1:10;
p_data = [26.1 27.0 28.2 29.0 29.8 30.6 31.1 31.3 31.0 30.5];
% Fits
p1 = polyfit(t, p_data, 1); % linear
p2 = polyfit(t, p_data, 2); % quadratic
p3 = polyfit(t, p_data, 3); % cubic
% Smooth plotting
t_fit = linspace(1, 11, 200);
y1 = polyval(p1, t_fit);
y2 = polyval(p2, t_fit);
y3 = polyval(p3, t_fit);
% Plot
figure;
plot(t, p_data, 'ko', 'MarkerSize',8, 'LineWidth',2); hold on;
plot(t_fit, y1, 'r-', 'LineWidth',2);
plot(t_fit, y2, 'b-', 'LineWidth',2);
plot(t_fit, y3, 'g-', 'LineWidth',2);
title('Pressure vs Time Polynomial Fits');
xlabel('Time (sec)');
ylabel('Pressure (psi)');
legend('Data','Linear','Quadratic','Cubic','Location','best');
grid on;
% Prediction at t = 11
t_pred = 11;
pred1 = polyval(p1, t_pred);
pred2 = polyval(p2, t_pred);
pred3 = polyval(p3, t_pred);
fprintf('Prediction at t=11:\n');
fprintf('Linear: %.4f psi\n', pred1);
fprintf('Quadratic: %.4f psi\n', pred2);
fprintf('Cubic: %.4f psi\n', pred3);
To embed this project on your website, copy the following code and paste it into your website's HTML: