Jupyter を使ってやってみます。
べき乗
$y=x^5$
import numpy as np
import matplotlib.pyplot as plt
def exponentiation(x):
a = 5
return x**a # xのa乗
x = np.linspace(0, 10)
y = exponentiation(x) # y = f(x)
plt.plot(x, y)
plt.xlabel("x", size=14)
plt.ylabel("y", size=14)
plt.grid()
plt.show()
平方根
$y=\sqrt x$
import numpy as np
import matplotlib.pyplot as plt
def square_root(x):
return np.sqrt(x) # xの正の平方根
x = np.linspace(0, 100)
y = square_root(x) # y = f(x)
plt.plot(x, y)
plt.xlabel("x", size=14)
plt.ylabel("y", size=14)
plt.grid()
plt.show()
多項式
$y=4x^3+3x^2+2x+1$
import numpy as np
import matplotlib.pyplot as plt
def polynomial(x):
return 4*x**3 + 3*x**2 + 2*x +1
x = np.linspace(-10, 10)
y = polynomial(x) # y = f(x)
plt.plot(x, y)
plt.xlabel("x", size=14)
plt.ylabel("y", size=14)
plt.grid()
plt.show()
三角関数
$y=\sin x$
$y=\cos x$
$y=\tan x$
import numpy as np
import matplotlib.pyplot as plt
def sin(x):
return np.sin(x) # sin(x)
def cos(x):
return np.cos(x) # cos(x)
def tan(x):
return np.tan(x) # tan(x)
x = np.linspace(-2*np.pi, 2*np.pi) # xの範囲を指定
y_sin = sin(x)
y_cos = cos(x)
y_tan = tan(x)/np.pi/10
plt.plot(x, y_sin, label="sin")
plt.plot(x, y_cos, label="cos")
plt.plot(x, y_tan, label="tan")
plt.legend()
plt.xlabel("x", size=14)
plt.ylabel("y", size=14)
plt.grid()
plt.show()