cmath常用函数示例
时间: 2023-10-26 20:07:15 浏览: 56
下面是一些常用的 `cmath` 函数及其示例:
1. `sqrt()`:计算平方根
```python
import cmath
x = 4
print(cmath.sqrt(x)) # 输出: (2+0j)
```
2. `exp()`:计算 e 的幂次方
```python
import cmath
x = 2
print(cmath.exp(x)) # 输出: (7.3890560989306495+0j)
```
3. `log()`:计算自然对数
```python
import cmath
x = 10
print(cmath.log(x)) # 输出: (2.302585092994046+0j)
```
4. `sin()`:计算正弦值
```python
import cmath
x = cmath.pi/2
print(cmath.sin(x)) # 输出: (1+0j)
```
5. `cos()`:计算余弦值
```python
import cmath
x = cmath.pi
print(cmath.cos(x)) # 输出: (-1+0j)
```
6. `tan()`:计算正切值
```python
import cmath
x = cmath.pi/4
print(cmath.tan(x)) # 输出: (0.9999999999999999+0j)
```
7. `asin()`:计算反正弦值
```python
import cmath
x = 1
print(cmath.asin(x)) # 输出: (1.5707963267948966j)
```
8. `acos()`:计算反余弦值
```python
import cmath
x = 0
print(cmath.acos(x)) # 输出: (1.5707963267948966+0j)
```
9. `atan()`:计算反正切值
```python
import cmath
x = 1
print(cmath.atan(x)) # 输出: (0.7853981633974483+0j)
```
注意:以上示例中,输出的结果是一个复数,其中实部表示函数计算的结果,虚部为 0。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)