Main Content

张敏产品样条近似值

Because the toolbox can handle splines with向量coefficients, it is easy to implement interpolation or approximation to网格数据由张量产品样条,如下图所示。您还可以运行示例“Bivariate Tensor Product Spline”。

To be sure, most tensor product spline approximation to gridded data can be obtained directly with one of the spline construction commands, likeSP.api要么csape., in this toolbox, without concern for the details discussed in this example. Rather, this example is meant to illustrate the theory behind the tensor product construction, and this will be of help in situations not covered by the construction commands in this toolbox.

This section discusses these aspects of the tensor product spline problem:

Choice of Sites and Knots

考虑,例如,对给定数据的最小二乘近似z(i,j)=f(x(i),y(j)),i=1:NX.,j=1:纽约。You take the data from a function used extensively byFranke用于测试表面拟合方案(参见R. Franke,“散射数据插值的一些方法的关键比较,”海军研究生院校。代表NPS-53-79-003,1979年3月)。它的域是单位广场。您选择更多的数据网站x-direction than they-direction; also, for a better definition, you use higher data density near the boundary.

x = sort([(0:10)/10,.03 .07,.93 .97]);y = sort([(0:6)/6,03 .07,.93 .97]);[xx,yy] = ndgrid(x,y);z = Franke(XX,YY);

Least Squares Approximation as Function of y

从a到a将这些数据视为矢量值函数,即函数ywhose value aty(j) is the vectorz(:,j), allj。For no particular reason, choose to approximate this function by a vector-valuedparabolic spline, with threeuniformly spaced interior knots。这意味着您选择该矢量值样条的花键顺序和结序列为

ky = 3; knotsy = augknt([0,.25,.5,.75,1],ky);

然后使用SP.ap2to provide the least squares approximant to the data:

SP.= spap2(knotsy,ky,y,z);

实际上,您同时找到了离散最小二乘近似值SKY,Knotsy.每个人NX.数据集

( y ( j ) , z ( i , j ) ) j = 1 N y , i = 1 : N x

特别是,陈述

yy = -.1:.05:1.1; vals = fnval(sp,yy);

提供阵列vals,谁的入场vals(i,j)can be taken as an approximation to the valuef(x(i),yy(j))of the underlying functionf在网眼点x(i),yy(j) becausevals(:,j)is the value atyy(j) of the approximating spline curve inSP.

This is evident in the following figure, obtained by the command:

