Movatterモバイル変換


[0]ホーム

URL:


Python Tutorial

Python cmath.acos() Function



The Pythoncmath.acos() function specifies the arc cosine of an angle, in radius.

The arc cosine of an angle is defined as the inverse of a cosine function. Whereas, the domain of the arc cosine function is in the range [-1,1], and this range is obtained in the form of radians.

Syntax

Following is the syntax for the Pythoncmath.acos() function −

cmath.acos(x)

Parameters

This function contains a numeric value in the range of -1 to 1. If x is greater than 1 or less than -1, then it will generate an error.

Return value

This function returns the arccosine of x in radians.

Example 1

In the below example, we are finding the arc cosine function for the standard values like '0','-1' and '1' usingcmath.acos() function.

import cmathzero = cmath.acos(0)neg_one = cmath.acos(-1)pos_one = cmath.acos(1)print("Arc Cosine value of 0:", cmath.acos(zero))print("Arc Cosine value of -1:", cmath.acos(neg_one))print("Arc Cosine value of 1:", cmath.acos(pos_one))

Output

When we run above program, it produces following result −

Arc Cosine value of 0: 1.0232274785475506jArc Cosine value of -1: 1.8115262724608532jArc Cosine value of 1: (1.5707963267948966+0j)

Example 2

Here,we are passing non-standard cosine ratios as arguments, and then arc cosine values for these objects are calculated usingcmath.acos() function.

import cmathx=cmath.acos(0.76)y=cmath.acos(-0.23)print(x,y)

Output

The result is displayed as follows −

(0.7074832117793429-0j) (1.8028740096576097-0j)

Example 3

In this example, input is not a complex number. So, we will get a TypeError.

import cmathcmath.acos("Welcome to TutorialsPoint")

Output

The output is produced as follows −

Traceback (most recent call last):  File "/home/cg/root/30462/main.py", line 2, in    cmath.acos("Welcome to TutorialsPoint")TypeError: must be real number, not str
python_modules.htm
Print Page
Advertisements

[8]ページ先頭

©2009-2025 Movatter.jp