Your code is slow and complex because:
- you expand all of the arrays xk2, xk3, ... xk208 on every loop iteration, which forces MATLAB to shift them in memory on every iteration, which forces your code to be slow.
- you calculate the sum of the arrays xk2, xk3, ... xk208 on every loop iteration, even though you discard all of those results except for the ones calculated on the final loop iteration. Total waste of time.
- Using numbered variables is a sign that you are doing something wrong. Using indexing is much more efficient overall, using loops would take less effort.
- Copy-and-pasting code is a sign that you are doing something wrong. Computers are really only very good at one thing: doing simple operations repeatedly. So when you sit there are copy-and-paste almost-identical code like that, you are just doing the computer's job for it. What a total waste of your time and a total waste of your computer. Instead you should learn how to use arrays (the most powerful and useful feature of MATLAB): https://www.mathworks.com/help/matlab/matlab_prog/vectorization.html
For example, I replaced all of your long, slow code with this one line:
>> m = sum(bsxfun(@power,x(:),2:208),1);
And comparing the first value:
ans = 3383.5
sumxk2 = 3383.5
and the last value:
ans = 1.1406e+208
sumxk208 = 1.1406e+208
Comparing the other 200 or so variables will demonstrate why using numbered variables is bad code design:
Oh, we might as well look at runtime too:
Elapsed time is 0.057419 seconds.
Elapsed time is 0.003724 seconds.