LoginSignup
0
2

Pythonでの数学関数の使い方

Last updated at Posted at 2019-10-27

こんにちは、未来電子テクノロジーでインターンをしている者です(2020年1月退社)。
今回は、Pythonでの数学関数の使い方をメモします。

ライブラリのインポート

まずは、mathライブラリをインポートします。

math.py
import math

いろいろな数学関数

次に、様々な数学関数を紹介します。

math.py
import math

print(math.pi)                  #円周率
#3.141592653589793
print(math.sin(0))              #sin
#0.0
print(math.cos(0))              #cos
#1.0
print(math.tan(0))              #tan
#0.0
print(math.asin(0))             #arcsin(sin^-1)
#0.0
print(math.acos(1.0))           #arccos(cos^-1)
#0.0
print(math.atan(1.0))           #arctan(tan^-1)
#0.7853981633974483
print(math.sinh(1.0))           #sinh
#1.1752011936438014
print(math.cosh(1.0))           #cosh
#1.5430806348152437
print(math.tanh(1.0))           #tanh
#0.7615941559557649
print(math.degrees(math.pi))    #弧度法(radian)→度数法(degree)
#180.0
print(math.radians(180.0))      #度数法(degree)→弧度法(radian)
#3.141592653589793
print(math.sqrt(3))             #平方根
#1.7320508075688772
print(math.exp(3))              #ネイピア数(自然対数の底)
#20.085536923187668
print(math.log10(100))          #常用対数
#2.0
print(math.log(100))            #自然対数
#4.605170185988092
print(math.factorial(5))        #階乗(!)
#120                            #5*4*3*2*1

まとめ

今回は、主な数学関数をメモしました。
HackerrankやAtCoderなどで数学の問題を解くときに役立ちそうです。

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2