weitbrej
(Jessica Weitbrecht)
1
Hi , so I’ve seen systems of simultaneous equations solved using Table and NSolve, but I’ve forgotten the appropriate syntax :
I have
M = 5
eqs = Table[q[i] == Sum[ Boole[i!=j] / (q[i] - q[j]) , {j, M}], {i, M}]
NSolve[eqs, ?]
I don’t know what to put for the variables in NSolve , I’ve tried q, q[[i]], {q[[1]],q[[2]],q[[3]],q[[4]],q[[5]]} , any help would be appreciated
fkampas
(Frank Kampas)
2
When I tried to use your method of generating the equations I got 1/0 error messages. I solved the problem as follow:
In[22]:= m = 5;
In[23]:= vars = Array[q, m]
Out[23]= {q[1], q[2], q[3], q[4], q[5]}
In[24]:= eqs =
Table[q[i] ==
Sum[1/(q[i] - q[j]), {j, Complement[Range[m], {i}]}], {i, m}]
Out[24]= {q[1] ==
1/(q[1] - q[2]) + 1/(q[1] - q[3]) + 1/(q[1] - q[4]) + 1/(
q[1] - q[5]),
q[2] == 1/(-q[1] + q[2]) + 1/(q[2] - q[3]) + 1/(q[2] - q[4]) + 1/(
q[2] - q[5]),
q[3] == 1/(-q[1] + q[3]) + 1/(-q[2] + q[3]) + 1/(q[3] - q[4]) + 1/(
q[3] - q[5]),
q[4] == 1/(-q[1] + q[4]) + 1/(-q[2] + q[4]) + 1/(-q[3] + q[4]) + 1/(
q[4] - q[5]),
q[5] == 1/(-q[1] + q[5]) + 1/(-q[2] + q[5]) + 1/(-q[3] + q[5]) +
1/(-q[4] + q[5])}
In[25]:= res = NSolve[eqs, vars];
In[26]:= Dimensions[res]
Out[26]= {462, 5}
In[27]:= res[[1]]
Out[27]= {q[1] -> 0.126062 - 0.296457 I,
q[2] -> -0.382905 - 20.0784 I, q[3] -> -0.655379 - 20.7984 I,
q[4] -> -0.624409 - 22.788 I, q[5] -> -0.0794937 - 21.6188 I}
danl
(Daniel Lichtblau)
3
Or just do NSolve[eqs] and let it figure out the variables.
There is a caveat to this whole thing though. In version 10 the solutions are iffy at best. So one might do better with
NSolve[eqs, Method->"Legacy"]
I realize there is no documented method of that name, but it should work to force the former default method to be used.
I have reported a bug for the fact that the default method is not giving good solutions for this example.