파이썬 cmath.isclose() 메서드
예시
두 복소수 값의 근접도를 비교합니다.
#Import cmath Library
import cmath
#compare the closeness of two
complex values using relative tolerance
print(cmath.isclose(10+5j,
10+5j))
print(cmath.isclose(10+5j, 10.01+5j))
정의 및 사용
이 cmath.isclose()
메서드는 두 개의 복소수 값이 가까운지 여부를 확인합니다. 이 메서드는 부울 값을 반환합니다. True
값이 가까우면 False
.
이 방법은 상대 허용오차 또는 절대 허용오차를 사용하여 값이 가까운지 확인합니다.
팁: 다음 공식을 사용하여 값을 비교합니다.
abs(ab) <= max(rel_tol * max(abs(a), abs(b)), abs_tol)
통사론
cmath.isclose(a, b, rel_tol = value, abs_tol = value)
매개변수 값
Parameter | Description |
---|---|
a | Required. The first value to check for closeness |
b | Required. The second value to check for closeness |
rel_tol = value | Optional. The relative tolerance. It is the maximum allowed difference between value a and b. Default value is 1e-09 |
abs_tol = value | Optional. The minimum absolute tolerance. It is used to compare values near 0. The value must be at least 0 |
기술적 세부 사항
반환 값: | 값 bool . True 값이 가까우면 그렇지 않으면False |
---|---|
파이썬 버전: | 3.5 |
더 많은 예
예시
절대 허용 오차가 정의된 두 개의 복소수 값의 근접도를 비교합니다.
#Import cmath Library
import cmath
#compare the closeness of two
complex values using absolute tolerance
print(cmath.isclose(10+5j, 10+5j,
abs_tol=0.005))
print(cmath.isclose(10+5j, 10.01+5j, abs_tol=0.005))