样条的分段方程 [英] Piecewise equations for spline

查看:134
本文介绍了样条的分段方程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组数据,我想在Matlab中使用曲线拟合工具箱为数据绘制样条图.我已经做到了:

I have a set of data and i want to use curve fit toolbox in matlab to plot a spline graph for the data. i have done this:

x =

  Columns 1 through 10

     0    1.2500    1.8800    2.5000    5.0000    6.2500    6.8800    7.1900    7.5000   10.0000

  Columns 11 through 13

   12.5000   15.0000   20.0000
y =

  Columns 1 through 10

      -85.9300  -78.8200  -56.9500  -34.5600  -33.5700  -39.6400  -41.9600  -49.2800  -66.6000  -66.6100

      Columns 11 through 13

      -59.1600  -48.7800  -41.5300
    cftool
 [breaks,coefs,l,k,d] = unmkpp(pp)

breaks =

  Columns 1 through 10

         0    1.2500    1.8800    2.5000    5.0000    6.2500    6.8800    7.1900    7.5000   10.0000

  Columns 11 through 13

   12.5000   15.0000   20.0000


coefs =

   -4.8535   30.6309  -25.0170  -85.9300
   -4.8535   12.4304   28.8095  -78.8200
  -11.9651    3.2573   38.6927  -56.9500
    3.0330  -18.9977   28.9337  -34.5600
   -0.2294    3.7501   -9.1852  -33.5700
  -11.6351    2.8899   -0.8852  -39.6400
  -68.6157  -19.1004  -11.0978  -41.9600
  130.6350  -82.9130  -42.7220  -49.2800
   -6.3971   38.5776  -56.4659  -66.6000
    1.6010   -9.4008   16.4760  -66.6100
   -0.2967    2.6064   -0.5099  -59.1600
   -0.2967    0.3814    6.9597  -48.7800


l =

    12


k =

     4


d =

     1

如果我错了,请更正我,命令[breaks,coefs,l,k,d] = unmkpp(pp)是否可以帮助我从所获得的样条图获得分段方程式?如果是这样,我能知道我如何理解该命令,以便我可以利用自己的优势以及coefs,k,d中值的重要性.谢谢!基本上,我希望能够获得一个方程式/方程式来描述通过曲线拟合工具箱获得的样条图.任何帮助将不胜感激!

Correct me if i am wrong, is the command [breaks,coefs,l,k,d] = unmkpp(pp) able to help me get piecewise equations from the spline graph i obtained? If so, can i know how do i understand the command, so i can use to my own advantage and the significance of the values in coefs, k, d. Thanks! Basically i want to be able to obtain an equation/equations to describe the spline graph i obtained through the curve fit toolbox. any help would be greatly appreciated!

推荐答案

这试图说明如何挑选和显示在Matlab中生成的样条线.

This tries to explain how you can pick apart and display splines generated in Matlab.

生成模拟数据

xx = [1:10];
yy = cos(xx);

用三次样条拟合数据

pp = spline(xx,yy);

用分段多项式进行插值,然后在x的更精细网格上对其求值

Interpolate with the piecewise polynomial, evaluating it over a finer grid in x

xxf = linspace(min(xx),max(xx),100);
yyf=ppval(pp,xxf);

首先检查pp,其中包含有关分段多项式的所有信息:

Start by inspecting pp, which contains all of the information about the piecewise polynomial:

 pp = 

   form: 'pp'
 breaks: [1 2 3 4 5 6 7 8 9 10]
  coefs: [9x4 double]
 pieces: 9
  order: 4
    dim: 1

函数

[breaks,coefs,l,k,d] = unmkpp(pp)

仅解包结构pp的内容,使得:

merely unwraps the contents of structure pp, such that:

 d = pp.dim; 
 l = pp.pieces; 
 breaks = pp.breaks; 
 coefs = pp.coefs;
 k = pp.order;

因此,如果pp是包含所有信息的结构(如上所述),则不必调用unmkpp,而您只需要系数和中断即可.相反,您只需输入

Therefore it isn't necessary to call unmkpp if pp is a structure containing all of the info (as above), and you just want the coefficients and the breaks. Instead you can just type

 breaks = pp.breaks; 
 coefs = pp.coefs;

并继续使用此信息,如下所示.

and continue working with this information, as shown below.

请注意,对于三次样条,多项式的阶数为4,因为多项式的形式为

Note that for a cubic spline, the order of the polynomials is 4, since the polynomials have the form

C(1)* X ^(K-1)+ C(2)* X ^(K-2)+ ... + C(K-1)* X + C(K)

C(1)*X^(K-1) + C(2)*X^(K-2) + ... + C(K-1)*X + C(K)

,K = 4,因此每个多项式具有 4 个系数C.最高阶项X ^ 3与样条线为 cubic 一致.

with K = 4, and therefore each polynomial has 4 coefficients C. The highest order term X^3 is consistent with the spline being cubic.

要计算分段多项式:

(1)选择要评估的部分 由breaks

(1) choose the piece over which you want to evaluate the polynomial, defined by breaks

(2)为该片段选择正确的系数,并存储在coefs中.

(2) pick the correct coefficients for that piece, stored in coefs.

由于这些是分段多项式,因此我们在 范围为0-1,然后根据实际值 stretch shift 的x.我们使用标准函数polyval使用范围0-1来评估所选片段的多项式系数,从而使用感兴趣范围内的已知系数来评估多项式.

Because these are piecewise polynomials, we evaluate them over the range 0-1 and then stretch and shift them according to the actual value of x. We use the range 0-1 to evaluate the polynomial coefficients for the selected piece using the standard function polyval to evaluate a polynomial with known coefficients over a range of interest.

因此,我们找到与该块相对应的系数cf,并在点xev处评估多项式:

So we find the coefficients cf corresponding to the piece and evaluate the polynomial at points xev:

xev = linspace(0,1,100);
cf = pp.coefs(1,:);  
yyp=polyval(cf,xev);

我们保留了一些其他绘图信息:

We keep some additional info for plotting:

br = pp.breaks(1:2); % find the breaks (beginning and end of stretch of interest)
xxp = linspace(br(1),br(2),100);

我们可以概括此过程.因此,对于第n个片段(例如#6):

We can generalize this procedure. Thus for the nth piece (say #6):

n = 6;

cf = pp.coefs(n,:);
yyp2=polyval(cf,xev);

br = pp.breaks(n:n+1);
xxp2 = linspace(br(1),br(2),100);

当然,您可以跳过上述内容,而只需使用ppval(专用于spline函数家族的功能 ),即可完成以下操作: 对您来说也一样,对第三部分说:

Of course you can skip the above and just use ppval (a function dedicated to work with the spline family of functions), which will do the same for you, say for the 3rd piece:

br = pp.breaks(3:4); % limits of the piece
xxp3 = linspace(br(1),br(2),100);
yyp3=ppval(pp,xxp3);

最后,我们plot上面评估的所有多项式

Finally we plot all of the polynomials evaluated above

plot(xx,yy,'.')
hold on
plot(xxf,ppval(pp,xxf),'k:')
plot(xxp,yyp,'g-','linewidth',2)
plot(xxp2,yyp2,'r-','linewidth',2)    % <-- generated with polyval
plot(xxp3,yyp3,'c-','linewidth',2)    % <-- generated with ppval
axis tight

这篇关于样条的分段方程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