プログラム(Python)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# -*- coding: utf-8 import numpy as np import matplotlib.pyplot as plt # yの値 y = np.array([2,3,3.5,4,5,7,8.5,9,10]) # xの値を生成 x = np.linspace(1, len(y), len(y)) A = np.array([x,np.ones(len(x))]) A = A.T a,b = np.linalg.lstsq(A,y)[0] plt.plot(x,y,"ro") plt.plot(x,(a*x+b),"g--") plt.grid() plt.show() |