Modeling Algorithm (ix)--fitting

Source: Internet
Author: User

First, the linear least squares 1, the basic idea

, whose R (X) is a previously selected set of linearly unrelated functions. AK is the undetermined factor. Then the criterion of fitting is to make the square and minimum of the distance between Yi and F (xi), called the least squares criterion.

2, the determination of the coefficient

, to make the distance of the square and the smallest, that as long as the acquisition, so that the extremum can be removed, the undetermined coefficient ak, remember

Then the linear equation group is, so when the R column is full rank, R ' r is reversible, so the equations have a unique solution

3. Selection of function R (x)

It is generally intuitive to judge what curve to use. And then there's the usual curve below.

It is generally necessary to do variable substitution to A1 and A2 linear functions.

You can then select a few more R (x), and then choose the sum of squares and the smallest of the distances.

4, MATLAB implementation

(1) Solution equation method

A demo

function ab=zuixiaoerchengfa (x, y)%x , Y is the data point, but the row vector x=x'; Y=y'; R=[ones (5,1), x.^2];ab=r\y;x0= +:0.1: -; y0=ab (1) +ab (2) *x0.^2;p lot (x, Y,'Bo', X0,y0,'R');

(2) polynomial quasi-legal

, and then to fit the given data, then MATLAB consists of the encapsulated function

A=ployfit (X0,Y0,M)

The value y of the polynomial at x can be calculated with this function

Y=polyval (a,x)

Where X0,y0 is the data to fit, M is the number of times to fit the polynomial, and the output parameter A is the coefficient of the fitted polynomial

A demo

>> x0=[1990   1991   1992   1993   19941995  1996]; >> y0=[  122144      174   196  202]; >> plot (x0,y0,'*');

Draw a scatter plot to see how many times the polynomial fit is used

Then it's obvious that you can use straight line fitting so

A=polyfit (X0,y0,1=   1.0e+04 *    0.0021   -4.0705>> y97 =polyval (A,1997=  233.4286>> y98=polyval (A,1998=  253.9286>>
Second, least squares optimization

Iv. the most important ~~~~~~~~~~!!!!!!!!!!!!!!!!

The user interface method of!!!!!!!!!!!! curve fitting

Direct use of command Cftool

Five, curve fitting and function approximation

A demo

int for symbol ∫

The indefinite integral of an int (s) symbol expression S.

an int (s,v) symbol expression s indefinite integral of the variable v.

The definite integral of the int (s,a,b) symbolic expression s, a, B is the lower and upper bound of the integral.

the int (s,v,a,b) symbol expression S is about the definite integral of the variable v from A to B.

When int cannot find the symbolic solution, it automatically turns to the numerical solution.

 syms x  base  =[ 1 , X^2 , X^4  ];y1  =base .  " *base  y2=cos (x) *base .  " r1=int  (y1,-pi/ 2 , Pi/2  )% Calculate integral R2  =int  (Y2,-pi/2 , Pi/2  ) a  =r1\r2xishu1  =double   (a) digits ( 8 ), XISHU2=VPA (a) 

Modeling Algorithm (ix)--fit

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.