cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Need to share some code when posting a question or reply? Make sure to use the "Insert code sample" menu option. Learn more! X

How to solve for the polynomial expression of a simple data matrix

TC_0928
10-Marble

How to solve for the polynomial expression of a simple data matrix

Newbie question...if I have a matrix of data values as shown below, how can I get Mathcad to solve for the actual polynomial (or exponential) expression ?

 

Or stated another way...can Mathcad provide the actual polynomial formula that would produce the graphed curve below based on the data provided.

 

TC_0928_0-1690482924116.png

I am using MathCad V9.0.

ACCEPTED SOLUTION

Accepted Solutions
Werner_E
25-Diamond I
(To:TC_0928)

I tried the site suggested by DJf (I knew the site as ZunZun from former times) and it was indeed able to find the best fit so far

Werner_E_4-1690551907460.png

I added it to my sheet

 

With free eyes you hardly can spot a difference to the best so far.

Werner_E_2-1690551636077.png

Main difference seems to be at the front values

Werner_E_3-1690551691875.png

 

 

View solution in original post

13 REPLIES 13
Werner_E
25-Diamond I
(To:TC_0928)

Probably the data is not exactly fulfilling a polynomial or exponential equation, so would rather use a fitting function.

Look up expfit, polyfit or genfit in the help pages.

If you need more help, come back again, attach your worksheet and state which version of Prime you are using.

From the pic it doesn't seem to me that a polynomial or an exponential would be a good fit - but you are the one who should know what process the data stems from and what kind of function can be expected.

 

BTW, from the spreadsheet screenshot it looks like you had chosen the wrong plot type in Excel as the x values are shown equidistant which they actually aren't.

LucMeekes
23-Emerald III
(To:TC_0928)

My guess is:

LucMeekes_0-1690494585753.png

with

LucMeekes_1-1690494606613.png

LucMeekes_2-1690494696955.png

So use genfit.

 

Success!
Luc

Thanks Luc...

 

Are you able to share any more of the details of your approach ? Apologies, but I'm new to the curve fitting functions in the Mathcad.

I will begin by looking at the genfit details in the help section as Werner suggested.

 

Can I assume that genfit produce these...

TC_0928_0-1690498037677.png

 

 

How did you arrive at this formula...

 

TC_0928_1-1690498069650.png

 

Werner_E
25-Diamond I
(To:TC_0928)


@TC_0928 wrote:
...

How did you arrive at this formula...

...

 

 


As Luc wrote - he guessed based on his experience that this type of function might give a good fit (and it looks like it actually does).

 

Still missing your worksheet with the data.

Understood...thanks Werner.

 

My intention is to try and have Mathcad derive a polynomial formula based on my set of data.

 

If I'm understanding the feedback so far, it would seem I have to use one of the curve fit functions to derive the coefficients.  Which specific curve fit function to use and the next steps beyond that I am unsure of.

 

 

 

 

Werner_E
25-Diamond I
(To:TC_0928)

I defined a function which calculates the root of the sum of squared errors so that I have a measure of the quality of the fit (the lower the value, the better the fit).

Werner_E_0-1690512430421.png

Exponential and polynomial fits do not provide good approximations

Werner_E_3-1690512711845.png

 

Logistic power was quite better

Werner_E_2-1690512594455.png

but MMF proved to give the best fit so far

Werner_E_4-1690512783386.png

Its even slightly better compared to what Luc had suggested

Werner_E_5-1690512830445.png

But when I added that additional parameter (exponent of x) in Luc's suggestion as described above, I got the best fit of all of them (so far)

Werner_E_9-1690513854465.png

 

Why do you write that you are looking for a polynomial fit but then you tried an exponential fit in your sheet??

Where do the data stem from and what's the reason for looking for a fitting function?

 

In the attached sheet I added a plot where you can compare your data against two of the six mentioned fit function which you can chose via a combo box. You also can set the order of the polynomial here by changing the global assignment for n.

As an example here the comparison of a fifth order polynomial with the last mentioned fit function:

Werner_E_7-1690513260522.png

Increasing the order of the polynomial does not really help. You may chose a 12th order polynomial which would run exactly through all your 13 data points and therefore has an SQE value of fantastic zero, but I bet that nonetheless you would not be happy with this fit:

Werner_E_10-1690514353643.png

 

EDIT: Just found a bug in Prime. Changing the order of the polynomial does not always refresh the plot. A manual recalc (F5/F9) of the sheet is necessary so the change also shows in the plot.

 

EDIT2: You may also use the built-in "corr()" function as a measure of quality - the closer to 1, the better.

Werner_E_0-1690515114488.png

 

 

Hi,

Often overlooked are splines as a means of fitting data with a smooth curve.  Is not what you asked for but it works.

Capture.JPG

Cheers

Terry

 

🙂

Werner_E_0-1690546718005.png

Surprise!!  😄

But then -  EVERY interpolation would yield a perfect correlation of 1, no matter if its a spline interpolation or a simple linear interpolation.

If an interpolation is appropriate as opposed to a functional fit depends on the needs.

In fact we don't know what the thread starter intends to do and why he asked for "how can I get Mathcad to solve for the actual polynomial (or exponential) expression ?"

 

DJF
16-Pearl
16-Pearl
(To:TC_0928)

findcurves.com is the best site I've found for finding a representative equation.

Werner_E
25-Diamond I
(To:DJF)


@DJF wrote:

findcurves.com is the best site I've found for finding a representative equation.


And which function type for the best fit this site comes up using the data provided here?

Attached is my cheat sheet for a least squares fit for a polynomial.  I apologize-- it's messy, You can pick the order of polynomial you want to fit and see how well it looks.  Runs in Prime 4 Express and higher.

Werner_E
25-Diamond I
(To:TC_0928)

I tried the site suggested by DJf (I knew the site as ZunZun from former times) and it was indeed able to find the best fit so far

Werner_E_4-1690551907460.png

I added it to my sheet

 

With free eyes you hardly can spot a difference to the best so far.

Werner_E_2-1690551636077.png

Main difference seems to be at the front values

Werner_E_3-1690551691875.png

 

 

Thanks for the help Werner...much appreciated !!

Announcements

Top Tags