matlab曲线拟合函数
各位大神走过路过,帮帮小弟。x=[195319641982198920002010];y=[6.02e+087.23e+081.03e+091.16e+091.24e+0...
各位大神走过路过,帮帮小弟。
x=[1953 1964 1982 1989 2000 2010];
y=[6.02e+08 7.23e+08 1.03e+09 1.16e+09 1.24e+09 1.33e+09];
求其拟合函数,要有原程序。再次感谢各位了
大神 能否不用多项式模型 这个误差太大 展开
x=[1953 1964 1982 1989 2000 2010];
y=[6.02e+08 7.23e+08 1.03e+09 1.16e+09 1.24e+09 1.33e+09];
求其拟合函数,要有原程序。再次感谢各位了
大神 能否不用多项式模型 这个误差太大 展开
推荐于2016-08-07
展开全部
x=[1953 1964 1982 1989 2000 2010];
y=[6.02e+08 7.23e+08 1.03e+09 1.16e+09 1.24e+09 1.33e+09];
[xData, yData] = prepareCurveData( x, y );
% Set up fittype and options.
ft = fittype( 'poly1' );
opts = fitoptions( ft );
opts.Lower = [-Inf -Inf];
opts.Upper = [Inf Inf];
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts );
% Plot fit with data.
figure( 'Name', 'linerFit' );
h = plot( fitresult, xData, yData );
legend( h, 'y vs. x', 'linerFit', 'Location', 'NorthEast' );
% Label axes
xlabel( 'x' );
ylabel( 'y' );
grid on
结果:
Linear model Poly1:
ans(x) = p1*x + p2
Coefficients (with 95% confidence bounds):
p1 = 1.344e+07 (1.075e+07, 1.613e+07)
p2 = -2.563e+10 (-3.097e+10, -2.03e+10)
说明:我这里用的是最小二乘的一阶拟合,如果是二阶可以将poly1改为poly2,以此类推poly3等
y=[6.02e+08 7.23e+08 1.03e+09 1.16e+09 1.24e+09 1.33e+09];
[xData, yData] = prepareCurveData( x, y );
% Set up fittype and options.
ft = fittype( 'poly1' );
opts = fitoptions( ft );
opts.Lower = [-Inf -Inf];
opts.Upper = [Inf Inf];
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts );
% Plot fit with data.
figure( 'Name', 'linerFit' );
h = plot( fitresult, xData, yData );
legend( h, 'y vs. x', 'linerFit', 'Location', 'NorthEast' );
% Label axes
xlabel( 'x' );
ylabel( 'y' );
grid on
结果:
Linear model Poly1:
ans(x) = p1*x + p2
Coefficients (with 95% confidence bounds):
p1 = 1.344e+07 (1.075e+07, 1.613e+07)
p2 = -2.563e+10 (-3.097e+10, -2.03e+10)
说明:我这里用的是最小二乘的一阶拟合,如果是二阶可以将poly1改为poly2,以此类推poly3等
追问
用指数函数的那个行吗 谢谢你了
追答
高斯函数拟合,指数的
[xData, yData] = prepareCurveData( x, y );
% Set up fittype and options.
ft = fittype( 'gauss1' );
opts = fitoptions( ft );
opts.Display = 'Off';
opts.Lower = [-Inf -Inf 0];
opts.StartPoint = [1330000000 2010 27.2886751671404];
opts.Upper = [Inf Inf Inf];
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts );
% Plot fit with data.
figure( 'Name', 'untitled fit 1' );
h = plot( fitresult, xData, yData );
legend( h, 'y vs. x', 'untitled fit 1', 'Location', 'NorthEast' );
% Label axes
xlabel( 'x' );
ylabel( 'y' );
grid on
结果:
General model Gauss1:
f(x) = a1*exp(-((x-b1)/c1)^2)
Coefficients (with 95% confidence bounds):
a1 = 1.35e+09 (1.19e+09, 1.51e+09)
b1 = 2019 (1998, 2041)
c1 = 72.42 (50.31, 94.52)
Goodness of fit:
SSE: 2.306e+15
R-square: 0.9946
Adjusted R-square: 0.991
RMSE: 2.772e+07
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询