Curve Fitting in MATLAB

Source: Internet
Author: User

Curve Fitting in MATLAB



In Matlab, The polyfit function can be used for fitting curves. This method is called polynomial fitting:


Polynomial fitting:

X = 0: 0.; y = [-0.447 1.978 3.28 6.16 7.08 7.34 7.66 9.56 9.48 9.30]; A = polyfit (X, Y, 2 ); % use quadratic polynomial curves to fit z = polyval (A, x); plot (X, Y, 'r * ', X, Z,' B ');

Note:

(X, y) In A = polyfit (X, Y, n) indicates the data coordinate to be fitted, N indicates the degree of the fit polynomial (when n is greater than or equal to the number of data to be fitted, it will always be completely fit), and the returned a indicates the coefficient of the fit polynomial, that is, a =, the fitted polynomial f (x) satisfies the following requirements: Therefore, the number of elements of a is equal to n + 1.

Z = polyval (A, x) indicates that the Y value corresponding to X is calculated based on the fitted polynomial f (x) of the coefficient matrix.


The result is as follows:





MATLAB also provides a graphic window-based fitting operation, which is very intuitive and convenient:

1. Enter the following statement:

x=0:0.1:1;y=[-0.447 1.978 3.28 6.16 7.08 7.34 7.66 9.56 9.48 9.30 11.2];plot(x, y, 'r*');

2. Open tools --> basic fitting in the figure graph window. You can set the fitting curve in the pop-up window to display the fitting curve equation, calculation of residual and other information.


3. Press the right arrow to see the equation of the fitting curve, and then press the right arrow to enter X to calculate the Y value corresponding to the fitting curve, or save these values to the workspace.




Note: residual = exact value-fitting value

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.