Curve fitting之matlab

本文介绍了MATLAB CurveFitting Toolbox的使用,包括多项式拟合技巧、数据预处理、自定义非线性模型的创建,以及如何通过lsqcurvefit进行非线性曲线拟合。讨论了过度拟合问题、置信区间计算和预测区间评估。适合处理大型数据和定制模型的需求。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

工具箱

Curve Fitting Toolbox文档
适用按钮

理论参考
在这里插入图片描述
拟合界面选择说明:
在这里插入图片描述

生成代码: 最上菜单栏 >> CURVE FITTING TOOL >> 文件 >> Generate Code >> 自动生成一个creatFit.m文件;
生成图片: 最上菜单栏 >> CURVE FITTING TOOL >> 文件 >> Print to Figure
若要修改图片性质之类的,鼠标在图片上右击,就OK了。


⋅ \cdot 多项式曲线拟合
经验

  1. 如果input is quite large, so you can obtain better results by centering and scaling the data.
    population3 = fit(cdate,pop,'poly3','Normalize','on');
  2. 拟合结果的 residual 如果a systematic pattern, 则 poorly,换拟合方式。
  3. 预测区间
    plot(population3,'predobs')
  4. 五次拟合的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.
  5. 在 新 查 询 点 评 估 最 佳 拟 合 \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)

经验

  1. 拟合数据的plot plot(curvefit,cdate,pop)
写m.文件

非线性数据拟合

  1. [求解器]使用 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-理论详细

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值