If you see this, something is wrong
First published on Saturday, Feb 21, 2026 and last modified on Saturday, Feb 21, 2026
The Trigonometric Functions
The trigonometric functions need a special package that is NumPy.
To access the functions of Numpy, we have to type 'from numpy import *'.
from numpy import *What are the trigonometric functions in Python? In Python, the trigonometric functions are defined for angles in radians.
The cosine, cos.
cos of zero is one, cos of pi over two is zero, and cos of pi is minus one.
cos(0)cos(pi/2)cos(pi)The sinus is sin.
sin of zero is equal to zero, sin of pi over two is one, and sin of pi is zero.
sin(0)sin(pi/2)sin(pi)And we have also the tangent, tan.
tan of 0 is 0, tan pi over 4 is one, and tan pi over 2 is a very big number, for infinity.
tan(0)tan(pi/4)tan(pi/2)But let's see it in Python.
Launch Anaconda and Spyder and follow me.
You have to type: from numpy import *, so you will have the trigonometric functions.
from numpy import *And then: cos of 0.
It is 1.
cos(0)Cos of 90.
Let's try.
and it is not at all zero.
cos(90)cos of pi over 2.
'pi', pi is also in NumPy package.
And it is very near from zero: it is 10 to the power minus 17.
cos(pi/2)And cos of pi is -1.
cos(pi)Now the sinus.
The sinus of zero is zero.
sin(0)The sinus of pi over two is one.
sin(pi/2)And the sinus of pi is very near from zero.
It is 10 to the power minus 16.
sin(pi)Now the tangent.
The tangent of zero is zero.
tan(0)The tangent of pi over 4 is very near from 1.
tan(pi/4)And the tangent of pi over 2, it is supposed to be the infinity, and it is a very big number, 10 to the power 16.
tan(pi/2)But we shall define more trigonometric functions with the function definition of Python.
The cotangent function will be defined as cotg of x is cos x over sin x.
And we shall also define trigonometric functions for angles in degree, with radians conversion function that converts degrees to radians.
Cosd of x is defined as cos of radians of x.
Sind of x will be defined as sin of radians of x.
Tand of x will be defined as tan of radians of x.
And cotd of x will be defined with the user-defined cotg function, cotg of radians of x.
But let's see how to do it with Python.
Launch Inaconda and Spyder and follow me We shall first define a new file for the editor.
We shall save it.
We define it as Trigonometry.py.
You can navigate to define where to put it.
So I save, 'enregistrer'.
And now we shall define our first Python function.
'def' for define function cotg of x.
cotg is the name of the function, x is the parameter.
Double point very important.
So we have an indentation, and we type just return cos x over sin x. It is a very simple function.
def cotg(x):
return cos(x)/sin(x)But I have forgotten a very important instruction: from numpy import *.
It imports all the elements of NumPy package.
from numpy import *
def cotg(x):
return cos(x)/sin(x)Now we save.
And then we run.
And now we have the cotg function available in the console.
cotg of 0 is infinity.
It is normal.
cotg(0)cotg of pi over four is one, very near from one.
cotg(pi/4)And cotg of pi over two is very near from zero, it is normal as well.
cotg(pi/2)Now we define the functions of trigonometry with angles in degrees.
cosd of x, the cosine for x in degrees, we return, it is the cosine for angles in radians, radians, conversion from degrees to radians, of x.
Now we copy and paste this function to modify it for sinus.
sind is sin of radians of x.
Now we paste again.
We modify it for the tangent.
tand, the tangent for x in degrees.
tan, the tangent for an angle in radians, of radians of x.
And we finish with the cotangent, cotd, cotg, the function that we have defined above.
from numpy import *
def cotg(x):
return cos(x)/sin(x)
def cosd(x):
return cos(radians(x))
def sind(x):
return sin(radians(x))
def tand(x):
return tan(radians(x))
def cotd(x):
return cotg(radians(x))And then, we save and we run.
Now we try our functions, our new functions.
cosd of 90 is very near from zero.
cosd(90)cosd of 180, 180 degrees, is -1, the cosine of the flat angle.
cosd(180)sind of 90 is 1, the sinus of the right angle.
sind(90)sind of 180, the flat angle, is very near from zero.
sind(180)Now tand.
Tand of 45 degrees.
The tangent of 45 degrees is very near from one.
It is supposed to be one.
tand(45)And the tangent of the right angle, 90 degrees, is a very big number.
It is supposed to be infinity.
tand(90)And the cotangent of 45 degrees is very near from one.
cotd(45)And the cotangent of 90 degrees is very near from zero.
cotd(90)What's coming now? What's coming now is the exponent related functions with NumPy package as well.