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

How to show equation in Matlab fitting toolbox?

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

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

编辑:我能够得到如下代码,file->generate code。 但我仍然需要找到方程式,谁能告诉我该怎么做?

谢谢。

我不确定如何在图表上显示任何方程,但您应该能够使用命令 spline and unmkpp.

复制三次样条插值
% 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),'-');