figure;
hold on; 

% data
timePoints = [0, 10, 15, 20, 22.5, 30];
velocityPoints = [0, 227, 363, 517, 603, 902];
plot(timePoints, velocityPoints, 'O','MarkerFaceColor','g');

% polynomial fit to data
vCoeffs = polyfit(timePoints, velocityPoints,2); % 2nd order polynomial

% plot polynomial
time = linspace(0,30, 100);
velocity = polyval(vCoeffs, time);
plot(time, velocity);

% plot attributes
xlabel('Time/seconds');
ylabel('Velocity/meters per second');
grid on;

hold off;

input('Hit Enter to see position and acceleration')

% position is integral of velocity
xCoeffs = polyint(vCoeffs,0);
distance = polyval(xCoeffs, time);

% acceleration is derivative of velocity
aCoeffs = polyder(vCoeffs);
acceleration= polyval(aCoeffs, time);

% plot position and acceleration
figure;
subplot(1,2,1);
plot(time,distance);
xlabel('Time/seconds'); ylabel('Distance/meters'); grid on;
subplot(1,2,2);
plot(time, acceleration);
xlabel('Time/seconds');ylabel('Acceleration/meters per second^2'); grid on;