+ Reply to Thread
Results 1 to 19 of 19

Curve fitting with formulas

  1. #1
    Registered User
    Join Date
    11-09-2006
    MS-Off Ver
    Excel 2010 64 bit
    Posts
    200

    Curve fitting with formulas

    Hello Friends,
    I wanted to ask if it is possible to replicate the nice smooth curves but with the formulas??? I need to approximate a rather jittery line to create a similar looking but very curvy curve - like Excel does in polynomial curves when adding the trend-line on the chart? How this can be done with the formulas apart from copying the equation from the charts polynomial trend line- not practical for me as the original lines will be updated constantly.
    any help hugely appreciated!

  2. #2
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: Curve fitting with formulas

    Hi there.

    A picture is worth 1,000 words. An Excel sheet is worth 1,000 pictures.

    Please read the yellow banner about sample worksheets, at the top of the screen. Act on its guidelines and post a SMALL sample sheet.
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU

  3. #3
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,428

    Re: Curve fitting with formulas

    Polynomials are "linear" functions and linear least squares regressions can be performed using the LINEST() function https://support.microsoft.com/en-us/...a-fa7abf772b6d You can also implement non-linear regressions in Excel, if your data requires a non-linear model. You have not provided any details, but the short answer to your question is, Yes, you can do curve fitting and/or data smoothing in Excel and other spreadsheets/
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  4. #4
    Registered User
    Join Date
    11-09-2006
    MS-Off Ver
    Excel 2010 64 bit
    Posts
    200

    Re: Curve fitting with formulas

    Quote Originally Posted by Glenn Kennedy View Post
    Hi there.

    A picture is worth 1,000 words. An Excel sheet is worth 1,000 pictures.

    Please read the yellow banner about sample worksheets, at the top of the screen. Act on its guidelines and post a SMALL sample sheet.

    thanks I have attached the workbook - the chart shows polynomial curve - need to create something similar with formulas and get the data in excel
    Attached Files Attached Files

  5. #5
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: Curve fitting with formulas

    Something like this?? I fitted it to a quartic polynomial. In G7, copied down:

    =INDEX(LINEST($C$2:$C$63,(ROW($C$2:$C$63)-ROW($C$2)+1)^{1,2,3,4}),1,ROWS(G$7:G7))

    You seem to be using an older version of Excel than me. So, please refer to the attached file. If the formulae are enclosed within a pair of { }, these are array formulae.

    These are a little different from ordinary formulae in that they MUST be confirmed in the FIRST CELL ONLY by pressing CTRL+SHIFT+ENTER to activate the array, not just ENTER. After that, the array can be dragged down as normal, to cover the desired range.

    You will know the array is active when you see the curly brackets { } appear around the outside of your formula. If you do not use CTRL+SHIFT+ENTER you will (almost always) get an error message or an incorrect answer. Press F2 on that cell and try again.

    Don't type the curly brackets yourself - it won't work...

    I added the regression equation on the chart. However, these are rounded. the ones delivered by the formula are mathematically exact.
    Attached Files Attached Files

  6. #6
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,428

    Re: Curve fitting with formulas

    You have specified a line chart for your chart data, which means that excel will use count numbers (1,2,3,...) for the X values rather than the (unevenly spaced) time values in column A. What do you want to use for the x values in these regressions? Your LINEST() function will need a column containing these values.

  7. #7
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: Curve fitting with formulas

    Well spotted Mr S!!

  8. #8
    Registered User
    Join Date
    11-09-2006
    MS-Off Ver
    Excel 2010 64 bit
    Posts
    200

    Re: Curve fitting with formulas

    Quote Originally Posted by Glenn Kennedy View Post
    Something like this?? I fitted it to a quartic polynomial. In G7, copied down:

    =INDEX(LINEST($C$2:$C$63,(ROW($C$2:$C$63)-ROW($C$2)+1)^{1,2,3,4}),1,ROWS(G$7:G7))

    You seem to be using an older version of Excel than me. So, please refer to the attached file. If the formulae are enclosed within a pair of { }, these are array formulae.

    These are a little different from ordinary formulae in that they MUST be confirmed in the FIRST CELL ONLY by pressing CTRL+SHIFT+ENTER to activate the array, not just ENTER. After that, the array can be dragged down as normal, to cover the desired range.

    You will know the array is active when you see the curly brackets { } appear around the outside of your formula. If you do not use CTRL+SHIFT+ENTER you will (almost always) get an error message or an incorrect answer. Press F2 on that cell and try again.

    Don't type the curly brackets yourself - it won't work...

    I added the regression equation on the chart. However, these are rounded. the ones delivered by the formula are mathematically exact.

    Thank you very much Glenn - I have tried to add the curve based on these parameters and could not do that - can you help? I have attached my trial workbook:
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    11-09-2006
    MS-Off Ver
    Excel 2010 64 bit
    Posts
    200

    Re: Curve fitting with formulas

    Quote Originally Posted by MrShorty View Post
    You have specified a line chart for your chart data, which means that excel will use count numbers (1,2,3,...) for the X values rather than the (unevenly spaced) time values in column A. What do you want to use for the x values in these regressions? Your LINEST() function will need a column containing these values.

    yes values can sometimes not be evenly spaced but I am ok with that - I can just replace the time axis with 1,2,3

  10. #10
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: Curve fitting with formulas

    I don't follow you. This is the sheet I posted in reply to you. What do you expect to see? Where do you expect to see it? The components of the LoBF are there, the fitted curve is shown...

  11. #11
    Registered User
    Join Date
    11-09-2006
    MS-Off Ver
    Excel 2010 64 bit
    Posts
    200

    Re: Curve fitting with formulas

    thanks I want to have curve data in a column - can this be done?

  12. #12
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: Curve fitting with formulas

    Yep:

    =SIGN($H$2)*(ABS($H$2*ROWS($F$2:F2))^4)+SIGN($H$3)*(ABS($H$3*ROWS($F$2:F2))^3)+SIGN($H$4)*(ABS($H$4*ROWS($F$2:F2))^2)+($H$5*ROWS($F$2:F2))+$H$6

    You're welcome.



    If that takes care of your original question, please select "Thread Tools" from the menu link above and mark this thread as SOLVED.

    It'd also be appreciated if you were to click the Add Reputation button at the foot of any of the posts of all members who helped you reach a solution.
    Attached Files Attached Files

  13. #13
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: Curve fitting with formulas

    That (like the graph you plotted) is fitted with 1,2,3, etc on the X-axis. it is up to you to determine if that is correct for your purposes.

  14. #14
    Registered User
    Join Date
    11-09-2006
    MS-Off Ver
    Excel 2010 64 bit
    Posts
    200

    Re: Curve fitting with formulas

    thank you - the fitted line is just straight line - can it be made similar to the polynomial curve that we see on the chart? can you plot the fitted line on the chart?

  15. #15
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: Curve fitting with formulas

    Titters loudly. Yep. I fouled up there. So, I have removed the trendline and fitted the experimental points.
    Attached Files Attached Files

  16. #16
    Registered User
    Join Date
    11-09-2006
    MS-Off Ver
    Excel 2010 64 bit
    Posts
    200

    Re: Curve fitting with formulas

    awesome! thanks a lot Glenn! a short question - the curves can be made even more fitted? can it be 6th or 10ths power equation? notwithstanding the formula chaos expected!)

  17. #17
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: Curve fitting with formulas

    Possibly. I went as far as 4th. As far as I recall, 5th order looked worse, so I stopped. You can add a trendline and try it for yourself. Do you know how to do that?

  18. #18
    Registered User
    Join Date
    11-09-2006
    MS-Off Ver
    Excel 2010 64 bit
    Posts
    200

    Re: Curve fitting with formulas

    Quote Originally Posted by Glenn Kennedy View Post
    Possibly. I went as far as 4th. As far as I recall, 5th order looked worse, so I stopped. You can add a trendline and try it for yourself. Do you know how to do that?
    I do not know how to generate the coefficients.....can you direct me to a proper guide if any on your mind?

  19. #19
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: Curve fitting with formulas

    Look at Cell H2, in my last file upload. It reads:

    =INDEX(LINEST($C$2:$C$63,(ROW($C$2:$C$63)-ROW($C$2)+1)^{1,2,3,4}),1,ROWS(H$2:H2))

    Red: your Y data range.
    Orange: a "counter" that sets your X-data range
    Cyan: tells Excel that it's a quartic fit. If, for example, you want a fifth order fit, use {1,2,3,4,5} instead.
    Blue: another counter. First row you have the formula in will be the 5th order exponent, the next the 4th and so on.

    don't forget that in your Excel version you may have to use an array formula in those cells. See post 5.

    If you have problmes, shout. Otherwise, you're welcome.



    If that takes care of your original question, please select "Thread Tools" from the menu link above and mark this thread as SOLVED.

    It'd also be appreciated if you were to click the Add Reputation button at the foot of any of the posts of all members who helped you reach a solution.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. 3D Curve Fitting
    By EssoExplJoe in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-30-2017, 04:56 PM
  2. Curve fitting questions
    By Joe Miller in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 12-22-2014, 02:45 AM
  3. curve fitting
    By somsankarsen@gmail.com in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 06-03-2006, 02:10 PM
  4. Curve fitting algorithm
    By ringo in forum Excel Charting & Pivots
    Replies: 4
    Last Post: 01-11-2006, 07:50 AM
  5. curve fitting a charging capacitor type curve
    By mcgradys in forum Excel General
    Replies: 4
    Last Post: 11-15-2005, 08:50 AM
  6. [SOLVED] Best fitting curve
    By ladee_bird in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-27-2005, 09:05 AM
  7. best curve fitting
    By ladee_bird in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 09-20-2005, 03:05 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1