2
$\begingroup$

I'm trying to find solutions to a fairly simple pair of simultaneous equations in variables $\phi_1, \phi_2$ using Reduce.

θ = Pi/8; (* e.g. 3.14 also doesn't work *)
points = Solve[
   Reduce[{Sin[ϕ1] + 0.1 Sin[θ + ϕ1 + ϕ2] == 
       0 && ϕ1 > -Pi && ϕ1 <= π && 
      0.1 Sin[ϕ2] + 0.1 Sin[θ + ϕ1 + ϕ2] == 
       0 && ϕ2 > -Pi && ϕ2 <= π} , {ϕ1, ϕ2}]]

However, Reduce seems to run into trouble when an external parameter $\theta$ in the equations is set to some decimal expansion, say 3.14 as opposed to $\pi$, and also when set to numbers around $\pi/8$. Reduce returns the empty list, while we know there are solutions. There are errors Reduce::ratnz and Reduce::ztest1:

enter image description here

le

PS: I will be scanning through many values of $\theta$ and also coefficients of the Sine functions so I need a fail proof way of finding all solutions in order to automate it.

$\endgroup$
4
$\begingroup$

A lot of trigonometric equation solving problems seem to work better if one uses the Weierstrass substitution.

With[{θ = π/8, φ1 = 2 ArcTan[u1], φ2 = 2 ArcTan[u2]}, 
     eqs = RootReduce[GroebnerBasis[{Sin[φ1] + Sin[θ + φ1 + φ2]/10 == 0, 
                                     Sin[φ2]/10 + Sin[θ + φ1 + φ2]/10 == 0} // TrigExpand,
                                    {u1, u2}]]];

{2 ArcTan[u1], 2 ArcTan[u2]} /. NSolve[Thread[eqs == 0], {u1, u2}, Reals]
   {{-3.0444244788667807, -1.8157299550057586},
    {3.0425062641101692, 1.4239899806853435},
    {0.020515491894360593, 2.934985366795896},
    {-0.018597277132295528, -0.1870509022832146}}

You can replace NSolve[] with Solve[] if you want to see exact solutions, but that might take you a while.

$\endgroup$
9
  • 1
    $\begingroup$ If you omit RootReduce, Solve is relatively quick, about 1 sec. $\endgroup$ – Michael E2 Feb 2 '20 at 15:15
  • $\begingroup$ Indeed, I just tried it out now, but the result will now need to be massaged with (Full)Simplify[]. Eep. $\endgroup$ – J. M.'s ennui Feb 2 '20 at 15:17
  • 1
    $\begingroup$ @Rudyard, yes, inexact numbers like 0.1 often do not play nice here, so you either use fractions and exact numbers, or use something like Rationalize[]. $\endgroup$ – J. M.'s ennui Feb 2 '20 at 15:39
  • 1
    $\begingroup$ @Rudyard, it looks like you found a case where preprocessing the set of equations to a Gröbner basis does not help. In that specific case, you can do this instead: With[{θ = π/6, φ1 = 2 ArcTan[u1], φ2 = 2 ArcTan[u2]}, eqs = Numerator[Simplify[{Sin[φ1] + 97/100 Sin[θ + φ1 + φ2], 97/100 Sin[φ2] + 97/100 Sin[θ + φ1 + φ2]} // TrigExpand]]]; {2 ArcTan[u1], 2 ArcTan[u2]} /. NSolve[Thread[eqs == 0], {u1, u2}, Reals] $\endgroup$ – J. M.'s ennui Feb 4 '20 at 11:57
  • 1
    $\begingroup$ @Rudyard, the latter one is more general, but if it is taking too long to evaluate, that is where one might consider preprocessing with GroebnerBasis[]. $\endgroup$ – J. M.'s ennui Feb 4 '20 at 14:21
3
$\begingroup$
θ = Pi/8;(*e.g.3.14 also doesn't work*)
points = 
Solve[{Sin[ϕ1] + 1/10 Sin[θ + ϕ1 + ϕ2] == 
   0 && ϕ1 > -Pi && ϕ1 <= π && 
  1/10 Sin[ϕ2] + 1/10 Sin[θ + ϕ1 + ϕ2] == 
   0 && ϕ2 > -Pi && ϕ2 <= π}, {ϕ1, ϕ2}] //
  N // Values

is this what you want?

{{-3.04442, -1.81573}, {0.0205155, 2.93499}, {3.04251, 1.42399}, {-0.0185973, -0.187051}}

$\endgroup$
7
  • 1
    $\begingroup$ That's much better thanks! It still seems to have problems in some cases, say, $\theta = 3.001$ ? $\endgroup$ – Rudyard Feb 2 '20 at 15:03
  • $\begingroup$ @Rudyard well, since it seems doesn't matter, you can just ignore the warning. (It happens because you use a Floating point number instead of exact number in Solve.) .If you don't want to see it, use //Quiet. $\endgroup$ – wuyudi Feb 2 '20 at 15:06
  • $\begingroup$ Oh I don't mind errors; I meant it's not actually able to solve it. Another example, try: ``` Solve[{Sin[[Phi]1] + 0.3 Sin[ [Phi]1 + [Phi]2] == 0 && [Phi]1 > -Pi && [Phi]1 <= [Pi] && 0.1 Sin[[Phi]2] + 0.3 Sin[ [Phi]1 + [Phi]2] == 0 && [Phi]2 > -Pi && [Phi]2 <= [Pi]}, {[Phi]1, [Phi]2}] // N // Values ``` $\endgroup$ – Rudyard Feb 2 '20 at 15:30
  • $\begingroup$ @Rudyard first , in comment , type \\ to type \ , single \ will disappear. second, you could use 3/10 instead of 0.3 . third, Solve is unable to solve this equation directly. fourth , use ` ` to contain code. $\endgroup$ – wuyudi Feb 2 '20 at 15:49
  • $\begingroup$ Thanks. Another example with coefficients rationalised below. You're saying Solve simply can't handle these? Solve[{Sin[\\[Phi]1] + 1/100 Sin[\[Phi]1 + \\[Phi]2] == 0 && \\[Phi]1 > -Pi && \\[Phi]1 <= Pi && 40/100 Sin[\\[Phi]2] + 1/100 Sin[\\[Phi]1 + \\[Phi]2] == 0. && \\[Phi]2 > -Pi && \\[Phi]2 <= Pi}, {\\[Phi]1, \\[Phi]2}] // N // Values $\endgroup$ – Rudyard Feb 3 '20 at 15:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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