matlab用rbf作为基函数进行插值计算

Posted studyer_domi

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了matlab用rbf作为基函数进行插值计算相关的知识,希望对你有一定的参考价值。

%**************************************************************************
% 1D Interpolation
%**************************************************************************

x = 0:1.25:10; 
y = sin(x); 
xi = 0:.1:10; 

%Matlab
yi = interp1(x,y,xi); 
subplot(2,1,1); plot(x,y,'o',xi,yi, xi, sin(xi),'r'); title('Interpolation using Matlab function interp1');

%RBF
%op=rbfcreate(x, y,'RBFFunction', 'thinplate'); rbfcheck(op);
%op=rbfcreate(x, y,'RBFFunction', 'linear'); rbfcheck(op);
%op=rbfcreate(x, y,'RBFFunction', 'cubic'); rbfcheck(op);
%op=rbfcreate(x, y,'RBFFunction', 'gaussian'); rbfcheck(op);
op=rbfcreate(x, y,'RBFFunction', 'multiquadric', 'RBFConstant', 2); rbfcheck(op);
op=rbfcreate(x, y); rbfcheck(op);
%op=rbfcreate(x, y,'RBFFunction', 'gaussian');
%op=rbfcreate(x, y);
fi = rbfinterp(xi, op);
subplot(2,1,2); plot(x, y,'o', xi, fi,xi, sin(xi),'r'); title('RBF interpolation');

yi=rbfinterp_ez(x,y,xi);
plot(x, y,'o', xi, fi,xi, sin(xi),'r'); title('RBF interpolation');

clear all; figure;
%**************************************************************************
% 2D Interpolation
%**************************************************************************
%Matlab standard interpolation using griddata 
rand('seed',0)
x = rand(50,1)*4-2; y = rand(50,1)*4-2;
z = x.*exp(-x.^2-y.^2);

ti = -2:.05:2; 
[XI,YI] = meshgrid(ti,ti);
ZI = griddata(x,y,z,XI,YI,'cubic');

subplot(2,2,1); mesh(XI,YI,ZI), hold, axis([-2 2 -2 2 -0.5 0.5]); 
plot3(x,y,z,'.r'), hold off; title('Interpolation using Matlab function griddata(method=cubic)');

subplot(2,2,3); pcolor(abs(ZI - XI.*exp(-XI.^2-YI.^2))); colorbar; title('griddata(method=cubic) interpolation error');

%RBF interpolation
%op=rbfcreate([X(:)'; Y(:)'], Z(:)','RBFFunction', 'thinplate'); rbfcheck(op);
%op=rbfcreate([X(:)'; Y(:)'], Z(:)','RBFFunction', 'linear'); rbfcheck(op);
%op=rbfcreate([X(:)'; Y(:)'], Z(:)','RBFFunction', 'cubic'); rbfcheck(op);
%op=rbfcreate([X(:)'; Y(:)'], Z(:)','RBFFunction', 'gaussian'); rbfcheck(op);
op=rbfcreate([x'; y'], z','RBFFunction', 'multiquadric', 'RBFConstant', 2);
rbfcheck(op);
%op=rbfcreate(x, y,'RBFFunction', 'gaussian');
%op=rbfcreate(x, y);
ZI = rbfinterp([XI(:)'; YI(:)'], op);
ZI = reshape(ZI, size(XI));
subplot(2,2,2); mesh(XI,YI,ZI), hold
plot3(x,y,z,'.r'), hold off; title('RBF interpolation'); axis([-2 2 -2 2 -0.5 0.5]);
subplot(2,2,4); pcolor(abs(ZI - XI.*exp(-XI.^2-YI.^2))); colorbar; title('RBF interpolation error');

clear all;
%**************************************************************************
% 1D smooth interpolation 
%**************************************************************************

x = 0:1.25:10; 
y = sin(x)+rand(size(x))-0.5; 
xi = 0:.1:10; 

%Matlab
yi = interp1(x,y,xi); 
subplot(2,1,1); plot(x,y,'o',xi,yi, xi, sin(xi),'r'); title('Interpolation using Matlab function interp1');

%RBF
op=rbfcreate(x, y,'RBFFunction', 'multiquadric', 'RBFConstant', 2, 'RBFSmooth', 0.1); rbfcheck(op);
fi = rbfinterp(xi, op);
subplot(2,1,2); plot(x, y,'o', xi, fi,xi, sin(xi),'r'); title('RBF interpolation');

clear all;
%**************************************************************************
% 1D  interpolation of random data
%**************************************************************************
N = 30;
smooth = 1e-2;
x = rand(1, N); 
y = rand(1, N); 
xi = [x rand(1, 10*N)]; 

%RBF
%op=rbfcreate(x, y,'RBFFunction', 'multiquadric', 'RBFConstant', 2, 'RBFSmooth', 1e-6); rbfcheck(op);
op=rbfcreate(x, y,'RBFFunction', 'cubic', 'RBFSmooth', smooth); 
yi = rbfinterp(xi, op);
[xi,index] = sort(xi);
subplot(2,2,1); plot(x, y,'.r', xi, yi(index)); title('RBF cubic interpolation'); 

op=rbfcreate(x, y,'RBFFunction', 'linear', 'RBFSmooth', smooth); 
yi = rbfinterp(xi, op);
[xi,index] = sort(xi);
subplot(2,2,2); plot(x, y,'.r', xi, yi(index)); title('RBF linear interpolation');

op=rbfcreate(x, y,'RBFFunction', 'multiquadric', 'RBFSmooth', smooth); 
yi = rbfinterp(xi, op);
[xi,index] = sort(xi);
subplot(2,2,3); plot(x, y,'.r', xi, yi(index)); title('RBF multiquadric interpolation');

op=rbfcreate(x, y,'RBFFunction', 'gaussian', 'RBFSmooth', smooth); 
yi = rbfinterp(xi, op);
[xi,index] = sort(xi);
subplot(2,2,4); plot(x, y,'.r', xi, yi(index)); title('RBF gaussian interpolation');

 

 

以上是关于matlab用rbf作为基函数进行插值计算的主要内容,如果未能解决你的问题,请参考以下文章

时间序列预测基于matlab RBF神经网络时间序列预测含Matlab源码 1336期

路径规划基于matlab RBF优化Qlearning算法机器人避障路径规划含Matlab源码 1219期

Matlab中插值函数怎么用

RBF神经网络理论与实现

多项式函数插值:全域多项式插值单项式基插值拉格朗日插值牛顿插值 [MATLAB]

请问matlab中RBF神经网络newrbe函数用的啥算法