Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X
I a trying to get to grips with the graphing capability of Mathcad.
In the attached I have used a polyfit which obviously is not what I want (I am not sure how to use other graphing functions).
How can I get a line of best fit approach?
Solved! Go to Solution.
Ah! I have not read the text thoroughly enough and did not read that a regression line is searched for.
You can also use "polyfit" for that case:
And in case you need the coefficients, you may use "polfitc":
or the built-in "line" command:
Instead of:
Try these:
Then:
Success!
Luc
Ah! I have not read the text thoroughly enough and did not read that a regression line is searched for.
You can also use "polyfit" for that case:
And in case you need the coefficients, you may use "polfitc":
or the built-in "line" command:
Werner,
Sorry I am really new to this area of Mathcad. In this context what are the coefficients returned?
Andy.
> In this context what are the coefficients returned?
The very same as the a and b in Lucs answer.
It was only after reading Lucs correct reply that I realized, that you want to plot a straight regression line and not a more complicated one or a perfect fit (graph runs through
all points) or interpolation.
Luc has shown one way to get the slope a and intercept b with the vertical axis of that line so you can formulate its equation y(x)= a*x+b. He was using the two separate commands "slope" and "intercept" and doing so perfectly documents the role of those two values.
I just showed another way to get those two values with a single command ("line") and also pointed out, that "polyfit" also is able to give you the straight regression line if you choose polynomial order 1 (highlighted in yellow).
Normally you would not care about the coefficients polyfit uses for its polynomial but you can get Mathcad to tell you those coefficients and a lot of other information using the function "polyfitc" (look it up in the help if you are interested in more details). "polyfitc" returns a matrix with all its information and I simply picked out the two values (slope and intercept) using the command "submatrix". Just another (more complicated) way to get those values.
Do you need an exact fit?
Or would a a regression be good enough. Then try order 1, 3, or 5 instead of 8 if you want a polynomial function.
You may also consider an interpolation using splines.