# How to solve the following set of equations to find values of a1, a2, and a3

i am new to Mathematica, Can some one kind enough to show me how to solve the following set of nonlinear equations to find a1, a2, and a3..

ClearAll;
v1 = 0.25;
eqn = {
(Cos[a1 Degree] - Cos[a2 Degree] + Cos[a3 Degree]) -v1 == 0,
(Cos[3 a1 Degree] - Cos[3 a2 Degree] + Cos[3 a3 Degree]) == 0,
(Cos[5 a1 Degree] - Cos[5 a2 Degree] + Cos[5 a3 Degree]) == 0
};

(* Please, i need to know what commands follow from here, thanks *)
(*Note that a1 < a2 < a3 <π/2 and that a1,a2, and a3, may all be decimal numbers.*)


Note that a1 < a2 < a3 <π/2 and that a1,a2, and a3, may all be decimal numbers and degrees not radians

• Please note that a1, a2, and a3, will all be degrees not radians. thnks
– UTs
May 14 '17 at 13:28
• It might be easier to solve in radians and then convert to degrees. May 14 '17 at 13:30
• to solve should i use solve or NDsolve or Nminimize
– UTs
May 14 '17 at 13:34
• In my opinion it should be FindRoot, however, you should specify the initial values of parameters a1,a2 and a3 May 14 '17 at 13:40

One can solve the trigonometric system by converting it to a polynomial system with the usual trick of letting c and s denote cosine and sine, respectively, and adding the constraint s^2 + c^2 == 1.

