3
$\begingroup$

I have the equation: $A \sin x + B \cos[x] = 0$ that should be satisfied for all the $x$. Of course, the solution is obvious: $A=B=0$, but I need Mathematica to resolve it automatically because this is a part of a bigger code.

I have tried SolveAlways, ForAll, Reduce and Resolve functions and nothing works.

 eq = A Cos[x] + B Sin[x] == 0

 SolveAlways[eq, x]
 SolveAlways::ifun: Inverse functions are being used by SolveAlways, so some solutions may not be found; use Reduce for complete solution information.
 {{}, {B -> 0}}

 Reduce[ForAll[x, eq], {A, B}]
 Reduce::nsmet: This system cannot be solved with the methods available to Reduce

Actually Reduce[eq, {A, B}] gives the results and the needed result of {A->0,B->0} is there, however, there are other expressions, that I do not need (with the dependence of $A$ and $B$ on $x$).

I wonder, if it is a robust way to handle this simple problem?

$\endgroup$
  • $\begingroup$ SolveAlways[Reduce[eq,{A,B}],x] $\endgroup$ – Marius Ladegård Meyer Feb 5 '15 at 6:50
  • $\begingroup$ This could be a solution, however, if eq is a big system of equations the Reduce function will fail before SolveAlways will have a chance to filter the results out. $\endgroup$ – galadog Feb 5 '15 at 7:14
  • $\begingroup$ Reduce will only rewrite the set of equations right, it won't solve anything. I don't think it will be a problem, unless you have an example? $\endgroup$ – Marius Ladegård Meyer Feb 5 '15 at 7:33
6
$\begingroup$

One approach (that works for this simple problem) is to make the substitutions $\cos(x)\rightarrow u \in \mathbb{R}$ and $\sin(x)\rightarrow v \in \mathbb{R}$ with the additional constraint that $u^2+v^2=1$. This approach transforms the transcedental equation to a polynomial (actually, linear) one, and MMA has no problem providing the answer:

Resolve[ForAll[{u, v}, Element[{u, v, A, B}, Reals] && u^2 + v^2 == 1,
   A*u + B*v == 0]]

A == 0 && B == 0

$\endgroup$
7
$\begingroup$

Since it's triangle functions, I'll try Fourier transformation:

FourierCoefficient[#, x, n] & /@ (A Sin[x] + B Cos[x] == 0)
Reduce[ForAll[{n}, %], {A, B}]

conditions on Fourier coefficients

A == 0 && B == 0
$\endgroup$
5
$\begingroup$

in inverse kinematics, this sort of thing is done all the time. There are general analytical formulas used in solving the inverse kinematics, and one of this is the one asked here. The solution is always to use atan2. So the solution for this problem, as given in the text book, is, given $a\cos(\theta)+b\sin(\theta)=c$ then $$ \theta = {\rm atan2}\left(\frac{b}{a}\right)+ {\rm atan2}\left(\frac{\pm\sqrt{a^2+b^2-c^2}}{c}\right) $$

reference: Page 110, Robotics, basic analysis and design, by William A. Wolovich

Mathematica graphics

ps. in Mathematica, atan2(y/x) is implemented as ArcTan[x,y] so watch out.

$\endgroup$

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.