[Python] [数学][Python 数学]
>>> pow(2,10)
1024
>>> 2 ** 10
1024
- 平方根
>>> math.sqrt(16)
4.0
- n乗根 (指数形式に変換)
>>> math.pow(16, (1.0/2.0))
4.0
- math.log(真数,底)
>>> math.log(1024,2)
10.0
- 自然対数
>>> math.e ** 3 # e の 3乗
20.085536923187664
>>> math.log(20.085536923187664)
3.0
- 常用対数
>>> 10 ** 3 # 10 の 3乗
1000
>>> math.log10(1000)
3.0
- math.fabs は floatで結果を返す
>>> math.fabs(-2)
2.0
>>> abs(-2)
2
>>> abs(-2.0)
2.0
- 1 〜 10 までの和
>>> sum(range(1,11))
55
- 1 〜 10 まで奇数の和
>>> sum(range(1,11,2))
25
>>> math.factorial(5)
120
|
数学 |
Python |
正弦 |
sinθ |
math.sin |
余弦 |
cosθ |
math.cos |
正接 |
tanθ |
math.tan |
逆正弦 |
arcsin |
math.asin |
逆余弦 |
arccos |
math.acos |
逆正接 |
arctan |
math.atan |
度→ ラジアン |
|
math.radians |
ラジアン→ 度 |
|
math.degrees |
- 円周率(π)の値
>>> math.pi
3.1415926535897931
- 30°をラジアンに換算
>>> 30 * math.pi / 180
0.52359877559829882
>>> math.radians(30)
0.52359877559829882
- 60°をラジアンに換算
>>> math.radians(60)
1.0471975511965976
>>> 60 * math.pi / 180
1.0471975511965976
- π/6を度に換算
>>> 180 / 6
30
>>> math.degrees(math.pi / 6)
29.999999999999996
>>> from decimal import Decimal
>>> math.degrees(Decimal(str(math.pi)) / Decimal('6'))
30.000000000001975
- sin 30°の値
>>> math.sin(30.0 / 180.0 * math.pi)
0.49999999999999994
>>> math.sin(Decimal(str(math.pi)) / Decimal('6.0'))
0.50000000000002986
- sinπ/6の値
>>> math.sin(math.pi / 6.0)
0.49999999999999994
- arcsin(1/2)の値
>>> math.asin(1.0 / 2.0)
0.52359877559829893
>>> math.sin(math.asin(1.0 / 2.0))
0.5
- arcsin(1/2)の演算結果を度単位に換算
>>> math.degrees(math.asin(1.0 / 2.0))
30.000000000000004
>>> math.sin(math.radians(30))
0.49999999999999994
- ネイピア数(e)の値
>>> math.e
2.7182818284590451
YAGI Hiroto (piroto@a-net.email.ne.jp)
twitter http://twitter.com/pppiroto
Copyright© 矢木 浩人 All Rights Reserved.