|
・In Japanese
■Poly1d explanation
poly1d performs polynomial arithmetic.
■Example using poly1d
This requires the numpy and matplotlib libraries.
import numpy as np
import matplotlib.pyplot as plt
x = np.array([-1, -0.8, -0.6, -0.4, -0.2, 0, 0.2, 0.4, 0.6, 0.8, 1])
w = np.array([-2, 3,-0.5]) # Polynomial coefficients
y = np.poly1d(w)(x)
plt.plot(x, y) # Draw a graph
plt.show()
The result is as follows, where "w" is the coefficient of the polynomial, sorted from highest degree to lowest degree. In this case, y = -2x2+3x-0.5.
|
|