如何在Matlab拟合工具箱中显示方程?

时间:2015-06-21 07:11:52

标签: matlab regression curve-fitting spline

我正在使用matlab曲线拟合工具箱来拟合我的数据曲线。我已经使用了三次样条,在图中它很合适,但我希望看到使用的等式。有没有办法做到这一点?

另外,有没有办法显示代码?我的意思是代码用于通过工具箱拟合曲线?

编辑:我能够获得以下代码,file->生成代码。 但是我仍然需要找到这个等式,任何人都可以告诉我如何做到这一点?

谢谢。

1 个答案:

答案 0 :(得分:1)

我不确定如何在图表上显示任何公式,但您应该能够使用命令splineunmkpp复制三次样条插值。

% returns the piecewise polynomial form of the cubic spline interpolant
pp = spline(x,Y)
% use unmkpp(pp) to get the piecewise polynomial details
[breaks,coefs,l,k,d] = unmkpp(pp)

请注意,在分段多项式中,每个部分都有一组系数。例如:

x = -4:4;
y = [0 .15 1.12 2.36 2.36 1.46 .49 .06 0];
% cs stores the piecewise polynomial
cs = spline(x,[0 y 0]);
% extract the coefficients
[breaks,coefs,l,k,d] = unmkpp(cs)
% the endpoints of each of the polynomial pieces
breaks =
  -4  -3  -2  -1   0   1   2   3   4
% 8 sets of coefficients (each set of 4 coefficients for one polynomial piece)
coefs =
   0.20344  -0.05344   0.00000   0.00000
  -0.09033   0.55689   0.50344   0.15000
  -0.39211   0.28589   1.34622   1.12000
   0.14878  -0.89045   0.74167   2.36000
   0.13699  -0.44411  -0.59289   2.36000
   0.13325  -0.03313  -1.07012   1.46000
  -0.05998   0.36661  -0.73663   0.49000
  -0.06334   0.18668  -0.18334   0.06000
% the number of pieces is 8
l =  8
% order is 4 (so 4 coefficients)
k =  4
d =  1
% plot the interpolation
xx = linspace(-4,4,101);
plot(x,y,'o',xx,ppval(cs,xx),'-');
相关问题