网格(x,yy,vals。'),查看(150,50)

注意使用vals.', 在里面啮合命令,因为matlab而需要®绘制阵列时面向矩阵视图。这可能是双变象逼近的严重问题,因为它习惯了z(i,j) as the function value at the point (x(i),y(j)),而Matlab认为z(i,j) as the function value at the point (x(j),y(i)))。

假装是表面的平滑曲线

注意both the first two and the last two values on each smooth curve are actually zero because both the first two and the last two sites inyy在外面样条的基本间隔SP.

Note also the ridges. They confirm that you are plotting smooth curves in one direction only.

Approximation to Coefficients as Functions of x

要获得实际的表面,您现在必须进一步逐步。看看系数cofsy.花键SP.:

cofsy.= fnbrk(sp,'coefs');

Abstractly, you can think of the spline inSP.as the function

y | σ. r c o e f s y ( : , r ) B r , k y ( y )

与之ith entrycofsy.(i,r)的the vector coefficientcofsy.(:,r)corresponding tox(i), for alli。This suggests approximating each coefficient vectorcofsy(q,:)通过相同顺序的样条kx和与之same appropriate knot sequenceknotsx.。For no particular reason, this time use立方体SP.lines withfouruniformly spaced interior knots:

kx = 4; knotsx = augknt([0:.2:1],kx); sp2 = spap2(knotsx,kx,x,coefsy.');

注意SP.ap2(结,k,x,fx) expectsfx(:,j)成为基准x(j), i.e., expects eachcolumnfx是一个函数值。适合数据cofsy(q,:)atx(q), for allq, presentSP.ap2与之翻倒cofsy.

一分变焦近似

现在考虑系数的转换CXY由此产生SP.linecurve:

COEFS = FNBRK(SP2,'COEFS')。'

它提供了bivariate样条近似

( x , y ) | σ. q σ. r c o e f s ( q , r ) B q , k x ( x ) B r , k y ( y )

to the original data

( x ( i ) , y ( j ) ) | z ( x ( i ) , y ( j ) ) , i = 1 : N x , j = 1 : N y

在网格上绘制该样条曲表面,例如网格

XV.= 0:.025:1; yv = 0:.025:1;

you can do the following:

values =Spcol(Knotsx,Kx,XV)* Cofs * Spcol(Knotsy,Ky,YV)。';网格(XV,YV,值。'),查看(150,50);

这导致下图。

曲线近似到Franke的功能

This makes good sense becauseSpcol(Knotsx,Kx,XV)是矩阵的(i,q)Th条目等于V值bq,kx(XV.(i)) atXV.(i) of theqth B-spline of orderkxfor the knot sequenceknotsx.

Because the matricesSpcol(Knotsx,Kx,XV)Spcol(Knotsy,Ky,YV)带状,它可能更有效率,虽然也许m要么e memory-consuming, forlargeXV.yvto make use offnval, as follows:

value2 = ... fnval(spmak(knotsx,fnval(spmak(knotsy,coefs),yv).'),xv).';

事实上,这是在内部发生的事情fnvalis called directly with a tensor product spline, as in

value2 = fnval(spmak({knotsx,knotsy},coefs),{xv,yv});

这里是计算相对误差,即给定数据与这些数据站点的近似值之间的差异,与给定数据的幅度相比:

错误= z - spcol (knotsx kx, x) *系数* spcol (knotsy,ky,y).'; disp( max(max(abs(errors)))/max(max(abs(z))) )

The output is0.0539, perhaps not too impressive. However, the coefficient array was only of size8 6.

disp(size(coefs))

适合大小的数据数组15 11

disp(size(z))

Switch in Order

似乎是这种方法biased,以下列方式。首先想到给定的数据zas describing a vector-valued function ofy,和then treat the matrix formed by the vector coefficients of the approximating curve as describing a vector-valued function ofx

What happens when you take things in the opposite order, i.e., think ofzas describing a vector-valued function ofx,和then treat the matrix made up from the vector coefficients of the approximating curve as describing a vector-valued function ofy?

Perhaps surprisingly, the final approximation is the same, up to round-off. Here is the numerical experiment.

Least Squares Approximation as Function of x

First, fit a spline curve to the data, but this time withxas the independent variable, hence it is thezthat now become the data values. Correspondingly, you must supplyz.', rather thanz, 至SP.ap2,

SPB.= spap2(knotsx,kx,x,z.');

thus obtaining a spline approximation to all the curves (x;z(:,j)))。In particular, the statement

valsb = fnval(spb,xv).';

provides the matrixvalsb,谁的入场valsb(i,j)can be taken as an approximation to the valuef(XV.(i),y(j)) of the underlying functionf在网眼点(XV.(i),y(j)))。This is evident when you plotvalsb使用啮合:

网格(xv,y,valsb。'),查看(150,50)

Another Family of Smooth Curves Pretending to Be a Surface

注意脊。他们确认您再次绘制一个方向的平滑曲线。但这时间曲线沿另一个方向运行。

Approximation to Coefficients as Functions of y

Now comes the second step, to get the actual surface. First, extract the coefficients:

COEFSX = FNBRK(SPB,'COEFS');

Then fit each coefficient vectorCOEFSX.(r,:)通过相同顺序的样条ky和与之same appropriate knot sequenceKnotsy.:

SPB2 =Spap2(Knotsy,Ky,Y,Cofsx。');

注意, once again, you need to transpose the coefficient array fromSPB., becauseSP.ap2takes the columns of its last input argument as the data values.

Correspondingly, there is now no need to transpose the coefficient arrayCOEFSB.由此产生curve:

COEFSB = FNBRK(SPB2,'COEFS');

一分变焦近似

索赔是COEFSB.equals the earlier coefficient arrayCOEFS.,截止到圆形,这是测试:

disp( max(max(abs(coefs - coefsb))) )

The output is1.4433E-15.

The explanation is simple enough: The coefficientsc的the splinescontained inSP.= spap2(knots,k,x,y)依靠线性的在输入值上y。这意味着,给予这两种cy是1行矩阵,有一些矩阵A=A结,k,x以便

c = y A knots , k , x

对于任何数据y。这个声明甚至持有什么时候y是A.matrix, of sized-by-N, say, in which case each datumy(:,j) is taken to be a point inRd,和the resulting spline is correspondinglyd- vector值,因此其系数阵列cis of sized-by-n, with n =length(knots)-k

特别是,陈述

SP.= spap2(knotsy,ky,y,z); coefsy =fnbrk(sp,'coefs');

provide us with the matrixcofsy.that satisfies

COEFS. y = z A Knotsy,Ky,y

The subsequent computations

sp2 = spap2(knotsx,kx,x,cofsy。');COEFS = FNBRK(SP2,'COEFS')。'

generate the coefficient arrayCOEFS.,考虑到两个换位,满足

COEFS. = ( ( z A Knotsy,Ky,y ) ' A Knotsx,kx,x ) ' = ( A Knotsx,kx,x ) ' z A Knotsy,Ky,y

在第二个,替代,计算,你第一次计算

SPB.= spap2(knotsx,kx,x,z.'); coefsx = fnbrk(spb,'coefs');

因此COEFSX.=z'.AKnotsx,kx,x。随后的计算

SPB2 = SPAP2(Knotsy,Ky,Y,Cofsx。');COEFSB = FNBRK(SPB,'COEFS');

then provided

COEFSB. = COEFSX. ' A Knotsy,Ky,y = ( A Knotsx,kx,x ) ' z A Knotsy,Ky, y

所以,COEFSB.=COEFS.

Comparison and Extension

The second approach is more symmetric than the first in that transposition takes place in each call toSP.ap2和nowhere else. This approach can be used for approximation to gridded data in any number of variables.

If, for example, the given data over a-dimensional grid are contained in some three-dimensional arrayv的size[Nx,Ny,Nz], withv(i,j,k)containing the valuef(x(i),y(j),z(k)),然后你会开始

cofs = Rehape(v,nx,ny * nz);

Assuming thatnj =knotsJ -kj, for j =x,y,z, you would then proceed as follows:

SP.= spap2(knotsx,kx,x,coefs.'); coefs = reshape(fnbrk(sp,'coefs'),Ny,Nz*nx); sp = spap2(knotsy,ky,y,coefs.'); coefs = reshape(fnbrk(sp,'coefs'),Nz,nx*ny); sp = spap2(knotsz,kz,z,coefs.'); coefs = reshape(fnbrk(sp,'coefs'),nx,ny*nz);

见第17章PGS要么[C. de Boor, “Efficient computer manipulation of tensor products,”ACM Trans. Math. Software 5(1979),173-182;有关更多细节,Corrigenda,525]相同的参考资料还明确表示使用最小二乘近似没有什么特别的。任何近似过程,包括样条插值,其结果近似具有在给定数据上线性地线性地具有依赖性的系数,可以以与多变量近似过程相同的方式扩展到网格数据。

This is exactly what is used in the spline construction commandsCSAPI.,csape.,SP.api,SP.aps,和SP.ap2, when gridded data are to be fitted. It is also used infnval, when a tensor product spline is to be evaluated on a grid.