0
$\begingroup$

I have encountered a strange problem, which is, the NSolve does not calcualte, but only reproduce what I have typed. Seems there is no typo in the code I input either. I have attached the code below:

 f1 = 0.7377392112755202079`9.089193376796182 Cos[Subscript[af, 
  2]] Sin[Subscript[af, 
  1]] + (-0.6344315700984725494`9.011997365861196 Cos[Subscript[
     af, 1]] - 
   0.5218271784972072738`8.772545864993926 Sin[Subscript[af, 
     1]]) Sin[Subscript[af, 2]] == -(1/2);
f2 = 0.7729790313212816457`9.097780292912853 Cos[Subscript[af, 
  3]] Sin[Subscript[af, 
  2]] + (-0.6025154363599145082`8.971889083011506 Cos[Subscript[
     af, 2]] - 
   0.5063444223878829805`8.750028023288934 Sin[Subscript[af, 
     2]]) Sin[Subscript[af, 3]] == -(1/2);
f3 = 1/2 + (0.7981072289786766554`9.0939821495743 Cos[Subscript[af, 
     1]] - 0.4444992628014892196`8.725562683371656 Sin[Subscript[
     af, 1]]) Sin[Subscript[af, 3]] == 
   0.6750858139129968099`9.050649491643144 Cos[Subscript[af, 3]] Sin[
 Subscript[af, 1]];
eqs = {f1, f2, f3}
NSolve[eqs, {Subscript[af, 1], Subscript[af, 2], Subscript[af, 
  3]}, Reals]

the results are shown in Fig.1. I have tried a different set of equations with those variables with subscript, so seems this is not the source of the problem. Could someone help me with this? Thanks a lot!

$\endgroup$

marked as duplicate by corey979, Feyre, Young, MarcoB, happy fish Feb 12 '17 at 5:12

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • $\begingroup$ FindRoot[eqs, {{Subscript[af, 1], 0}, {Subscript[af, 2], 0}, {Subscript[af, 3], 0}}] yields a solution $\endgroup$ – george2079 Feb 8 '17 at 21:44
  • $\begingroup$ Maybe related to WorkingPrecision (see mathematica.stackexchange.com/questions/137240/…). Also, in general I would highly recommend to avoid subscript and superscript variables. It might look nice, but they are not atomic and often don't behave the way you would expect them to. $\endgroup$ – Felix Feb 8 '17 at 22:17
  • $\begingroup$ NSolve definitely doesn't like the subscripts here. Switching to atomic symbols it no longer returns immediately, but is now taking a long time. I don't have high expectations that it will work on such transcendental equations. $\endgroup$ – george2079 Feb 8 '17 at 22:49
  • $\begingroup$ @george2079 But I have tried a simpler set of equations with variables involving subscripts, which it solves, so I thought it is not the problem of them, but I have to think about it again now. The set of solution should yield at least 4 real solutions, which I have verified using another formulation. So is there anyway to find all the real solutions, even if not using the NSolve command? Thanks. $\endgroup$ – larry Feb 8 '17 at 23:06
  • $\begingroup$ @Felix The reason I use subscript is that I had to use N[] to do the estimate in some previous steps, which somehow changes af[1] etc. to af[1.0000..], which makes it difficult to delete duplicate solutions. However, if this does affect, I will change them all, though I have a large piece of code, which is gonna be a headache.. $\endgroup$ – larry Feb 8 '17 at 23:08
5
$\begingroup$
f1 = 0.7377392112755202079`9.089193376796182 Cos[af[2]] Sin[
      af[1]] + (-0.6344315700984725494`9.011997365861196 Cos[af[1]] - 
       0.5218271784972072738`8.772545864993926 Sin[af[1]]) Sin[
      af[2]] == -(1/2);
f2 = 0.7729790313212816457`9.097780292912853 Cos[af[3]] Sin[
      af[2]] + (-0.6025154363599145082`8.971889083011506 Cos[af[2]] - 
       0.5063444223878829805`8.750028023288934 Sin[af[2]]) Sin[
      af[3]] == -(1/2);
f3 = 1/2 + (0.7981072289786766554`9.0939821495743 Cos[af[1]] - 
       0.4444992628014892196`8.725562683371656 Sin[af[1]]) Sin[
      af[3]] == 
   0.6750858139129968099`9.050649491643144 Cos[af[3]] Sin[af[1]];
eqs = {f1, f2, f3};

start = Range[0, 2 Pi, Pi/3];

