Do you even need to collect the last vector? This is more than 3x faster again:
x = 0:99
xhat = mean(x)
xminxhat = x .- xhat
Do you even need to collect the last vector? This is more than 3x faster again:
x = 0:99
xhat = mean(x)
xminxhat = x .- xhat