close all; clear; clc

tic
x = zeros(10000, 1);
for i = 2:length(x)
    x(i) = x(i-1) + i^2;
end
toc

clear x

tic
cumsum((2:1000).^2);
toc