Message Boards Message Boards

0
|
3980 Views
|
2 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Solving Simultaneous Equations using NSolve and Table

Posted 10 years ago

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

2 Replies

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.

POSTED BY: Daniel Lichtblau

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}
POSTED BY: Frank Kampas
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract