Curve Fitter tool-Center and scale

57 visualizzazioni (ultimi 30 giorni)
SYML2nd
SYML2nd il 15 Feb 2023
Risposto: Steven Lord il 15 Feb 2023
I am using the matlab Curve Fitter tool. I don't know what means the button "Center and scale". Can you explain? I tried to use it and sometimes the fitting seems to improve in quality. When I use it, it appears the phrase "where x is normalized by mean ** and std *** ". Should I scale also the resulting coefficient?

Risposta accettata

Steven Lord
Steven Lord il 15 Feb 2023
Suppose you wanted to fit a quadratic curve to the census data set.
format longg
load census
plot(cdate, pop, 'o-')
Let's build the coefficient matrix.
A = [cdate.^2, cdate.^1, cdate.^0]
A = 21×3
3204100 1790 1 3240000 1800 1 3276100 1810 1 3312400 1820 1 3348900 1830 1 3385600 1840 1 3422500 1850 1 3459600 1860 1 3496900 1870 1 3534400 1880 1
The elements of A vary in magnitude from 1 to nearly 4 million.
[minValue, maxValue] = bounds(A, 'all')
minValue =
1
maxValue =
3960100
So the condition number is pretty bad.
cond(A)
ans =
3913649716.08753
By the rule of thumb cited on that Wikipedia page, "As a rule of thumb, if the condition number is , then you may lose up to k digits of accuracy on top of what would be lost to the numerical method due to loss of precision from arithmetic methods."
What if we centered and scaled the date data and used the centered and scaled data in the construction of A?
normalizedCdate = normalize(cdate, 'zscore');
Normalizing using 'zscore' (the default) results in normalized data with mean 0 and standard deviation 1.
mean(normalizedCdate) % close enough to 0
ans =
4.22942104619107e-17
std(normalizedCdate)
ans =
1
If we build the coefficient matrix with this data:
A2 = normalizedCdate.^[2 1 0]
A2 = 21×3
2.5974025974026 -1.61164592805076 1 2.1038961038961 -1.45048133524568 1 1.66233766233766 -1.28931674244061 1 1.27272727272727 -1.12815214963553 1 0.935064935064935 -0.966987556830456 1 0.649350649350649 -0.80582296402538 1 0.415584415584416 -0.644658371220304 1 0.233766233766234 -0.483493778415228 1 0.103896103896104 -0.322329185610152 1 0.025974025974026 -0.161164592805076 1
the range of elements is much smaller:
[minValue, maxValue] = bounds(A2, 'all')
minValue =
-1.61164592805076
maxValue =
2.5974025974026
This matrix is much better conditioned.
cond(A2)
ans =
2.72887654772582
log10(cond(A2))
ans =
0.435983888966277
Instead of losing 9 digits of accuracy we're losing less than half a digit.
coefficients1 = A\pop
coefficients1 = 3×1
1.0e+00 * 0.00654113049421954 -23.5097459954225 21129.5921192301
coefficients2 = A2\pop
coefficients2 = 3×1
25.183352402746 75.4338934853799 61.7444262830991
Note that we could be required to multiply a number near 4 million by a small number (0.0065...) if we want to use coefficients1 to evaluate the fit. If we want to use coefficients2 we're multiplying a number between say -2 and 2.5 by 25.1833....

Più risposte (0)

Categorie

Scopri di più su Curve Fitting Toolbox in Help Center e File Exchange

Prodotti


Release

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by