% program to make a vector from 1 to n

% set n
n = 10;

% define a blank vector of length n
x = zeros(n,1);

% initialise xsum
xsum = 0;

% loop from 1 to n, defining the elements and adding them up
for i=1:n
   x(i) = i;
   xsum = xsum + x(i);
   % check for unexpected errors
   if (xsum < 0)
      disp('ERROR: xsum is negative')
   end
end
disp('Value of xsum:')
disp(xsum)
