8
$\begingroup$

How can I tell Mathematica to evaluate all expressions, plot all functions, solve all equations in degrees, instead of radians?

$\endgroup$
4
  • $\begingroup$ Degree? $\endgroup$
    – corey979
    Commented Dec 21, 2016 at 13:10
  • $\begingroup$ @corey979 what does that mean? $\endgroup$
    – teed
    Commented Dec 21, 2016 at 13:11
  • 1
    $\begingroup$ @corey979 i mean like the option in scientific calculators. $\endgroup$
    – teed
    Commented Dec 21, 2016 at 13:13
  • $\begingroup$ So, you want the result of D[Sin[x], x] to be π Cos[x]/180? In the meantime: Plot[Sin[x °], {x, 0, 360}]. $\endgroup$ Commented Dec 21, 2016 at 13:17

2 Answers 2

13
$\begingroup$

Possibly a bad idea for the reasons mentioned in previous messages, but you could do something like the following:

SetAttributes[trigMode, HoldAllComplete];
trigMode[expr_] := 
 Unevaluated[expr] /. 
    {(f : ArcSin | ArcCos | ArcTan | ArcCot | ArcSec | ArcCsc)[x_] :> 180 f[x]/π,
     (f : Sin | Cos | Tan | Cot | Sec | Csc)[x_] :> f[x °]};

$Pre = trigMode;

Sin[90]
(* 1 *)

ArcSin[Sqrt[3]/2]
(* 60 *)

Plot[Sin[x], {x, 0, 360}]

sine in degrees

I used $Pre to make sure my function trigMode is applied to every input expression. It was important that the function has the attribute HoldAllComplete (so it doesn't evaluate on me and therefore ArcSin[Sqrt[3]/2] doesn't get transformed to π/3 before I have a chance to catch it and apply a transformation rule). trigMode uses some pattern matching to find parts of the expression that contain "trig functions" and makes sure they get treated like a calculator in "degree mode" would.

When you want to go back to the standard mode, use $Pre = . to clear.

$\endgroup$
4
  • $\begingroup$ @Mr.Wizard sure thing. $\endgroup$
    – chuy
    Commented Dec 21, 2016 at 22:15
  • $\begingroup$ Done. Please check that I did not break anything! $\endgroup$
    – Mr.Wizard
    Commented Dec 21, 2016 at 22:17
  • $\begingroup$ @Mr.Wizard looks good to me. I knew MemberQ was a bad idea. $\endgroup$
    – chuy
    Commented Dec 21, 2016 at 22:19
  • $\begingroup$ I've added the three other pairs of trig functions; it might be sufficient for students. $\endgroup$ Commented Dec 22, 2016 at 1:52
3
$\begingroup$
Sin[60 Degree]

$\frac{\sqrt{3}}{2}$

Plot[Sin[alpha Degree], {alpha, 0, 360}]

enter image description here

ToDeg[rad_] := N[rad/Degree];
FromDeg[deg_] := N[Degree deg];

ToDeg[ArcSin[Sqrt[3]/2]]
60.

See also: https://stackoverflow.com/questions/8313489/set-degrees-as-default-in-mathematica-8

$\endgroup$
11
  • $\begingroup$ Isn't there a feature to set it in degrees without putting Degree after the angle so that when I input ArcSin[Sqrt[3]/2], the answer will be 60? $\endgroup$
    – teed
    Commented Dec 21, 2016 at 13:23
  • 1
    $\begingroup$ I doubt that. Consider ArcSin[2.] - how do you want to express complex numbers in degrees? $\endgroup$
    – corey979
    Commented Dec 21, 2016 at 13:27
  • $\begingroup$ @corey: I agree, and additionally, should Exp[180 I] be -1, in such a case? $\endgroup$ Commented Dec 21, 2016 at 13:29
  • $\begingroup$ @Teokan Duran Demircan: see above $\endgroup$
    – mrz
    Commented Dec 21, 2016 at 13:30
  • $\begingroup$ Or try with UnitConvert. $\endgroup$
    – corey979
    Commented Dec 21, 2016 at 13:31

Your Answer

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

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