Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I need some help with parallelizing the calculation of a vector function F which is inside a recursive formula. An example of the code is below for few iterations. The function F is calculated using all the values for r in the last iteration. The time consuming part of the code is the calculation of F and increase rapidly when the iterator p is large (For example 100).

r[1, 1] = {1, 0, 0};
r[2, 1] = {0, 1, 0};
r[3, 1] = {0, 0, 1};
F[1, 1] = {1, 0, 1};
F[2, 1] = {1, 0, 1};
F[3, 1] = {1, 0, 1};


F[i_, n_] := -(Sum[1/Norm[r[i, n] - r[j, n]], {j, 1, i - 1}] + 
          Sum[1/Norm[r[i, n] - r[j, n]], {j, i + 1, p}]); 


p = 3;
nsteps = 50;
Do[Do[{r[i, n] = r[i, n - 1] + F[i, n - 1]}, {i, 1, p}], {n, 2, 
   nsteps}];
Table[r[1, n], {n, 1, nsteps}] // TableForm
share|improve this question

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.