工具箱
理论参考
拟合界面选择说明:
生成代码: 最上菜单栏 >> CURVE FITTING TOOL >> 文件 >> Generate Code >> 自动生成一个creatFit.m文件;
生成图片: 最上菜单栏 >> CURVE FITTING TOOL >> 文件 >> Print to Figure
若要修改图片性质之类的,鼠标在图片上右击,就OK了。
⋅
\cdot
⋅ 多项式曲线拟合
经验:
- 如果input is quite large, so you can obtain better results by centering and scaling the data.
population3 = fit(cdate,pop,'poly3','Normalize','on');
- 拟合结果的 residual 如果a systematic pattern, 则 poorly,换拟合方式。
- 预测区间
plot(population3,'predobs')
- 五次拟合的CI中低阶的跨越了 ‘+与-’,过度拟合(因高阶的系数为0,无法确定低阶的倾向)
If the higher order model terms may have coefficients of zero, they are not helping with the fit, which suggests that this model over fits the census data. - 在 新 查 询 点 评 估 最 佳 拟 合 \textcolor{orange}{在新查询点评估最佳拟合} 在新查询点评估最佳拟合
cdateFuture = (2000:10:2020).’;
popFuture = population2(cdateFuture) % population2指chosed拟合模型
置 信 区 间 \textcolor{orange}{置信区间} 置信区间
ci = predint(population2,cdateFuture,0.95,‘observation’)
⋅ \cdot ⋅ 自定义非线性拟合
load census
%Custom nonlinear census fitting
s = fitoptions( 'Method','NonlinearLeastSquares', ...
'Startpoint',[1 1]);
f= fittype('a*(x-b)^n','problem','n','options',s);
[c2,gof2] = fit(cdate,pop,f,'problem',2)
经验
- 拟合数据的plot
plot(curvefit,cdate,pop)
写m.文件
非线性数据拟合
- [求解器]使用 lsqcurvefit 的求解
需指定(带参数)拟合函数形式,且需given'待估计paras'的初始点
lsqcurvefit
用最小二乘求解非线性曲线拟合(数据拟合)问题
x = l s q c u r v e f i t ( f u n , x 0 , x d a t a , y d a t a ) \color{blue}{x = lsqcurvefit(fun,x0,xdata,ydata)} \quad x=lsqcurvefit(fun,x0,xdata,ydata)
% x 0 x_0 x0初始点, 求解器使用 x0 中的元素数量和 x0 的大小来确定 fun 接受的变量数量和大小。
mathworkds help文档
fun = @(x,xdata)x(1)*exp(x(2)*xdata);
x0 = [100,-1];
x = lsqcurvefit(fun,x0,xdata,ydata)
x = lsqcurvefit(fun,x0,xdata,ydata,lb,ub)
%拟合参数有约束条件下求数据的最佳指数拟合。
[x,resnorm,~,exitflag,output] = lsqcurvefit(F,x0,t,y)
解释:
三次样条插值:
output上下波动,没有单调性
Def: 三次样条插值多项式是一种分段函数,它在节点分成的每个小区间上是3次多项式
龙格现象:中间部分插值效果比较好,而对于两端,插值结果是非常不理想的
重点推荐:多种插值method-理论详细