this is my equation using matlab , i can't get it manually.

dmat = reshape(sqrt(sum((xy(a,:)-xy(a',:)).^2,2)),N,N);

5 comentarios

njj1
njj1 el 19 de Abr. de 2018
Your question is really unclear... It's very hard to know what these variables are and their properties without any further details. Moreover, I'm not sure of the exact error you getting, Can you provide more details?
its not an error i'm getting this equation from a script of "Fixed Start Open Multiple Traveling Salesmen Problem (M-TSP) Genetic Algorithm (GA)" i just want to get it manually like this : s = sqrt ( (x-10)^2 ---->
njj1
njj1 el 19 de Abr. de 2018
So what is your variable 'a'? What is the size of 'xy'?
maatoug ayoub
maatoug ayoub el 19 de Abr. de 2018
Editada: Stephen23 el 19 de Abr. de 2018
for k = nargin:nargs-1
switch k
case 0
xy = 10*rand(20,2);
case 1
N = size(xy,1);
a = meshgrid(1:N);
dmat = reshape(sqrt(sum((xy(a,:)-xy(a',:)).^2,2)),N,N);
case 2
salesmen = 4;
case 3
min_tour = 2;
case 4
pop_size = 80;
case 5
num_iter = 5e3;
case 6
show_prog = 1;
case 7
show_res = 1;
otherwise
end
this is a part of the script

Iniciar sesión para comentar.

 Respuesta aceptada

njj1
njj1 el 19 de Abr. de 2018
Editada: njj1 el 19 de Abr. de 2018
This looks like it's the distance from each (x,y) pair to every other (x,y) pair.
A_{i,j} = \sqrt{(x_i - x_j)^2}, where x = (x,y)

4 comentarios

njj1
njj1 el 19 de Abr. de 2018
Sorry for the multiple edits. Each entry in the final matrix that I called 'A' (and in the script is called dmat) is the Euclidean distance from one (x,y) pair to another (x,y) pair.
thank you very much ..so sum((xy(a,:)-xy(a',:) its equal {(x_i - x_j)
njj1
njj1 el 19 de Abr. de 2018
Yes, it is, but they do it in a clever, vectorized way, where they do not have any for loops to cycle through each i,j.
thank you my friend now i untrestand it

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Preguntada:

el 19 de Abr. de 2018

Comentada:

el 19 de Abr. de 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by