# Mathematica struggles to solve system of trigonometric equations?

As explained here, I'm trying to solve $$-ar \cos \phi = R \cos \psi \\ r \sin \phi = R \sin \psi$$ for $$R, \psi$$ in terms of $$r, \phi$$.

I believe the correct solution is $$R = r \sqrt{a^2 \cos^2 \phi + \sin^2 \phi}\\\psi = \arctan(\frac {-1} a \tan \phi)$$ but cannot get Mathematica to produce anything like that.

where it doesn't even solve for $$\psi$$!

Using Reduce gives a solution for $$\psi$$, but it's very different than what I'd expect:

I'm very new to Mathematica, so if I'm using it incorrectly, please let me know. Also: I can assume that e.g. $$\phi$$ is in the first quadrant and that $$\psi$$ is the simplest angle that works (I don't need every solution in $$\mathbb R$$).

Also: While my ideal would be to have Mathematica produce a simple solution, if it could verify or disprove my solution, that would also meet my needs.

# Code below

eq1 = -a r Cos[\[Phi]]==R Cos[\[Psi]]
eq2 = r  Sin[\[Phi]] == R  Sin [\[Psi]]
Solve[eq1 && eq1, {\[Psi], R}]
Solve[eq1 && eq2, {\[Psi], R}]
Reduce[eq1 && eq2, {\[Psi], R}]

• Please post your code as formatted text, not as images, so people can copy / paste it into their own notebook and run it. It should be easy to back-substitute your solution into your equations to see if it's correct though. See e.g. ReplaceAll in the docuemntation. Commented Jan 10 at 17:56
• You have eq1 && eq1 while it should be eq1 && eq2. Commented Jan 10 at 18:02
• @corey979 Thanks! Fixing that, I still don't get something I can parse. Commented Jan 10 at 18:06
• Solve[eq1 && eq2, {\[Psi], R}] // FullSimplify results in {R -> -((r Sqrt[1 + a^2 + (-1 + a^2) Cos[2 \[Phi]]])/Sqrt[2]), \[Psi] -> ConditionalExpression[ArcTan[(a Cos[\[Phi]])/Sqrt[ a^2 Cos[\[Phi]]^2 + Sin[\[Phi]]^2], -(Sin[\[Phi]]/Sqrt[a^2 Cos[\[Phi]]^2 + Sin[\[Phi]]^2])] + 2 \[Pi] ConditionalExpression[1, \[Placeholder]], ConditionalExpression[1, \[Placeholder]] \[Element] Integers]} for one solution and
– JimB
Commented Jan 10 at 18:33
• {R -> (r Sqrt[1 + a^2 + (-1 + a^2) Cos[2 \[Phi]]])/Sqrt[2], \[Psi] -> ConditionalExpression[ ArcTan[-((a Cos[\[Phi]])/Sqrt[a^2 Cos[\[Phi]]^2 + Sin[\[Phi]]^2]), Sin[\[Phi]]/Sqrt[a^2 Cos[\[Phi]]^2 + Sin[\[Phi]]^2]] + 2 \[Pi] ConditionalExpression[1, \[Placeholder]], ConditionalExpression[1, \[Placeholder]] \[Element] Integers]} for the second solution.
– JimB
Commented Jan 10 at 18:34

Here is a bit of code that gives the solution closer to the form we would prefer.

ClearAll["Global*"]
$Version simplify = First[Simplify[#, C[1] ∈ Integers]] &; eqns = -a r Cos[ϕ] == R Cos[ψ] && r Sin[ϕ] == R Sin[ψ]; soln = Solve[eqns, {ψ, R}]; prefer = {R -> Sqrt[R^2 /. soln // simplify], ψ -> ArcTan[Tan[ψ] /. soln // simplify]}  In Wolfram Cloud the code evaluated to Sometimes we must give Mathematica some guidance. What worked this time to get closer to the preferred form was to simplify $$R^2$$ and $$\tan(\psi)$$ then use the Sqrt and the ArcTan to create the desired solution form. In this case I defined a simplify function that provides an assumption (C[1] ∈ Integers) to the plain Simplify and then returns only the First expression in the list returned by Simplify. Edits in response to comment: To verify the hand calc for $$R$$: If we only want to verify that our hand calc is correct, we will look at soln and think maybe something is wrong. But since we are confident in both the hand calc and soln we will try to manipulate soln. One manipulation is to look at $$R^2$$ by evaluating R^2 /. soln. We see that MMA did not multiply it out, so we apply Simplify. We find that Simplify[R^2 /. soln] gives us the some expression as our hand calc, so we're done! To verify the hand calc for $$\psi$$: Similarly for $$\psi$$ we want to manipulate the MMA soln to obtain something we can compare to our hand calc. soln contains ArcTan, so we use Tan to get a simpler expression. We evaluate Tan[ ψ /. soln] and find that it requires further simplification, so we next evaluate Simplify[ Tan[ ψ /. soln] ]. The result matches our hand calc for $$\tan \psi$$, so we're through. Explanation of prefer: Solve gives us the solution(s) as a list of rules that we use with ReplaceAll, the /. operator in further calculation. The variable prefer is a new set of rules, similar to soln, but in the preferred form. prefer is defined by using same manipulations we used to verify the hand calculation. That is, we start with R^2 /. soln, then simplify and take the square root to get an expression for $$R$$. prefer could be used in place of soln in further calculation. Explanation of simplify: We do the same thing for $$\psi$$, but soln contains a ConditionalExpression, which is not unusual with inverse trig functions. We can tell MMA to simplify assuming the constant is an integer, which effectively eliminates the condition. • Wow. Can you explain (or direct me to a resource) how the prefer line works? I don't follow the R -> Sqrt[R^2 /. soln // simplify] expression. How would I use it, e.g., if I wanted to see if$\psi = \arctan (\tan \phi / a)\$ (without the minus sign) also works? Commented Jan 10 at 21:16

A Weierstrass substitution ψ -> 2 ArcTan[uψ] is the way to solve these equations:

eqn = {-a r Cos[ϕ] == R Cos[ψ], r Sin[ϕ] == R Sin[ψ]} /. ψ -> 2 ArcTan[uψ] //TrigExpand

soluψ = Solve[eqn, {R, uψ}];
solψ = soluψ /. uψ -> Tan[ψ/2]
(*{{R -> -r Sqrt[a^2 Cos[ϕ]^2 + Sin[ϕ]^2],
Tan[ψ/2] ->a Cot[ϕ] -Csc[ϕ] Sqrt[a^2 Cos[ϕ]^2 +Sin[ϕ]^2]}
,
{R ->r Sqrt[a^2 Cos[ϕ]^2 + Sin[ϕ]^2],
Tan[ψ/2] ->Csc[ϕ] (a Cos[ϕ] + Sqrt[a^2 Cos[ϕ]^2 +Sin[ϕ]^2])}}*)


Knowing

Tan[x] == (2 Tan[x/2])/(1 - Tan[x/2]^2) // FullSimplify (*True*)


we get

tanψ = (2 Tan[ ψ/2])/(1 - Tan[ ψ/2]^2) /. solψ// FullSimplify
(* {-(Tan[ϕ]/a), -(Tan[ϕ]/a)}*)
`

Hope it helps!