0
$\begingroup$

I have certain systems of equations for which I need ANY solution if one exists. Can I get MMa to just do that?

This doesn't work:

nParticles = 4;
nPow = 2;
m = {0, 1, 0, 1};
soln = Table[Sum[a[i]^n, {i, 1, nParticles}]/nParticles == m[[n]], {n, 1, nPow}];
start = Table[{a[i], RandomReal[1] - .5}, {i, 1, nParticles}];
aa = FindRoot[soln, start]

...because it's underdetermined. It works perfectly if nParticles==nPow.

There's a similar question here: Any solution to system of equations? but the Answer-er gave an elegant MATH solution instead of a MMa solution.

$\endgroup$
2
  • 2
    $\begingroup$ Try FindInstance[soln, {a[1], a[2], a[3], a[4]}]. $\endgroup$
    – Szabolcs
    Commented Aug 9, 2015 at 21:18
  • $\begingroup$ For a FindRoot type of approach, you can for a sum of squares and use FindMinimum. If the min is zero, you have located a root. $\endgroup$ Commented Aug 10, 2015 at 16:05

2 Answers 2

4
$\begingroup$

I used something like the following in Plotting implicitly-defined space curves.

Clear[findPoint, pseudonewton];
pseudonewton[f_List, vars_] := pseudonewton[f, D[f, {vars}]]; 
pseudonewton[f_List, df_?MatrixQ, vars_] := 
 With[{df0 = df /. Thread[vars -> #], f0 = f /. Thread[vars -> #]},
   # - PseudoInverse[df0].f0] &;

findPoint[eqs_List, {vars_, p0_}] := 
  With[{f = eqs /. {Equal -> Subtract}}, 
   Thread[vars -> 
     NestWhile[pseudonewton[f, D[f, {vars}], vars], p0, 
      Norm[f /. Thread[vars -> #]] > 1*^-15 &, 2, 100]]
   ];

findPoint[soln, Transpose@start]
(*  {a[1] -> 0.741866, a[2] -> -0.0513263, a[3] -> -1.61188, a[4] -> 0.921336}  *)

soln /. %
(*  {True, True}  *)
$\endgroup$
1
$\begingroup$

Not hard.

vars = Table[a[i], {i, 1, nParticles}];
FindInstance[soln, vars]

(* {{a[1] -> 0, a[2] -> 0, a[3] -> -Sqrt[2], a[4] -> Sqrt[2]}} *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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