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

Need help understanding Syntax of linfit function?

rmerrill-2
7-Bedrock

Need help understanding Syntax of linfit function?

Dear Community:

I am a very new user of MathCad, and I need help understanding the syntax of the linfit function.  (At least I think it's a syntax issue).

I built a small worksheet to look at various curve fitting functions (it grew out of a need from a work related worksheet; I have hand entered some of the data and changed to units to make the example sheet self-contained).  I successfully parroted the linfit example for a quadratic fit (a*x^2+b*x+c), but I could not extend it successfully for a cubic fit (a*x^3+b*x^2+cx+d).  I could successfully build a cubic fit using polyc.

I enclose the worksheet:

Page 1: Data

Page 2: Cubic Spline

Page 3: Straight Line

Page 4: Quadratic linfit (and polyc)

Page 6: Cubic linfit (and polyc)         <---- This is where it goes wrong

Any insights would be appreciated.

Regards,

Bob

ACCEPTED SOLUTION

Accepted Solutions

Thank you for your answers.  However, I am still perplexed.  I have enclosed a PDF of my worksheet for those with Prime 3.

Page 6, from the PDF is repeated here:

Page6.PNG

(ps, qres) are x,y values.  I print out the coefficients from both linfit and polyc (they come out in reverse order, but you can look at the units to compare).  The coefficients for x^3 and x^2 are arguably zero.  But the linear and constant terms are very, very different.  This difference is plotted on page 7 (reproduced here):

Page7.PNG

The results from polyc seem reasonable, those from linfit do not.

I think that I'm using the correct syntax - but clearly that isn't so!

Regards,

Bob

View solution in original post

5 REPLIES 5

I can't open your file, so I can't see what you did.  But this is linfit in Prime 3.0:

If we knew that the linear term wasn't there, we could modify the function:

This document is for Mathcad Prime 4.0 version.

Thank you for your answers.  However, I am still perplexed.  I have enclosed a PDF of my worksheet for those with Prime 3.

Page 6, from the PDF is repeated here:

Page6.PNG

(ps, qres) are x,y values.  I print out the coefficients from both linfit and polyc (they come out in reverse order, but you can look at the units to compare).  The coefficients for x^3 and x^2 are arguably zero.  But the linear and constant terms are very, very different.  This difference is plotted on page 7 (reproduced here):

Page7.PNG

The results from polyc seem reasonable, those from linfit do not.

I think that I'm using the correct syntax - but clearly that isn't so!

Regards,

Bob

Hi Robert,

Are you still having the issue or has it been solved?

I see you have marked your last post as correct, but within, your text hints that you are still having the issue.

Thank you for clarifying.

Best,

Toby

I can duplicate this exact problem in Prime 3.0,  Linfit gives an incorrect response.

I think you found a bug!

Note that "polyfit" (without the "c") will create a function:  Y := poltfit (ps,qres,3)  then Y(pres)= will give the function evaluated at "pres".  But you probably already knew that!  😉

Announcements

Top Tags