4
$\begingroup$

How would you solve a problem like "write csc(x) in terms of sec(x)" in Mathematica? The best I can get is "True."

https://math.stackexchange.com/questions/167935/write-cscx-in-terms-of-secx

I'm asking in order to better understanding of Mathematica, and as a way to verify I'm solving my trig identities correctly. It's been a while since I've done identities, and I'm trying to brush off the cobwebs before its too late. I was told that I'll need this skill later on in Calculus.

$\endgroup$
1
  • 1
    $\begingroup$ Would these help? 1 2 3 4 :) $\endgroup$
    – dearN
    Oct 10, 2012 at 19:07

2 Answers 2

4
$\begingroup$

Just playing tricks:

Cases[Join @@ Solve[{csc == 1/sin, sec == 1/cos, cos cos + sin sin == 1}, {csc, sin, cos}], 
      HoldPattern[csc -> _]]
 (*
  ->{csc -> -(sec/Sqrt[-1 + sec^2]), csc -> sec/Sqrt[-1 + sec^2]}
 *)

Edit

More generally (by using @J.M's suggestion below):

trigExpress[expr_, inTerms_] :=
 Module[
  {set = {sin, cos, tan, sec, csc},
   rels = {csc sin == 1, cos^2 + sin^2 == 1, 1 == cos sec, tan == sin/cos}},
  oneInTermsOf[one_, of_] := Solve[rels, {one}, Complement[set, {one, of}]];
  allIntermsOf[of_] :=       Flatten[oneInTermsOf[#, of] & /@ Complement[set, {of}]];
  Expand@FullSimplify[expr /. allIntermsOf[inTerms]]
  ]

so:

trigExpress[(sin + cos)/tan, sec]
(*
-> 1/sec - 1/(sec Sqrt[-1 + sec^2])
*)
$\endgroup$
5
  • 1
    $\begingroup$ Slightly more compact: Solve[{Csc Sin == 1, Cos^2 + Sin^2 == 1, 1 == Cos Sec}, Csc, {Cos, Sin}] $\endgroup$ Oct 11, 2012 at 0:59
  • $\begingroup$ @J.M. Thanks. Updated with a little more general thing using yours $\endgroup$ Oct 11, 2012 at 13:43
  • $\begingroup$ Hmmm ... probably one should take in account the negative radicals to get the expressions for all quadrants. $\endgroup$ Oct 11, 2012 at 13:46
  • $\begingroup$ @Dr.belisarius -- I've added a new answer to partially address the issues with different quadrants $\endgroup$
    – Simon
    May 19, 2016 at 4:54
  • $\begingroup$ Could anyone help to spell out why Solve[{Csc Sin == 1, Cos^2 + Sin^2 == 1, 1 == Cos Sec}, Csc, {Cos, Sin}] results in solving Csc in terms of Sin? Particularly I am confused with the dom in Solve[expr, vars, dom], and what does "restricts all variables and parameters to belong to the domain dom" mean in the manual, thanks! I would start a new question if this is a valuable question... $\endgroup$
    – Quar
    Feb 12, 2021 at 8:54
1
$\begingroup$

Here's some code that can solve this problem that I wrote a while back for another question.

$TrigFns = {Sin, Cos, Tan, Csc, Sec, Cot};
(WRules = $TrigFns == (Through[$TrigFns[x]] /. x -> 2 ArcTan[t] // 
        TrigExpand // Together) // Thread);

invWRules = #[[1]] -> Solve[#, t, Reals] & /@ WRules;

convert[expr_, (trig : Alternatives @@ $TrigFns)[x_]] := 
 Block[{temp, t}, 
  temp = expr /. x -> 2 ArcTan[t] // TrigExpand // Factor;
  temp = temp /. (trig /. invWRules) // FullSimplify // Union;
  Or @@ temp /. trig -> HoldForm[trig][x] /. ConditionalExpression -> (#1 &)]

In the example provided in the question:

convert[Csc[x], Sec[x]] // ReleaseHold

$$-\frac{\sec (x)}{\sqrt{\sec (x)-1} \sqrt{\sec (x)+1}} \quad \Big|\Big|\quad \frac{\sec (x) \sqrt{\frac{\sec (x)+1}{\sec (x)-1}}}{\sec (x)+1} $$

These solutions cover both quadrants (although the result could be presented in a nicer form).
To check this, let's plot:

Plot[{Csc[x], -(Sec[x]/(Sqrt[-1 + Sec[x]] Sqrt[1 + Sec[x]])), (
  Sec[x] Sqrt[(1 + Sec[x])/(-1 + Sec[x])])/(1 + Sec[x])}, {x, 0, 2 Pi},
 PlotStyle -> {Blue, Dotted, Dashed}]

Plot of Csc rewritten in terms of Sc

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.