sol0 = Solve[Flatten@Join[
TrigExpand@eqn /. {Cos -> c, Sin -> s},             (* convert to polynomials *)
c[#]^2 + s[#]^2 == 1 & /@ {a1, a2, a3},             (* pythagorean constraint *)
{0 <= c[#] <= 1, 0 <= s[#] <= 1} & /@ {a1, a2, a3}  (* first quadrant constraint *)
],
Join[c /@ #, s /@ #] &@{a1, a2, a3}];                 (* prescribe variables *)
Length@sol0  (* number of solutions *)
(*  2  *)


The solutions are numerically challenging and result in complex numbers. The following turns real Complex numbers into Real numbers (as well as replace the real 1. by the integer 1).

realize = # /. x_Complex /; Im[x] == 0 :> Re[x] /. (1.) -> 1 &;

systems = sol0 /. {c -> Cos, s -> Sin} /. Rule -> Equal;
N@N[systems, 16] // realize
(*
{{Cos[a1] == 0.126411, Cos[a2] == 0.644596, Cos[a3] == 0.768185,
Sin[a1] == 0.991978, Sin[a2] == 0.764524, Sin[a3] == 0.640228},
{Cos[a1] == 0.768185, Cos[a2] == 0.644596, Cos[a3] == 0.126411,
Sin[a1] == 0.640228, Sin[a2] == 0.764524, Sin[a3] == 0.991978}}
*)


Using Solve to solve these systems ought to be straightforward, but the symbolic numbers on the right-hand sides are so complicated that it takes way too long to finish. Instead, it's much easier to solve by hand:

sol = Cases[#, Sin[v_] == s_ :> v -> ArcSin[s]] & /@ systems;
N[sol, 16] // realize
(*
{{a1 -> 1.444046302394822,  a2 -> 0.8703021240983367, a3 -> 0.6947954385269770},
{a1 -> 0.6947954385269770, a2 -> 0.8703021240983367, a3 -> 1.444046302394822}}
*)


Check numerically (the symbolics are quite complicated and run too long):

eqn /. sol // N[#, 32] &
(*  {{True, True, True}, {True, True, True}}  *)


Addendum: You can simplify the process by specifying Cos[a1], Sin[a], etc. as variables and skip c and s. I think normally there is some risk to this, since built-in transformations of trigonometric functions might be applied, as far as I know.

sol0 = Solve[Flatten@Join[
TrigExpand@eqn,                                        (* convert to polynomials *)
Cos[#]^2 + Sin[#]^2 == 1 & /@ {a1, a2, a3},            (* pythagorean constraint *)
{0 <= Cos[#] <= 1, 0 <= Sin[#] <= 1} & /@ {a1, a2, a3} (* first quadrant constraint *)
],
Join[Cos@#, Sin@#] &@{a1, a2, a3}];
systems = sol0 /. Rule -> Equal;       (* systems have the same value as above *)


The rest is as above.

Reduce simply and rapidly finds a solution to this without the user needing to understand TrigExpand or other more complicated reworking of the problem.

v1 = 1/4;
Simplify[N[Reduce[{
Cos[a1] - Cos[a2] + Cos[a3] - v1 == 0,
Cos[3 a1] - Cos[3 a2] + Cos[3 a3] == 0,
Cos[5 a1] - Cos[5 a2] + Cos[5 a3] == 0,
0 < a1 < a2 < a3 < Pi/2}, {a1, a2, a3}]]]


It then produces a somewhat confusing result:

C[1] \[Element] Integers && a2 == 0.870302 && a3 == 1.44405 &&
((a1 == -0.694795 + 6.28319 C[1] && 0.11058 < C[1] < 0.249093) ||
(a1 == 0.694795 + 6.28319 C[1] && -0.11058 < C[1] < 0.0279328))


Simplify does not seem to realize that

C[1] being an integer and 0.11058 < C[1] < 0.249093 must mean that this solution must be discarded

or that

C[1] being an integer and -0.11058 < C[1] < 0.0279328 must mean that C[1] must be zero and thus a1 == 0.694795 radians.

If Reduce or Simplify did a slightly better job then this would be an exceptional result. The numerical results match the other two answers provided.

This is a possible workaround to this problem.

eqn = {(Cos[a1 ] - Cos[a2 ] + Cos[a3 ]) - v1 ==
0, (Cos[3 a1 ] - Cos[3 a2 ] + Cos[3 a3 ]) ==
0, (Cos[5 a1 ] - Cos[5 a2 ] + Cos[5 a3 ]) == 0};


I just trying many initial values and select solutions

sols = Select[
Flatten[Table[
If[({a1, a2, a3} /.
Quiet@FindRoot[eqn, {a1, a10}, {a2, a20}, {a3, a30}]) == {a10,
a20, a30}, Nothing,
Quiet@FindRoot[eqn, {a1, a10}, {a2, a20}, {a3, a30}]],
{a10, 0, \[Pi]/2, 0.1}, {a20, 0, \[Pi]/2, 0.1}, {a30, 0, \[Pi]/2,
0.1}], 2], #[[1, 2]] < #[[2, 2]] < #[[3, 2]] && #[[1, 2]] >
0 && #[[3, 2]] < \[Pi]/2 &]


The output of this very slightly differet solutions which is i think only one:

{-0.25 + Cos[a1] - Cos[a2] + Cos[a3],
Cos[3 a1] - Cos[3 a2] + Cos[3 a3],
Cos[5 a1] - Cos[5 a2] + Cos[5 a3]} /. {a1 -> 0.6947954385269768,
a2 -> 0.8703021240983365, a3 -> 1.444046302394822}
(*{-2.22045*10^-16, 5.55112*10^-17, 4.44089*10^-16}*)

• thanks to all....the above suggestions are really hard for me tounderstand....will work n try though....it they be simplified...
– UTs
May 14 '17 at 15:30

Improvement of the answer of @Bill

Simply restrict the domain of "Reduce" to "Reals"

 red1 = Reduce[{Cos[a1] - Cos[a2] + Cos[a3] - 1/4 == 0,
Cos[3 a1] - Cos[3 a2] + Cos[3 a3] == 0,
Cos[5 a1] - Cos[5 a2] + Cos[5 a3] == 0,
0 < a1 < a2 < a3 < Pi/2}, {a1, a2, a3}, Reals] // FullSimplify;


Now C[1] is expicitly restricted to Integers

red1 // N

(*
C[1] \[Element] Integers && a2 == 0.870302 &&
a3 == 1.44405 && ((a1 ==
2. (-0.347398 + 3.14159 C[1]) && -0.347398 + 3.14159 C[1] >
0. && -0.347398 + 3.14159 C[1] < 0.435151) || (a1 ==
2. (0.347398\[VeryThinSpace]+ 3.14159 C[1]) &&
0.347398\[VeryThinSpace]+ 3.14159 C[1] > 0. &&
0.347398\[VeryThinSpace]+ 3.14159 C[1] < 0.435151))    *)


You get a result only for C[1]==0

 N[red1] /. C[1] -> 0

(*    a2 == 0.870302 && a3 == 1.44405 && a1 == 0.694795    *)

N[red1] /. C[1] -> 1

(*    False    *)