ISSAC.Min

[Python Basic] 수학 모듈 (Math Module), 수학함수 (Math Function) - 지수와 로그함수 본문

Programming Language/Python Basic

[Python Basic] 수학 모듈 (Math Module), 수학함수 (Math Function) - 지수와 로그함수

ISSAC.M 2020. 11. 24. 17:09
반응형

수학 모듈 (Math Module)

파이썬에는 유용하게 사용할 수 있는 수학 내장 함수(Bulit In Function)이 존재합니다. 하지만 삼각함수, 로그, 쌍곡선, 상수 등과 같은 수학에 관련한 다양한 기능을 제공하지는 않습니다. 그러므로 파이썬에서는 수학 모듈(Math Module)을 제공합니다.

 

수학 모듈에는 다양한 수학 함수(Math Function)을 제공하며 아래와 같습니다.

 

- 수론 및 표현함수

- 지수와 로그함수

- 삼각함수

- 각도 변환

- 쌍곡선 함수

- 특수 함수

- 상수

 

수학 모듈은 수학 내장 함수(Bulit In Function)과 다르게 Math의 Importing 후에 Math.()을 통하여 사용하실 수 있습니다.

 

1
2
3
import math
 
print(math.ceil(1.234))  // print : 2
cs

 

 

 

지수와 로그함수(Power and Logarithmic Functions)

이번 포스팅에서는 지수와 로그함수에 대해서 설명합니다. 수학모듈에서 제공하는 수학함수들은 다음과 같습니다.

 

함수 설명 반환값
math.exp(x) 자연상수인 e의 x 거듭제곱을 반환합니다.   e^x
math.expm1(x) 자연상수인 e의 x 거듭제곱에서 1을 뺀값을 반환합니다. e^x - 1
math.log(x) 진수가 x인 자연로그를 반환합니다. ln(x)
math.log(x,base) 밑을 base, 진수를 x로 가지는 log를 반환합니다. log(x) / log(base)
math.log1p(x) 밑이 e(자연상수)인 x+1의 자연로그를 반환합니다.  ln(1+x)
math.log2(x) 밑이 2인 로그를 반환합니다. log(x) / log(2)
math.log10(x) 밑이 10인 상용로그를 반환합니다. log(x) / log(10)
math.pow(x, y) x의 y 거듭제곱을 반환합니다. x^y
math.sqrt(x) x의 제곱근을 반환합니다. x^(1/2)

 

math.exp(x)

자연상수인 e의 x 거듭제곱을 반환합니다.

자연상수 e = 2.718281... Python 공식 자료에서 일반적으로 math.e ** x나 pow(math.e, x)보다 정확하다고 명시되어있다.

 

(입력)

 

1
2
3
4
5
import math
 
print("math.exp(10) = " + str(math.exp(10)))
print("math.e ** 10 = " + str(math.e ** 10))
print("pow(math.e, 10) = " + str(pow(math.e, 10)))
cs

 

(출력)

 

 

math.expm1(x)

자연상수인 e의 x 거듭제곱에서 1을 뺀값을 반환합니다. 반환값은 float입니다.

 

(입력)

 

1
2
3
4
5
import math
 
print("math.expm1(10) = " + str(math.expm1(10)))
print("math.exp(10) = " + str(math.exp(10)))
print("math.exp(10) - 1 = " + str(math.exp(10- 1))
cs

 

(출력)

 

 

math.log(x)

진수가 x인 자연로그를 반환합니다. 반환값은 float입니다.

 

(입력)

 

1
2
3
4
import math
 
print("math.log(10) = " + str(math.log(10)))
print("math.log(math.e) = " + str(math.log(math.e)))
cs

 

(출력)

 

 

math.log(x, base)

밑이 base, 진수가 x인 로그를 반환합니다. 반환값은 float입니다.

 

(입력)

 

1
2
3
4
5
import math
 
print("math.log(1, 2) = " + str(math.log(12)))
print("math.log(4, 2) = " + str(math.log(42)))
print("math.log(math.e ** 2, math.e) = " + str(math.log(math.e ** 2, math.e)))
cs

 

(출력)

 

 

 

math.log1p(x)

밑이 e(자연상수)인 x+1의 자연로그를 반환합니다. 반환값은 float입니다.

 

(입력)

 

1
2
3
4
import math
 
print("math.log1p(math.e) = " + str(math.log1p(math.e)))
print("math.log(math.e + 1) = " + str(math.log(math.e + 1)))
cs

 

(출력)

 

 

math.log2(x)

밑이 2인 x의 로그를 반환합니다. 반환값은 float입니다.

 

(입력)

 

1
2
3
4
5
import math
 
print("math.log2(2) = " + str(math.log2(2)))
print("math.log2(4) = " + str(math.log2(4)))
print("math.log2(8) = " + str(math.log2(8)))
cs

 

(출력)

 

 

math.log10(x)

밑이 10인 x의 상용로그를 반환합니다. 반환값은 float입니다.

 

(입력)

 

1
2
3
4
5
import math
 
print("math.log10(10 ** 1) = " + str(math.log10(10 ** 1)))
print("math.log10(10 ** 2) = " + str(math.log10(10 ** 2)))
print("math.log10(10 ** 3) = " + str(math.log10(10 ** 3)))
cs

 

(출력)

 

 

math.pow(x, y)

x의 y 거듭제곱을 반환합니다. 반환값은 float입니다.

 

(입력)

 

1
2
3
4
5
import math
 
print("math.pow(2, 3) = " + str(math.pow(23)))
print("math.pow(math.e, 1) = " + str(math.pow(math.e, 1)))
print("math.pow(4, 1/2) = " + str(math.pow(41/2)))
cs

 

(출력)

 

 

math.sqrt(x)

x의 제곱근을 반환합니다. math.pow(x, 1/2), x ** (1/2)와 동일하며 반환값은 float 입니다.

 

(입력)

 

1
2
3
4
5
import math
 
print("math.sqrt(3) = " + str(math.sqrt(3)))
print("math.sqrt(4) = " + str(math.sqrt(4)))
print("math.sqrt(9) = " + str(math.sqrt(9)))
cs

 

(출력)

 

실습

 

 

반응형