Skip to content
site-logo
  • Home
  • JavaScript
  • Machine Learning
  • C++Expand
    • C++ Programing
    • Numerical Techniques C++
    • Data Structures C++
    • C++ Programs
  • Typing Guide
  • Blogs
site-logo
Home / Numerical Techniques C++ / Fit a Second Order Polynomial to the given data. Curve fitting Polynomial Regression

Fit a Second Order Polynomial to the given data. Curve fitting Polynomial Regression

ByLonz Updated onAugust 24, 2023
Numerical Techniques C++
polynomial regression
Ad
Table of contents
  1. Polynomial Regression Example
  2. Solution:
    1. 1. Polynomial Regression Formula
    2. 2. Evaluate Formula
    3. 3. Substitute Values
    4. 4. Make Matrix
    5. 5. Use Matrix Elimination
    6. 6. Final Equation
  3. Conclusion

Got data that doesn’t make a straight line? No worries! Polynomial regression helps find the right curve for your numbers.

Let’s learn how to use it for fitting a second-order curve to your data – perfect for spotting trends in a snap.

Ad

Polynomial Regression Example

Let’s say you have the following data points:

x1.02.03.04.0
y6.011.018.027.0
regression table data

Solution:

Let Y = a1 + a2x + a3x2    ( 2nd order polynomial ).

Here, m = 3  ( because to fit a curve we need at least 3 points ).

Since the order of the polynomial is 2, therefore we will have 3 simultaneous equations as below.

1. Polynomial Regression Formula

To learn more, see what is Polynomial Regression

polynomial regression formula

2. Evaluate Formula

Now we have to evaluate the values that are required according to the above equations.

Let us find the value of x2, x3, x4, yx, and yx2.

xyx2x3x4yxyx2
1.06.011166
2.011.049162244
3.018.09168154162
4.027.01636256108432
∑xi=10∑yi=62∑x2=364∑x3=524∑x4=354∑yx=190∑yx2=644
Regression table

3. Substitute Values

Put the values in the above 3 equations as below.

Ad

4a1 + 10a2 + 30a3 = 62   …. ( 1 )

10a1 + 30a2 + 100a3 = 190  …. ( 2 )

30a1 + 100a2 + 354a3 = 644  … ( 3 )

4. Make Matrix

In order to solve the above 3 simultaneous equations, we will write the above equations in the form of matrices as below.

5. Use Matrix Elimination

By using matrix elimination techniques, you can solve for the coefficients a, b, and c.

Fit a Second Order Polynomial to the  following given data.
Fit a Second Order Polynomial
Fit a Second Order Polynomial to the  following given data. Curve fitting Polynomial Regression using gauss elimination method

Now by using back substitution, we can find the values of a1, a2, and a3.

Here, 4a3 = 4 , a3 = 1
And, a2 + 5a3 = 7 , a2 = 2
Also, a1 + 2.5a2 + 7.5a3 = 15.5 , a1 = 3
Therefore, a1 = 3, a2 = 2, a3 = 1.

6. Final Equation

The Quadratic equation becomes: Y = 3 + 2x + x2, or

Sol:- Y = x2 + 2x + 3

This is your second-order polynomial regression equation that closely matches your given data points!

Suggestion:

  1. Newtons Interpolation
  2. Lagrange’s Interpolation
  3. Bisection method
  4. Regula falsi method
  5. Linear Regression

Conclusion

In simple words, polynomial regression helps us find the right curve that fits our data points, even when they don’t play nicely with a straight line.

It’s a bit of math magic that lets us make predictions and understand trends in our data.

Just remember, not every problem needs a fancy high-degree polynomial – sometimes, a simple line works best.

Post navigation

Previous Previous
What is Polynomial Regression & how to derive the Polynomial Regression Formula
NextContinue
Taylor series Formula with Solved Examples | What is Taylor Series
Search

  • Home
  • Privacy Policy
  • Disclaimer
  • Sitemap
  • Write for us
  • Contact Us

Copyright © 2025 TechInDetail

Scroll to top
  • Home
  • JavaScript
  • Machine Learning
  • C++
    • C++ Programing
    • Numerical Techniques C++
    • Data Structures C++
    • C++ Programs
  • Typing Guide
  • Blogs
Search