Comme le dit le titre, mon tableau total n'ajoutera aucune des valeurs tirées de l'un de mes tableaux de distances et ne renverra qu'un 1. Mon tableau total ne reconnaîtra pas non plus de valeurs i et semblera l'ignorer complètement.Si quelqu'un pouvait m'expliquer comment je continue d'obtenir l'erreur 21 dans Scilab en utilisant ce code?
Toute aide serait appréciée pour me donner des conseils.
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)