number of significant digits for the coefficients in curve fitter (polynomial, with two degree)

44 views (last 30 days)
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!

Answers (3)

Steven Lord
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.

dpb
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')
f =
Linear model Poly2: f(x) = p1*x^2 + p2*x + p3 Coefficients (with 95% confidence bounds): p1 = 0.4623 (0.4409, 0.4838) p2 = 1.075 (0.8524, 1.298) p3 = 0.2647 (-0.2141, 0.7434)
and we see that the coefficients are displayed with four digits past the decimal. But,
format long; format compact
coeffvalues(f)
ans = 1×3
0.462347359439879 1.075119429611482 0.264656217904630
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')
f =
Linear model Poly2: f(x) = p1*x^2 + p2*x + p3 Coefficients (with 95% confidence bounds): p1 = 0.4623 (0.4409, 0.4838) p2 = 1.075 (0.8524, 1.298) p3 = 0.2647 (-0.2141, 0.7434)
Yeah, as I suspected -- those are output-formatted within the fit function itself, the format statement had no effect.
  2 Comments
John D'Errico
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
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.

Sign in to comment.


Nirav
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
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.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!