Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

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
share|improve this question

1 Answer 1

up vote 1 down vote accepted

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
share|improve this answer
    
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.