# Is there another solution for write the algorithm by matlab?

I have an algorithm as you can see below and i wrote it with different 2 ways but it seems there are problems for both solutions.is there any alternative to write it with different way?

$$X_i(k+1)= X_i(k)+ 0.1*\sum_{j\in N_i} (X_j(k)-X_i(k))$$

while( k < t )
for i = 1 : N
for j = 1 : N


Solution 1---> X(:,k+1) = X(:,k) + 0.1* ((sum(bsxfun(@minus,X(:,k).',X(:,k)),2))); Solution 2---> X(i,k+1) = X(i,k) + 0.1*((( X(j,k)-X(i,k))));

      end
end
k = k + 1;
end

-

In explicit form

$$X_1(k+1)=X_1(k)+0.1\bigg((X_1(k)-X_1(k))+(X_1(k)-X_2(k))+...+(X_1(k)-X_N(k))\bigg)$$ $$X_2(k+1)=X_2(k)+0.1\bigg((X_2(k)-X_1(k))+(X_2(k)-X_2(k))+...+(X_2(k)-X_N(k))\bigg)$$ $$...$$ $$X_N(k+1)=X_N(k)+0.1\bigg((X_N(k)-X_1(k))+(X_N(k)-X_2(k))+...+(X_N(k)-X_N(k))\bigg)$$

The algorithm should be

while( k < t )
for i = 1 : N
sum=0;
for j = 1 : N
sum=sum+0.1*(X(i,k)-X(j,k));
end
X(i,k+1)=X(i,k)+sum;
end
k = k + 1;
end

-
this give same result of solution 1 and i dont know why but when i calculate with calculator not give me right solution:( –  Toto Apr 8 '13 at 0:09
Can you post more info? How do you calculate it with calculator? –  Occupy Gezi Apr 8 '13 at 11:42