日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

径向基函数插值(2)一维数据的插值

發布時間:2025/4/16 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 径向基函数插值(2)一维数据的插值 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

假設我們有N組數據(xi,yi),,,,,,,,這時我們根據徑向基函數我們的目的主要是找到徑向基函數中的位置參數的值,

我們要用這些已知數據的值用最小二乘法得到這些參數。。

現在我們用一般的方法matlb自帶的插值函數進行新值得計算:

<span style="font-size:18px;">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');</span>


現在我們用徑向基函數的方法進行插值

1、

<span style="font-size:18px;">x = 0:1.25:10; y = sin(x); xi = 0:.1:10; </span>產生數據集,和需要插值的數據

2、設定調用函數的參數

% 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'); 求解徑向基函數的系數過程 function options = rbfcreate(x, y, varargin) %RBFCREATE Creates an RBF interpolation % OPTIONS = RBFSET(X, Y, 'NAME1',VALUE1,'NAME2',VALUE2,...) creates an % radial base function interpolation % % RBFCREATE with no input arguments displays all property names and their % possible values. % %RBFCREATE PROPERTIES % % % Alex Chirokov, alex.chirokov@gmail.com % 16 Feb 2006 tic; % Print out possible values of properties. if (nargin == 0) & (nargout == 0)fprintf(' x: [ dim by n matrix of coordinates for the nodes ]\n');fprintf(' y: [ 1 by n vector of values at nodes ]\n');fprintf(' RBFFunction: [ gaussian | thinplate | cubic | multiquadrics | {linear} ]\n');fprintf(' RBFConstant: [ positive scalar ]\n');fprintf(' RBFSmooth: [ positive scalar {0} ]\n');fprintf(' Stats: [ on | {off} ]\n');fprintf('\n');return; end Names = ['RBFFunction ''RBFConstant ''RBFSmooth ''Stats ' ]; [m,n] = size(Names); names = lower(Names);options = []; for j = 1:moptions.(deblank(Names(j,:))) = []; end%************************************************************************** %Check input arrays %************************************************************************** [nXDim nXCount]=size(x); [nYDim nYCount]=size(y);if (nXCount~=nYCount)error(sprintf('x and y should have the same number of rows')); end;if (nYDim~=1)error(sprintf('y should be n by 1 vector')); end;options.('x') = x; options.('y') = y; %************************************************************************** %Default values %************************************************************************** options.('RBFFunction') = 'linear'; options.('RBFConstant') = (prod(max(x')-min(x'))/nXCount)^(1/nXDim); %approx. average distance between the nodes options.('RBFSmooth') = 0; options.('Stats') = 'off';%************************************************************************** % Argument parsing code: similar to ODESET.m %**************************************************************************i = 1; % A finite state machine to parse name-value pairs. if rem(nargin-2,2) ~= 0error('Arguments must occur in name-value pairs.'); end expectval = 0; % start expecting a name, not a value while i <= nargin-2arg = varargin{i};if ~expectvalif ~isstr(arg)error(sprintf('Expected argument %d to be a string property name.', i));endlowArg = lower(arg);j = strmatch(lowArg,names);if isempty(j) % if no matcheserror(sprintf('Unrecognized property name ''%s''.', arg));elseif length(j) > 1 % if more than one match% Check for any exact matches (in case any names are subsets of others)k = strmatch(lowArg,names,'exact');if length(k) == 1j = k;elsemsg = sprintf('Ambiguous property name ''%s'' ', arg);msg = [msg '(' deblank(Names(j(1),:))];for k = j(2:length(j))'msg = [msg ', ' deblank(Names(k,:))];endmsg = sprintf('%s).', msg);error(msg);endendexpectval = 1; % we expect a value nextelseoptions.(deblank(Names(j,:))) = arg;expectval = 0; endi = i + 1; endif expectvalerror(sprintf('Expected value for property ''%s''.', arg)); end%************************************************************************** % Creating RBF Interpolatin %**************************************************************************%選擇所用基函數的形式 這五種函數 高斯 線性 立方 薄板 多項式 switch lower(options.('RBFFunction')) case 'linear' options.('rbfphi') = @rbfphi_linear; %線性case 'cubic'options.('rbfphi') = @rbfphi_cubic;%立方case 'multiquadric'options.('rbfphi') = @rbfphi_multiquadrics;%多項式case 'thinplate'options.('rbfphi') = @rbfphi_thinplate;%薄板case 'gaussian'options.('rbfphi') = @rbfphi_gaussian;%高斯型otherwiseoptions.('rbfphi') = @rbfphi_linear; endphi = options.('rbfphi'); % 調用函數,求解出數據集使用調用||x-xi||函數的值 A=rbfAssemble(x, phi, options.('RBFConstant'), options.('RBFSmooth')); b=[y'; zeros(nXDim+1, 1)]; %這是數據集對應的輸出值Y %inverse rbfcoeff=A\b; %這是徑向基函數對應的參數系數%SVD % [U,S,V] = svd(A); % % for i=1:1:nXCount+1 % if (S(i,i)>0) S(i,i)=1/S(i,i); end; % end; % rbfcoeff = V*S'*U*b;options.('rbfcoeff') = rbfcoeff;if (strcmp(options.('Stats'),'on'))fprintf('%d point RBF interpolation was created in %e sec\n', length(y), toc); fprintf('\n'); end;function [A]=rbfAssemble(x, phi, const, smooth) %x 為已知的數據集 %phi 表示調用的是哪個基函數形式 %const 表示高斯形式時的方差 %smooth 偏移量 一般為0 [dim n]=size(x); %得到數據集的維數 A=zeros(n,n); %初始化有數據集帶入基函數中得到的值 for i=1:nfor j=1:ir=norm(x(:,i)-x(:,j)); %每個數據跟其他數據之間的距離temp=feval(phi,r, const); %帶入相應的基函數中得到的值,存儲到A中,用于求解系數A(i,j)=temp;A(j,i)=temp;endA(i,i) = A(i,i) - smooth; end % Polynomial part P=[ones(n,1) x']; A = [ A PP' zeros(dim+1,dim+1)]; %************************************************************************** % Radial Base Functions %************************************************************************** %五種基函數的表達式 function u=rbfphi_linear(r, const) u=r;function u=rbfphi_cubic(r, const) u=r.*r.*r;function u=rbfphi_gaussian(r, const) u=exp(-0.5*r.*r/(const*const));function u=rbfphi_multiquadrics(r, const) u=sqrt(1+r.*r/(const*const));function u=rbfphi_thinplate(r, const) u=r.*r.*log(r+1);這是進行求解新插入值得過程

已知新的插入值,和上一個函數得到的徑向基函數的參數,進行計算,得到新插入值的解

function [f] = rbfinterp(x, options) %x 為插值的數據 %options 徑向基函數的參數設定 tic; phi = options.('rbfphi'); %調用的基函數形式 rbfconst = options.('RBFConstant');%基函數的方差設置 nodes = options.('x'); %已知的數據集x rbfcoeff = (options.('rbfcoeff'))';%求得的徑向基函數的系數[dim n] = size(nodes); [dimPoints nPoints] = size(x);if (dim~=dimPoints)error(sprintf('x should have the same number of rows as an array used to create RBF interpolation')); end;f = zeros(1, nPoints); r = zeros(1, n);for i=1:1:nPointss=0;r = (x(:,i)*ones(1,n)) - nodes; %新數據點到已知每個數據點的距離r = sqrt(sum(r.*r, 1)); % for j=1:n % r(j) = norm(x(:,i) - nodes(:,j)); % ends = rbfcoeff(n+1) + sum(rbfcoeff(1:n).*feval(phi, r, rbfconst));for k=1:dims=s+rbfcoeff(k+n+1)*x(k,i); % linear partendf(i) = s; end;if (strcmp(options.('Stats'),'on'))fprintf('Interpolation at %d points was computed in %e sec\n', length(f), toc); end;



總結

以上是生活随笔為你收集整理的径向基函数插值(2)一维数据的插值的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。