这是一个国外朋友自己做的“least squares splines”优化工具箱,做的相当不错!!!!你只需要安装好这个优化工具箱,用法超简单。首先传上优化工具箱:
接下来演示拟合过程,首先使用安装好的这个拟合工具箱做一个数据拟合,范例见下:
matlab code:
x = (sort(rand(1,100)) - 0.5)*pi;
y = sin(x).^5 + randn(size(x))/10;
slm = slmengine(x,y,'plot','on','knots',10,'increasing','on', ...
'leftslope',0,'rightslope',0)
slm =
form: 'slm'
degree: 3
knots: [10x1 double]
coef: [10x2 double]
prescrip
tion: [1x1 struct]
x: [100x1 double]
y: [100x1 double]
同时出拟合结果图:
接下来使用MATLAB自带的样条曲线进行拟合:
MATLAB code:
x = (sort(rand(1,100)) - 0.5)*pi;
y = sin(x).^5 + randn(size(x))/10;
xx=linspace(min(x),max(x),200);
yy = spline(x,y,xx);
plot(x,y,'o',xx,yy);
拟合曲线图: