# How to graph the inverse trigonometric function (arctan, arccotan) in asymptote?

A want to add the inverse trig.function for tangens to the code of asymptote. Thank you for adivise.

``````settings.outformat="pdf";
unitsize(2.5cm);
import graph;

real xmin = -pi/2;
real xmax = pi/2;
real ymin = -pi/2;
real ymax = pi/2;

xlimits(xmin,xmax);
ylimits(ymin,ymax);

//axis and the grid :

xaxis(Label("\$x\$",align=2E),Ticks("\$%.2f\$",new real[]{xmin,-1,1,xmax},Size=1mm,1bp),Arrow);
yaxis(Label("\$y\$",align=2N),Ticks("\$%.2f\$",new real[]{xmin,-1,1,xmax},Size=1mm,1bp),Arrow);

// function y=sin(x)
real f(real x) {return sin(x)/cos(x); }
path g = graph(f,xmin+0.5, xmax-0.5);
draw(g,red,
L= Label("\$y=tan(x)\$", UnFill,
position=EndPoint));

// function y=x
draw((xmin-0.25,ymin-0.25)--(xmax+0.25,ymax+0.25),
L= Label("\$y=x\$", UnFill,position=EndPoint));
``````

• What is your desired image?
– user213378
Commented Oct 13, 2020 at 14:34
• `atan` for arctangent in radians, `aTan` for degrees. See asymptote.sourceforge.io/doc/…. You can compute arccotan from arctan. Commented Oct 13, 2020 at 16:49
• Welcome to TeX.SE! Commented Oct 14, 2020 at 14:33
• The graph and its inverse are symmetric to the bisector `y=x`, so one way is rotate it to x-axis, reflex to y-axis, then rotate back, and we get the graph of the inverse. This way `rotate(45)*yscale(-1)*rotate(-45)` works for any curve. `// http://asymptote.ualberta.ca/ unitsize(1cm); import graph; import math; axes("\$x\$","\$y\$"); drawline((0,0),(1,1),gray+.3pt); real dx=.35; path g = graph(tan,-pi/2+dx, pi/2-dx); draw(g,red); draw(rotate(45)*yscale(-1)*rotate(-45)*g,blue);` Commented Jan 29, 2021 at 15:04

The general idea for drawing an inverse is to plot `(f(x),x)` in some manner. With the cotangent of your image, that would mean changing your code to

``````real xmin = 0;
real xmax = pi;
real ymin = -pi/2;
real ymax = pi/2;
...
real f(real x) {return cos(x)/sin(x); }
``````

and then adding at the end:

``````pair h(real t) { return (f(t),t); }
path j = graph(h,xmin+0.3,xmax-0.3);
draw(j,blue,L=Label("\$y=cotg^{-1}(x)\$", UnFill,
position=EndPoint));
``````

Resulting in: