#!/usr/bin/env python # coding: utf-8 # ## Görbeillesztés # Generáljunk zajos jeleket: # In[4]: import numpy as np import matplotlib.pylab as plt get_ipython().run_line_magic('matplotlib', 'inline') # generáljunk zajos jeleket x = np.arange(1000) y = 0.000321 * x**2 + 20*np.random.randn(len(x)) plt.plot(x, y, 'k.', linewidth = 5) plt.show() # Illesszünk görbét, majd jelenítsük meg. # In[6]: # illesszünk görbét M = np.column_stack((x**2,)) # construct design matrix k, _, _, _ = np.linalg.lstsq(M, y, rcond=None) # least-square fit of M * k = y # jelenítsük meg plt.plot(x, y, 'k.', x, k*x**2, 'r', linewidth = 5) plt.legend(('measurement', 'fit'), loc=2) plt.title('best fit: y = {:.8f} * x**2'.format(k[0])) plt.show()