- Just because you can use a 9th degree polynomial doesn't mean you should. Look at the coefficients -- many of the higher order ones are extremely small.
- The coefficients values being displayed are not displayed to their full precision. If you used the displayed values rather than the full double precision values to evaluate the fit, particularly with an x as large as 250, the small error in the coefficients you used through rounding to five significant figures could be greatly magnified. Instead, export the fit and use it directly (NOT the displayed coefficients) to evaluate the fit.
- If you centered and scaled the fit but didn't center and scale the data when you evaluated it manually, the results will be different.
MATLAB - Basic fitting tool on plot
조회 수: 3 (최근 30일)
이전 댓글 표시
Hi, I don't understand any things on interactive fitting.
When I try to fit a plot with basic fittings, the norm residual is the error of fitting? My fitting is better if norm residual is near 0?
Another question:
In basic fitting I got this data (9-th degree polynomial):
y = p1*x^9 + p2*x^8 + p3*x^7 + p4*x^6 + p5*x^5 + p6*x^4 + p7*x^3 + p8*x^2 + p9*x + p10
Coefficients:
p1 = 1.4601e-20
p2 = -5.7732e-17
p3 = 1.0077e-13
p4 = -1.0187e-10
p5 = 6.5726e-08
p6 = -2.8044e-05
p7 = 0.0079067
p8 = -1.4194
p9 = 147.14
p10 = -6709.5
Norm of residuals =
0.078056
In the basic fitting tool, in the Find y=f(x) section, why if I insert a value, for example 250, I get as f(x) = -0.366, and instead, if I compute
y = p1*x^9 + p2*x^8 + p3*x^7 + p4*x^6 + p5*x^5 + p6*x^4 + p7*x^3 + p8*x^2 + p9*x + p10
above, why I get a different result?
UPDATE: the code is
close all
clear all
filename = 'phase_diagram.xls';
T = readtable(filename);
Temp_K_Saturation = str2double((T.SaturationLine(2:length(T.SaturationLine)))');
Temp_K_Saturation(isnan(Temp_K_Saturation)) = [];
Pressure_Bar_Saturation = str2double((T.Var5(2:length(T.Var5)))');
Pressure_Bar_Saturation(isnan(Pressure_Bar_Saturation)) = [];
figure(1);
plot(Temp_K_Saturation,Pressure_Bar_Saturation)
title('Linear Phase Diagram Water - Saturation line');
xlabel('Temperature [K]');
ylabel('Pressure [Bar]');
x=Temp_K_Saturation';
y=Pressure_Bar_Saturation';
degree=4;
%POLYFIT No centering and scaling
p = polyfit(x,y,degree);
f = polyval(p,x);
figure
plot(x,y,'o')
hold on
plot(x,f,'r')
hold off
title(strcat('No Centering and Scaling: Saturation Line --> Degree = ', num2str(degree)));
T = table(x,y,f,y-f,'VariableNames',{'X','Y','Fit','FitError'})
p
%%%%%%%%%%%%%%%
%POLYFIT CENTERING AND SCALING
[p,S,mu] = polyfit(x,y,degree);
f = polyval(p,x,S,mu);
figure
plot(x,y,'o')
hold on
plot(x,f,'r')
hold off
title(strcat('Auto Centering and Scaling: Saturation Line --> Degree = ', num2str(degree)));
T = table(x,y,f,y-f,'VariableNames',{'X','Y','Fit','FitError'})
p
댓글 수: 0
답변 (1개)
Steven Lord
2016년 2월 28일
댓글 수: 3
Walter Roberson
2016년 2월 28일
You can use the three-output form of polyfit(); that tells it to re-center and rescale.
However, typically if you are using anything over 7th degree, your answers are prone to be numeric nonsense.
참고 항목
카테고리
Help Center 및 File Exchange에서 Interpolation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!