# How to assign starting values for multiple variables in FindRoot effectively?

I've been trying to solve a system of equations numerically using FindRoot. The following is my code, and it worked well.

SysEqn = Table[40a[i]-Sum[If[j == i, 0, 1/(a[i] - a[j])] , {j, 1, 20}], {i, 1, 20}];
data = Table[a[i] /. FindRoot[
SysEqn, {{a[1], 0.05}, {a[2], 0.1}, {a[3], 0.15}, {a[4],
0.2}, {a[5], 0.25}, {a[6], 0.3}, {a[7], 0.35}, {a[8],
0.4}, {a[9], 0.45}, {a[10], 0.5}, {a[11], 0.55}, {a[12],
0.6}, {a[13], 0.65}, {a[14], 0.7}, {a[15], 0.75}, {a[16],
0.8}, {a[17], 0.85}, {a[18], 0.9}, {a[19], 0.95}, {a[20],
1}}], {i, 1, 20}]


Here I want to increase the number of variables from 20 to bigger numbers but I can't find an effective way to assign starting values for a[i] in that case. Is there any way to simplify the following...?

{{a[1], 0.05}, {a[2], 0.1}, {a[3], 0.15}, {a[4],
0.2}, {a[5], 0.25}, {a[6], 0.3}, {a[7], 0.35}, {a[8],
0.4}, {a[9], 0.45}, {a[10], 0.5}, {a[11], 0.55}, {a[12],
0.6}, {a[13], 0.65}, {a[14], 0.7}, {a[15], 0.75}, {a[16],
0.8}, {a[17], 0.85}, {a[18], 0.9}, {a[19], 0.95}, {a[20],
1}}


I tried with For but the FindRoot doesn't work with For inside, at least when I tried...

Does the following duplicate what you have?

n = 20;
SysEqn = Table[2 n a[i] - Sum[If[j == i, 0, 1/(a[i] - a[j])], {j, 1, n}], {i, 1, n}];
startingValues = Table[{a[i], -1 + 2 (i - 1)/(n - 1)}, {i, n}];
FindRoot[SysEqn, startingValues]

(* {a[1] -> -0.851836, a[2] -> -0.727906, a[3] -> -0.623722,
a[4] -> -0.529342, a[5] -> -0.440949, a[6] -> -0.356543,
a[7] -> -0.274887, a[8] -> -0.195125, a[9] -> -0.116605,
a[10] -> -0.0387918, a[11] -> 0.0387918, a[12] -> 0.116605,
a[13] -> 0.195125, a[14] -> 0.274887, a[15] -> 0.356543,
a[16] -> 0.440949, a[17] -> 0.529342, a[18] -> 0.623722,
a[19] -> 0.727906, a[20] -> 0.851836} *)

• Thanks! By the way, is it general for mathematica to recognize "f(i)" (some function of i) as a value of a[i] when we define startingValues=Table[{a[i],f(i)},{i,n}]? Commented May 20, 2017 at 2:13
• I'm not following but with the Table[{a[i], -1 + 2 (i - 1)/(n - 1)}, {i, n}] command one can obtain the format required for a list of variables and starting values. I used the particular function that seemed to match the solution (having values from -1 to 1 rather than 0 to 1 that you started with) and it seemed that the final solution would always have a[1] < a[2] <...<a[n]. Good starting values are your best friends.
– JimB
Commented May 20, 2017 at 2:21