Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Mathematica implements ArcCot function as an inverse to Cot on range [-Pi/2, Pi/2]. I personally prefer the other definition (as it's used in courses I attend). Is it possible to redefine the function?

Current implementation:

range -Pi/2 to Pi/2

My prefered implementation:

range 0 to Pi

(images taken from http://intmstat.com/blog/2011/04/cotx_2.gif)

share|improve this question
1  
example of redefining a function, utilizing the original: forums.wolfram.com/mathgroup/archive/2013/Sep/msg00006.html –  george2079 Dec 27 '13 at 13:31
    
@george2079 awesome, thanks, this completes the answers below. –  Mikulas Dite Dec 27 '13 at 15:32
add comment

4 Answers 4

up vote 1 down vote accepted

Long comment / warning..

Heres anotherlink:

http://stackoverflow.com/questions/4198961/what-is-in-your-mathematica-tool-bag/5149656#5149656

Which in this case is implemented as:

Unprotect[ArcCot];
ArcCot[args___ ] :=
Block[{$inAcot = True}, Mod[ArcCot[args], Pi]] /; ! TrueQ[$inAcot]
Protect[ArcCot]

And seems to work ..

{ArcCot[1], ArcCot[-1]} -> {Pi/4, 3 Pi /4}

However in some unexpected circumstances we fall back on the original..

GraphicsRow[{
   ListPlot[Table[ {x, ArcCot[ x]} , {x, -5, 5, .2}], Joined -> True], 
   ListPlot[Table[ {x, ArcCot[ x]} , {x, -5, 5, .02}], Joined -> True],
   Plot[ ArcCot[ x], {x, -5, 5}]}, PlotRange -> All]

Table[] uses the new definition in the first case and the original in the second.. go figure.

  First@Table[ {x, ArcCot[ x]} , {x, -1, 0, .01}]  -> {-1., 2.35619}
  First@Table[ {x, ArcCot[ x]} , {x, -1, 0, .001}] -> {-1., -0.785398}

Same results with this:

 Unprotect[ArcCot];
 ArcCot[args___ ] := Pi/2 - ArcTan[args];
 Protect[ArcCot];

( 9.0.0.0 / windows..)

share|improve this answer
1  
Falling back to the original behaviour is most probably due to auto-compilation, which uses the built in functions. This can be circumvented by using an additional Evaluate or in the case of Plot by the option Evaluated->True. –  sebhofer Dec 28 '13 at 14:33
    
@sebhofer confirmed that does fix things. Still you need to wonder where else this issue might show up. –  george2079 Dec 30 '13 at 19:25
    
It's well known that compilation does not use user defined rules for built in functions (at least for some of them, I'm not sure if it's true for all of them). On the other hand I don't think it's surprising that things like this happen when you redefine protected functions. An easy fix is to define your own... –  sebhofer Dec 31 '13 at 9:24
add comment

Just take the result mode Pi?

  myArcCot[n_] := Mod[ArcCot[n], Pi]
  N@myArcCot[-Pi/4]
  (*2.23657007682325*)

And if you want, you can change the definition of ArcCot by removing the read protection on it and redfining it, but I would think making you own wrapper would be more safe.

share|improve this answer
    
Thanks, the issue though is that I can't manage to redefine the original function. Unprotect[ArcCot]; ArcCot[x_] := Mod[ArcCot[x], Pi] does not work for obvious reason. –  Mikulas Dite Dec 26 '13 at 14:49
    
@MikulasDite, sure and that is why I said it is better to make a wrapper around it as I have shown above. –  Nasser Dec 27 '13 at 6:39
add comment

You could use ArcTan[t, 1] instead of ArcCot[t]

share|improve this answer
    
Oh this is so easy it's awesome. Thanks :) –  Mikulas Dite Dec 28 '13 at 14:25
add comment

Another possibility is

Block[{ArcCot = π/2 - ArcTan[#] &}, Plot[ArcCot[x], {x, -10, 10}]]

enter image description here

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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