Matlab tìm ra hàm hồi quy của 1 đường cong bằng thuật toán ‘least squares curve fitting’. The curve used is restricted to polynomials. With the command polyfit any polynomial can be fitted to the data. polyfit (x, y, n)

finds the coefficients of a polynomial of degree n that fits the data (finds the linear relation between x and y).
Let’s start with finding a linear regression of some data:
>> x = 0:10;
>> y = [-.10 .24 1.02 1.58 2.84 2.76 2.99 4.05 4.83 5.22 7.51]
>> p = polyfit (x, y, 1) % find the fitting polynomial of order 1
p = 0.6772 -0.3914
The output of polyfit is a row vector of the polynomial coefficients, the solution of this example is therefore
y = 0.6772x − 0.3914.
Exercise 51.

0 nhận xét:

Cảm nhận Học viên

Matlabthayhai. Powered by Blogger.