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

Community Tip - Need help navigating or using the PTC Community? Contact the community team. X

The best way to extract polynomial coefficients and form an equation

MarkBuckton
4-Participant

The best way to extract polynomial coefficients and form an equation

I have performed a least squares fit on a data set and fitted a 21st order polynomial to the data. However, within the forum I could not find a good example of how to extract the polynomial coefficients. Since this is a 21st order polynomial automating the process would be the preferred way to go. From what I can garner through other discussions on the subject there may not be a trivial way to do this - am I correct? Anyway has someone accomplished this feat and is willing to alter my worksheet to show me how to do it. If not I may have to buy Curve Fit Expert but Mathcad methods are of more interest to me.

Kind regards, Mark

1 ACCEPTED SOLUTION

Accepted Solutions
lturek
4-Participant
(To:MarkBuckton)

Afterthought:

If you really want the coefficients and need a symbolic representation, you can either use regression as shown by Valery Ochkov or you can use polyfitc which you already mentioned yourself.

If you want to show this function via symbolic evaluation (why would you do so?), you have to add a numeric evaluation after the definition of coeffs, because the symbolics can not evaluate poyfitc.

The symbolics are unit unaware and treats time and volume units like unknown variables. I guess you could replace s and m by min and L using substitute.

Concerning the help pages: I would suggest you install Mathcad 15 (you get it for free with Prime) and use the help of that program. Is not complete either but much better accessible compared to what Prime offers.

Why do you try a fit with a polynomial of that high order? Do you know that the data should follow a polynomial? You could try a polynomial with much smaller degree (e.g. 3) or a logistic regression (assuming that the decrease at the end should not be there). It all depends on where the data stems from, what is represents and what you know about it.

Is it mandatory to fit with a continuous, analytic function, or wouldn't a simple linear or a spline interpolation do the job as well? You can integrate those interpolations numerically as well.

View solution in original post

8 REPLIES 8

If you use the function "regress" to do the fit, the resulting vector contains all the coefficients.

Ok. Looks like "regress" isn't in Prime (at least, not in Prime 2, don't know about Prime 3). Try "polyfitc".

Alan

May be so

regr.png

Thanks Valery;

Your method looks more elegant i.e. simpler than polyfitc function which produces a rather large matrix of information (most of which I am uninterested in) nevertheless polyfitc appears to give the same results as your method. Unfortunately, I don't understand what the second group of parameters that you have applied to the regress function i.e. the 3,24,0,0 as the regress function is not explained in the Prime 3 help.

Also; I note that polyfitc is not well explained either and returns the first matrix column in the following form "A","AA","AAA","AAAA" ...etc. Why not c0, c1, c2 etc. According to the help one can define the polynomial regression equation by its polynomial order n or by its terms as specified in the string “terms” or in matrix M. Use matrix M when you do not want to include the intercept in the polynomial fit. This description is meaningless to me because it doesn't give an example of how to apply these parameters. If you have time to explain these parameters it would be appreciated.

Regards, Mark

I am glad to help you Mark.

As one gift see the animation - Video Link : 1473

lturek
4-Participant
(To:MarkBuckton)

You won't need the coefficients of the polynomial if all you wanna do is plotting, numerical integration, etc. Just use your function g(x) the usual way as you already did in the plot:

You should replace the second zero in your X-vector for a different value like 2 for consistency.

I wonder why polyfit does not throw an error because of the two equal x-values.

What happened to this site? Looks like it was undergoing heavy changes in appearance and functionality. Navigation looks a bit more straightforward but the overall visual impact is less appealing and overburdened compared to what I remember. Not very inviting.

lturek
4-Participant
(To:MarkBuckton)

Afterthought:

If you really want the coefficients and need a symbolic representation, you can either use regression as shown by Valery Ochkov or you can use polyfitc which you already mentioned yourself.

If you want to show this function via symbolic evaluation (why would you do so?), you have to add a numeric evaluation after the definition of coeffs, because the symbolics can not evaluate poyfitc.

The symbolics are unit unaware and treats time and volume units like unknown variables. I guess you could replace s and m by min and L using substitute.

Concerning the help pages: I would suggest you install Mathcad 15 (you get it for free with Prime) and use the help of that program. Is not complete either but much better accessible compared to what Prime offers.

Why do you try a fit with a polynomial of that high order? Do you know that the data should follow a polynomial? You could try a polynomial with much smaller degree (e.g. 3) or a logistic regression (assuming that the decrease at the end should not be there). It all depends on where the data stems from, what is represents and what you know about it.

Is it mandatory to fit with a continuous, analytic function, or wouldn't a simple linear or a spline interpolation do the job as well? You can integrate those interpolations numerically as well.

MarkBuckton
4-Participant
(To:lturek)

You have both been of great help. Thank you.

I think the Mathcad Prime 3 help is very bad. I agree I must remember to look at the Mathcad 15 help on these functions and hopefully it explains things a little better.

Kind regards, Mark

Top Tags