while True:

プログラミング演習(備瀬 竜馬)

第5回

小問番号はコメント(#)を参照
# 5_A_1
import math as ma
n0 = input("Input n:")
n = int(n0)
m0 = input("Input m:")
m = int(m0)
value = ma.pow(n, m)
print("{}^{} = {}".format(n, m, value))


# 5_A_2
import math as ma
n0 = input("Input n:")
n = float(n0)
value = ma.fabs(n)
print("絶対値:{}".format(value))


# 5_B_1
import math as ma
x0 = input("Input x:")
x = float(x0)
print("sin(x) = {}".format(ma.sin(x)))
print("cos(x) = {}".format(ma.cos(x)))
print("tan(x) = {}".format(ma.tan(x)))
print("e ^ x = {}".format(ma.exp(x)))
print("loge(x) = {}".format(ma.log(x)))
print("log10(x) = {}".format(ma.log10(x)))
print("平方根(x) = {}".format(ma.sqrt(x)))
print("立方根(x) = {}".format(ma.pow(x, (1 / 3))))


# 5_B_2
x0 = input("Input x:")
x = float(x0)
value1 = pow(x, 3)
value2 = x ** 3
print("pow(x, 3) = {}".format(value1))
print("x ** 3 = {}".format(value2))
if value1 == value2:
print("same!!")


# 5_B_3
import math as ma
from matplotlib import pyplot
x = [i for i in range(1, 11)]
y = [ma.log(k) for k in x]
z = [ma.pow(l, 2) for l in x]
pyplot.plot(x, y, label="y = log(x)")
pyplot.plot(x, z, label="y = x ^ 2")
pyplot.legend()
pyplot.show()


# 5_C_1
import math as ma
rad = ma.pi / 3
r = input("Input n°(r):") # 度数表示
value = float(r)
x = value * ma.cos(rad)
y = value * ma.sin(rad)
print("({},{})".format(x, y))


# 5_C_2
import math as ma
num0 = input("Input angle(x)")
rad = ma.radians(int(num0))
sinx = ma.sin(rad)
cosx = ma.cos(rad)
print("sin(x) = {}".format(sinx))
print("cos(x) = {}".format(cosx))
value = sinx ** 2 + cosx ** 2
print("sin^2(x) + cos^2(x) = {}".format(value))
  
ページのトップへ戻る