If anyone could explain to me how I keep getting error 21 in Scilab using this code?
<p>Like the title says, my total array won't add any of the values taken from any of my distance arrays and would only return a 1. My total array wont also recognize any i values and seem to completely ignore it. </p>

<p>Any help would be appreciated for giving me advice.</p>

<pre><code>perms_x = perms(x)
perms_y = perms(y)
lngth = length(x)
fctrl = factorial(lngth)
total = zeros(fctrl)                       //initializes a zero array using factorial as the number of elements
for i=1:fctrl                                 //loop that goes from 1 to factorial value
    for k=1:lngth               //loops from the start of the array until the length
        distance(k) = sqrt((perms_x(i,k)-perms_x(i, k+1))^2 + (perms_y(i, k+1)-perms_y(i, k+1))^2);
        total(i) = distance(k) + sum(i);
    end
   //adds the value of city 1 to 0
   distance_1(i) = sqrt(perms_x(i,1)^2+perms_y(i,1)^2);
   //adds the value of city n to 0
   distance_n(i) = sqrt(perms_x(i,lngth)^2+perms_y(i,lngth)^2);
   //adds both values of city 1 and city n to the current sum
   total(i) = total(i) + distance_1(i) + distance_n(i);
end
disp (total)
g=min(total)
</code></pre>