sol = ({af[1], af[2], af[3]} /.
      Select[Outer[FindRoot[eqs,
           {{af[1], #1, 0, 2 Pi},
            {af[2], #2, 0, 2 Pi},
            {af[3], #3, 0, 2 Pi}}] &,
         start, start, start] // Flatten[#, 2] &,
       And @@ (eqs /. #) &]) //
    Round[#, 10.^-5] & // Union // 
  Quiet

(*  {{0.61065, 3.04504, 5.03029}, {1.52516, 3.49629, 5.94345}, {1.7364, 
  1.69935, 1.67172}, {2.94679, 4.8352, 0.45597}, {3.75224, 6.18663, 
  1.8887}, {4.66676, 0.3547, 2.80186}, {4.87799, 4.84094, 
  4.81331}, {6.08838, 1.69361, 3.59756}}  *)
$\endgroup$
1
$\begingroup$

I'd go about it the same was as is shown here. Also I change naming to avoid subscripts. The idea is to turn into explicit polynomials in the trigs, add appropriate algebraic relations linking cosines to sines, and solve.

Set up:

f1 = 0.7377392112755202079`9.089193376796182 Cos[af[2]] Sin[
      af[1]] + (-0.6344315700984725494`9.011997365861196 Cos[af[1]] - 
       0.5218271784972072738`8.772545864993926 Sin[af[1]]) Sin[
      af[2]] == -(1/2);
f2 = 0.7729790313212816457`9.097780292912853 Cos[af[3]] Sin[
      af[2]] + (-0.6025154363599145082`8.971889083011506 Cos[af[2]] - 
       0.5063444223878829805`8.750028023288934 Sin[af[2]]) Sin[
      af[3]] == -(1/2);
f3 = 1/2 + (0.7981072289786766554`9.0939821495743 Cos[af[1]] - 
       0.4444992628014892196`8.725562683371656 Sin[af[1]]) Sin[
      af[3]] == 
   0.6750858139129968099`9.050649491643144 Cos[af[3]] Sin[af[1]];
eqs = {f1, f2, f3};
exprs = Apply[Subtract, eqs, {1}];
subs = {Cos[a_] :> c[a], Sin[a_] :> s[a]};
tpolys = exprs /. subs;
cosvars = Cases[Variables[tpolys], c[_]];
defpolys = Map[#^2 + s[#[[1]]]^2 - 1 &, cosvars];
allpolys = Join[tpolys, defpolys]

Solve:

AbsoluteTiming[
 solns = NSolve[allpolys, Method -> "EndomorphismMatrix"];]
realsols = Select[solns, FreeQ[#, Complex] &]
(* Out[1770]= {0.166695, Null}

Out[1771]= {{c[af[1]] -> -0.81927821, c[af[2]] -> 0.99534234, 
  c[af[3]] -> -0.31257383, s[af[1]] -> -0.57339621, 
  s[af[2]] -> -0.096403411, 
  s[af[3]] -> 0.94989347}, {c[af[1]] -> -0.81927821, 
  c[af[2]] -> 0.99534234, c[af[3]] -> -0.31257383, 
  s[af[1]] -> -0.57339621, s[af[2]] -> -0.096403411, 
  s[af[3]] -> 0.94989347}, {c[af[1]] -> 0.81927821, 
  c[af[2]] -> -0.99534234, c[af[3]] -> 0.31257383, 
  s[af[1]] -> 0.57339621, s[af[2]] -> 0.096403411, 
  s[af[3]] -> -0.94989347}, {c[af[1]] -> 0.81927821, 
  c[af[2]] -> -0.99534234, c[af[3]] -> 0.31257383, 
  s[af[1]] -> 0.57339621, s[af[2]] -> 0.096403411, 
  s[af[3]] -> -0.94989347}, {c[af[1]] -> 0.98108617, 
  c[af[2]] -> -0.12250217, c[af[3]] -> -0.89783451, 
  s[af[1]] -> -0.19357149, s[af[2]] -> 0.99246825, 
  s[af[3]] -> -0.44033304}, {c[af[1]] -> 0.98108617, 
  c[af[2]] -> -0.12250217, c[af[3]] -> -0.89783451, 
  s[af[1]] -> -0.19357149, s[af[2]] -> 0.99246825, 
  s[af[3]] -> -0.44033304}, {c[af[1]] -> -0.98108617, 
  c[af[2]] -> 0.12250217, c[af[3]] -> 0.89783451, 
  s[af[1]] -> 0.19357149, s[af[2]] -> -0.99246825, 
  s[af[3]] -> 0.44033304}, {c[af[1]] -> -0.98108617, 
  c[af[2]] -> 0.12250217, c[af[3]] -> 0.89783451, 
  s[af[1]] -> 0.19357149, s[af[2]] -> -0.99246825, 
  s[af[3]] -> 0.44033304}, {c[af[1]] -> -0.16484943, 
  c[af[2]] -> -0.12819639, c[af[3]] -> -0.10075124, 
  s[af[1]] -> 0.98631874, s[af[2]] -> 0.99174880, 
  s[af[3]] -> 0.99491165}, {c[af[1]] -> -0.16484943, 
  c[af[2]] -> -0.12819639, c[af[3]] -> -0.10075124, 
  s[af[1]] -> 0.98631874, s[af[2]] -> 0.99174880, 
  s[af[3]] -> 0.99491165}, {c[af[1]] -> 0.16484943, 
  c[af[2]] -> 0.12819639, c[af[3]] -> 0.10075124, 
  s[af[1]] -> -0.98631874, s[af[2]] -> -0.99174880, 
  s[af[3]] -> -0.99491165}, {c[af[1]] -> 0.16484943, 
  c[af[2]] -> 0.12819639, c[af[3]] -> 0.10075124, 
  s[af[1]] -> -0.98631874, s[af[2]] -> -0.99174880, 
  s[af[3]] -> -0.99491165}} *)

Now can use multiple-valued inverses, that is, arctrigs plus suitable integer multiples of Pi, to recover results in the original variables.

$\endgroup$

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