logo

파이썬 | math.cos() 함수

Python에서 수학 모듈에는 모듈을 사용하여 쉽게 수행할 수 있는 여러 가지 수학 연산이 포함되어 있습니다. math.cos()>함수는 인수로 전달된 값의 코사인을 반환합니다. 이 함수에 전달된 값은 라디안 단위여야 합니다.

통사론: 수학.cos(x)

매개변수:
x : cos()에 전달할 값



보고: 인수로 전달된 값의 코사인을 반환합니다.

코드 #1:


자바테이블



# Python code to demonstrate the working of cos()> > # importing 'math' for mathematical operations> import> math> > a>=> math.pi>/> 6> > # returning the value of cosine of pi / 6> print> (>'The value of cosine of pi / 6 is : '>, end>=>'')> print> (math.cos(a))>

>

>

산출:

 The value of cosine of pi/6 is : 0.8660254037844387>


코드 #2:




문자를 int로 자바
# Python program showing> # Graphical representation of> # cos() function> import> math> import> numpy as np> import> matplotlib.pyplot as plt> > in_array>=> np.linspace(>->(>2> *> np.pi),>2> *> np.pi,>20>)> > out_array>=> []> > for> i>in> range>(>len>(in_array)):> >out_array.append(math.cos(in_array[i]))> >i>+>=> 1> > > print>(>'in_array : '>, in_array)> print>(>' out_array : '>, out_array)> > # red for numpy.sin()> plt.plot(in_array, out_array, color>=> 'red'>, marker>=> 'o'>)> plt.title(>'math.cos()'>)> plt.xlabel(>'X'>)> plt.ylabel(>'Y'>)> plt.show()>

>

>

산출:

in_array : [-6.28318531 -5.62179738 -4.96040945 -4.29902153 -3.6376336 -2.97624567
-2.31485774 -1.65346982 -0.99208189 -0.33069396 0.33069396 0.99208189
1.65346982 2.31485774 2.97624567 3.6376336 4.29902153 4.96040945
5.62179738 6.28318531]

out_array : [1.0, 0.7891405093963934, 0.2454854871407988, -0.40169542465296987, -0.8794737512064891, -0.9863613034027223, -0.677281571 6257412, -0.08257934547233249, 0.5469481581224268, 0.9458172417006346, 0.9458172417006346, 0.5469481581224268, -0.082579345472 3316, -0.6772815716257405, -0.9863613034027223, -0.8794737512064893, -0.40169542465296987, 0.2454854871407988, 0.789140509396393 4 , 1.0]