Change language

# Python | math.cos () function

In Python, a math module contains a number of math operations that can be easily accomplished using the module. `math.cos() ` returns the cosine of the value passed as an argument. The value passed to this function must be in radians.

Syntax: math.cos (x)

Parameter:
x: value to be passed to cos ()

Returns: Returns the cosine of value passed as argument

Code # 1:

 ` # Python code to demonstrate how cos () works `   ` # import & quot; math & quot; for math operations ` ` import ` ` math `   ` a ` ` = ` ` math.pi ` ` / ` ` 6 `   ` # returns the cosine of pi / 6 ` ` print ` ` (` ` "The value of cosine of pi / 6 is:" ` `, end ` ` = ` ` "") ` ` print ` ` (math.cos (a)) `

Output:

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

Code # 2:

 ` # Show Python program ` ` # Graphical view ` ` # 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_arra y) `   ` # 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 () `

Exit:

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.6772815716257412, -0.08257934547233249, 0.5469481581224268, 0.9458172417006346, 0.9458172417006346, 0.5469481581224268, -0.0825793454723316, -0.6772815716257405, -0.9863613034027223, -0.8794737512064893, -0.40169542465296987, 0.2454854871407988, 0.789140509ques> ssobcode.topages = ` .jpg "/> `

``` ```
``` ```
``` (adsbygoogle = window.adsbygoogle || []).push({}); Shop Learn programming in R: courses\$FREE Best Python online courses for 2022\$FREE Best laptop for Fortnite\$399+ Best laptop for Excel\$ Best laptop for Solidworks\$399+ Best laptop for Roblox\$399+ Best computer for crypto mining\$499+ Best laptop for Sims 4\$ (adsbygoogle = window.adsbygoogle || []).push({}); Latest questions PythonStackOverflow Common xlabel/ylabel for matplotlib subplots 1947 answers PythonStackOverflow Check if one list is a subset of another in Python 1173 answers PythonStackOverflow How to specify multiple return types using type-hints 1002 answers PythonStackOverflow Printing words vertically in Python 909 answers PythonStackOverflow Python Extract words from a given string 798 answers PythonStackOverflow Why do I get "Pickle - EOFError: Ran out of input" reading an empty file? 606 answers PythonStackOverflow Python os.path.join () method 384 answers PythonStackOverflow Flake8: Ignore specific warning for entire file 360 answers All questions (adsbygoogle = window.adsbygoogle || []).push({}); ```
``` ```
``` ```
``` News 02/02/2023 AMD along with Nvidia deliberately delays CPU and GPU shipments to keep prices high 01/02/2023 Marshall introduced the Middleton portable Bluetooth speaker with 360-degree sound and IP67 water protection 01/02/2023 OpenAI released a tool to detect AI-generated text Wiki Python functions Python | How to copy data from one Excel sheet to another __main__ Python module Common xlabel/ylabel for matplotlib subplots ast Python module Check if one list is a subset of another in Python code Python module How to specify multiple return types using type-hints __main__ Python module Printing words vertically in Python code Python module Python Extract words from a given string Python functions Cyclic redundancy check in Python Python functions Finding mean, median, mode in Python without libraries ast Python module Python add suffix / add prefix to strings in a list ast Python module Why do I get "Pickle - EOFError: Ran out of input" reading an empty file? Python functions Python - Move item to the end of the list Python functions Python - Print list vertically © 2017—2023 Python Engineering Hub EN | ES | DE | FR | IT | RU | TR | PL | PT | JP | KR | CN | HI | NL Python.Engineering is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to amazon.com Python Loops Counters NumPy NLP Regular Expressions Wiki Tech news Python Wiki StackOverflow PHP JavaScript Books All books Computations Development Cryptography For dummies Big Data document.addEventListener("DOMContentLoaded", () => { let arrayCode = document.querySelectorAll('pre'); arrayCode.forEach(element => { element.classList.add("prettyprint"); }); }); window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'G-Q022WLXW4X'); ```