Matlab曲线拟合问题
%% 构造数据
x=-10:.1:10;
y=x.^3+5*randn(1,length(x))
figure,plot(x,y),title('原始数据')
%% 打开拟合工具箱进行拟合
%% 拟合结果 ,得到函数的参数
% Linear model Poly3:
% f(x) = p1*x^3 + p2*x^2 + p3*x + p4
% Coefficients (with 95% confidence bounds):
p1 = 1.006 % (1.001, 1.01)
p2 = 0.01305 % (-0.01003, 0.03612)
p3 = -0.3299 % (-0.6293, -0.03041)
p4 = -0.375 %(-1.417, 0.6674)
f = p1.*x.^3 + p2.*x.^2 + p3.*x + p4
figure,plot(x,f),title('拟合后得到的函数图象')
% Goodness of fit:
% SSE: 4917
% R-square: 0.9998
% Adjusted R-square: 0.9998
% RMSE: 4.996