Results 1 to 9 of 9

Math Help - Curve fitting nonlinear polynomial

  1. #1
    Newbie
    Joined
    Sep 2011
    Posts
    4

    Curve fitting nonlinear polynomial

    Hello,

    Sorry to say but I studied this in class 20 years ago. Now it is gone. So I need help here.

    I have 5-10 data points that I want to approximate a nonlinear polynominal to. I need to write the solution in excel, in the visual basic editor, meaning I want to use an iterative approach and not a "inverse matrix" solution. Can someone please help me here.

    Ex)

    x=2012, 2013, 2014, 2015, 2016
    y= 5937, 5343, 4310, 3887, 0

    Preferably, I want to have zero error at the boundaries but if the difference between the total least square error for "zero boundrary solution" and "without zero boundary error constraint" is too big I can skip the boundary conditions.

    Would approciate if solution is written in a form that it is easy to see how I can code it in VB, flow chart maybe.....

    Thanks in advance from an "old" student that has not been able to remember this knowledge 20 years later.....

    /sbe
    Follow Math Help Forum on Facebook and Google+

  2. #2
    MHF Contributor
    Prove It's Avatar
    Joined
    Aug 2008
    Posts
    11,560
    Thanks
    1425

    Re: Curve fitting nonlinear polynomial

    Quote Originally Posted by sbe70 View Post
    Hello,

    Sorry to say but I studied this in class 20 years ago. Now it is gone. So I need help here.

    I have 5-10 data points that I want to approximate a nonlinear polynominal to. I need to write the solution in excel, in the visual basic editor, meaning I want to use an iterative approach and not a "inverse matrix" solution. Can someone please help me here.

    Ex)

    x=2012, 2013, 2014, 2015, 2016
    y= 5937, 5343, 4310, 3887, 0

    Preferably, I want to have zero error at the boundaries but if the difference between the total least square error for "zero boundrary solution" and "without zero boundary error constraint" is too big I can skip the boundary conditions.

    Would approciate if solution is written in a form that it is easy to see how I can code it in VB, flow chart maybe.....

    Thanks in advance from an "old" student that has not been able to remember this knowledge 20 years later.....

    /sbe
    That depends... Do you want a curve that fits all the points exactly? If so you will need a quartic. Otherwise you can do a lest squares quadratic or cubic...
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Newbie
    Joined
    Sep 2011
    Posts
    4

    Re: Curve fitting nonlinear polynomial

    Hi,

    Thanks for the quick reply.

    No, I will seldom get an exact match since the data points will vary a lot. I want to be able to change the order of the polynomial if necessary.

    I have been trying to use least square approach but everything on the internet has inverse matrix examples. I can not use that approach since the inverse sometime does not work, the matrix has no inverse.

    Would be very grateful if you could help out. it is urgent to the stress level is not good

    /sbe
    Follow Math Help Forum on Facebook and Google+

  4. #4
    MHF Contributor
    Prove It's Avatar
    Joined
    Aug 2008
    Posts
    11,560
    Thanks
    1425

    Re: Curve fitting nonlinear polynomial

    Quote Originally Posted by sbe70 View Post
    Hi,

    Thanks for the quick reply.

    No, I will seldom get an exact match since the data points will vary a lot. I want to be able to change the order of the polynomial if necessary.

    I have been trying to use least square approach but everything on the internet has inverse matrix examples. I can not use that approach since the inverse sometime does not work, the matrix has no inverse.

    Would be very grateful if you could help out. it is urgent to the stress level is not good

    /sbe
    Maybe the reason your system of equations isn't giving you an inverse matrix is because the matrix isn't square when you aren't fitting the polynomial exactly. The first step to getting a least-square solution is to first premultiply both sides by the transpose. This creates a square matrix, which will probably have an inverse.
    Follow Math Help Forum on Facebook and Google+

  5. #5
    Newbie
    Joined
    Sep 2011
    Posts
    4

    Re: Curve fitting nonlinear polynomial

    As I understand it there does not always exists an inverse even for a square matrix. If I am wrong I need to find a way to code the inverse of a matrix. Before I need to determine the polynomial order based on number of data points. How do I do that?
    Follow Math Help Forum on Facebook and Google+

  6. #6
    MHF Contributor
    Prove It's Avatar
    Joined
    Aug 2008
    Posts
    11,560
    Thanks
    1425

    Re: Curve fitting nonlinear polynomial

    Quote Originally Posted by sbe70 View Post
    As I understand it there does not always exists an inverse even for a square matrix. If I am wrong I need to find a way to code the inverse of a matrix. Before I need to determine the polynomial order based on number of data points. How do I do that?
    1. CHOOSE the order of the polynomial you want. In this case, you can only have up to a quartic.
    2. Write your system of equations that you get from the data points.
    3. Write this system in matrix form \displaystyle \mathbf{A}\mathbf{x} = \mathbf{b}.
    4. Premultiply both sides by the transpose of \displaystyle \mathbf{A}, in other words, you should get \displaystyle \mathbf{A}^T\mathbf{A}\mathbf{x} = \mathbf{A}^T\mathbf{b}. The matrix \displaystyle \mathbf{A}^T\mathbf{A} is now square.
    5. IF the inverse of \displaystyle \mathbf{A}^T\mathbf{A} exists, premultiply both sides of the equation by it.
    In other words \displaystyle \mathbf{x} = \left(\mathbf{A}^T\mathbf{A}\right)^{-1}\mathbf{A}^T\mathbf{A}\mathbf{b}.
    Follow Math Help Forum on Facebook and Google+

  7. #7
    Newbie
    Joined
    Sep 2011
    Posts
    4

    Re: Curve fitting nonlinear polynomial

    I have a problem if the inverse does not exist. What do I do then? That is why I prefer a numerical method before a matrix approach. Do you have an idea for an numerical approach?
    Follow Math Help Forum on Facebook and Google+

  8. #8
    MHF Contributor
    Prove It's Avatar
    Joined
    Aug 2008
    Posts
    11,560
    Thanks
    1425

    Re: Curve fitting nonlinear polynomial

    Quote Originally Posted by sbe70 View Post
    I have a problem if the inverse does not exist. What do I do then? That is why I prefer a numerical method before a matrix approach. Do you have an idea for an numerical approach?
    Chances are the inverse will exist.
    Follow Math Help Forum on Facebook and Google+

  9. #9
    Newbie
    Joined
    Nov 2012
    From
    USA,New Jersey,Newark
    Posts
    1

    Re: Curve fitting nonlinear polynomial

    Hello Prove It, and sbe70,
    I have a similar problem. However I want to curve fit 3 points exactly resulting in some y=f(x) formula I can use to get any other point.
    My sample data is x=1,120,2304 and y=1,145,210. I am actually more concerned with the middle data, and less so with the extremes.
    I'm looking for a curve something like y = c * ln(x) + Y but that is just to get an idea: it does not have to involve ln(x).
    Apparently Excel uses the least squares method for curve fitting, but when I selected a 2nd degree polynomial form for these 3 points I got the St. Louis Arch !
    I guess then my last criterion would be a curve fitting method which also results in some miniumum area under the curve.
    Thanks, Mike
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Nonlinear Fitting
    Posted in the Advanced Applied Math Forum
    Replies: 7
    Last Post: July 4th 2011, 12:40 PM
  2. Curve Fitting
    Posted in the Calculus Forum
    Replies: 8
    Last Post: September 15th 2010, 02:09 PM
  3. Polynomial Curve Fitting, Matrices
    Posted in the Advanced Algebra Forum
    Replies: 2
    Last Post: February 6th 2010, 05:13 AM
  4. [SOLVED] Polynomial Curve Fitting
    Posted in the Advanced Algebra Forum
    Replies: 4
    Last Post: September 6th 2009, 10:43 AM
  5. Help with nonlinear regression / curve fitting
    Posted in the Advanced Statistics Forum
    Replies: 17
    Last Post: June 6th 2007, 10:48 PM

Search Tags


/mathhelpforum @mathhelpforum