close all; clear; clc

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

clear x

tic
x = cumsum((2:100000).^2);
toc