number of significant digits for the coefficients in curve fitter (polynomial, with two degree)
44 views (last 30 days)
Show older comments
Hello, I am creating a surface from 5X4 arrray of X, Y, Z as polynomial and 2 degrees of X and Y to derive a equation showing Z as a afunction of X and Y. When it comes to the multipliers (p00, p10, p01, p20,...) how can we increase the number of significant digits after decimal. Thanks in advance!
0 Comments
Answers (3)
Steven Lord
on 4 Apr 2023
Don't confuse what's displayed by the fit object and what's stored in the fit object. Perform the fitting, export the fit to the workspace, and call coeffvalues on the object to extract the full double precision coefficient values stored in the object.
0 Comments
dpb
on 4 Apr 2023
All are estimated to full double-precision; the number of digits that are displayed is solely dependent upon how you look at the results (and what tool, specifically, you used for the estimation and how it may display them by default).
Consider
x=[0:10].'; y=x.^1.75+rand(size(x)); % make up something
f=fit(x,y,'poly2')
and we see that the coefficients are displayed with four digits past the decimal. But,
format long; format compact
coeffvalues(f)
shows the values are stored with full precision. Hence, unless you're writing these down somewhere by hand or writing them to an ASCII file, then just using the variable as provided will give you the full precision. Hence, it's wise to only export in a format that does maintain the full precision; polynomials can be deceiving in that the extra digits may be quite important in evaluation; especially for higher power models.
Well, let's see -- are the output values from fit itself aware of the present format setting or are they produced internally to be prettified? Let's rerun the fun and see what we see after setting format...
f=fit(x,y,'poly2')
Yeah, as I suspected -- those are output-formatted within the fit function itself, the format statement had no effect.
2 Comments
John D'Errico
on 4 Apr 2023
Edited: John D'Errico
on 4 Apr 2023
While I tested the same thing some time ago with fit, I have often wondered if fit should be responsive to your format settings. This would not be difficult to do for them. I'll put in a feature request that fit should do exactly that.
(Submitted just now.) They might arguably say no, that the user should not be encouraged to use the coefficients, but to extract them as is correct. But we know that many users will not use coeffvalues. So how can it hurt for fit to look at your format, and follow it for guidance?)
Steven Lord
on 5 Apr 2023
If you're simply trying to evaluate the fit, don't use coeffvalues to extract the coefficient values to then use in a separate equation or type them in as displayed. Just evaluate the fit directly.
Nirav
on 5 Apr 2023
What is the command for three variables (i.e., x,y,z) instead of two variables (i.e., x,y)?
More precisely, what is the command to display the more than four digitis past decimal? The equation is as follows:
Polynomial Surface Fit (poly22)
f(x,y) = p00 + p10*x + p01*y + p20*x^2 + p11*x*y + p02*y^2
1 Comment
dpb
on 5 Apr 2023
It doesn't matter, it's the command window format that controls..as before to SEE the coefficients in all their glory use
format long; format compact
coeffvalues(f)
BUT, they are stored and should be used with the fit object itself that contains the full precision internally.
See Also
Categories
Find more on Interpolation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!